Skip to content

Commit

Permalink
Depend on audeer>=2.0.0 (#411)
Browse files Browse the repository at this point in the history
* Depend on audeer>=2.0.0

* Add test for symlink storage

* Fix db.root when storing database

* Try to fix to_filewise_index()

* Depend on audeer>=2.0.0

* TST: enforce audeer>=2.0.0

* Try to enforce development version of audformat

* Try manual installation of audeer

* Add a comment
  • Loading branch information
hagenw authored Jan 25, 2024
1 parent 2f81002 commit 17332e4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r tests/requirements.txt
# Force audeer 2.0.0
# until we have a new audformat version released,
# that does not have "audeer <2.0.0"
# in its dependencies
pip install --upgrade audeer
- name: Test with pytest
run: |
Expand Down
2 changes: 1 addition & 1 deletion audformat/core/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _check_path(
root: str,
):
r"""Check if path exists and is not a symlink."""
if not os.path.exists(audeer.path(root, self.path)):
if not os.path.exists(audeer.path(root, self.path, follow_symlink=True)):
raise FileNotFoundError(
f"The provided path '{self.path}' "
f"of attachment '{self._id}' "
Expand Down
9 changes: 5 additions & 4 deletions audformat/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,8 @@ def save(
verbose: show progress bar
"""
root = audeer.mkdir(root)
root = audeer.path(root, follow_symlink=True)
audeer.mkdir(root)

ext = ".yaml"
header_path = os.path.join(root, name + ext)
Expand All @@ -1010,7 +1011,7 @@ def save(
if not header_only:
# Store (misc) tables
def job(obj_id, obj):
path = audeer.path(root, f"{name}.{obj_id}")
path = os.path.join(root, f"{name}.{obj_id}")
obj.save(
path,
storage_format=storage_format,
Expand Down Expand Up @@ -1411,7 +1412,7 @@ def load(
"""
ext = ".yaml"
root = audeer.path(root)
root = audeer.path(root, follow_symlink=True)
path = os.path.join(root, name + ext)

if not os.path.exists(path):
Expand All @@ -1435,7 +1436,7 @@ def load(
for table_id in table_ids:
table = db[table_id]
if load_data:
table_path = audeer.path(root, name + "." + table_id)
table_path = os.path.join(root, name + "." + table_id)
params.append(([table, table_path], {}))
else:
table._df = None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ classifiers = [
]
requires-python = '>=3.8'
dependencies = [
'audeer >=1.19.0,<2.0.0',
'audeer >=2.0.0',
'audiofile >=0.4.0',
'iso-639',
'iso3166',
Expand Down
22 changes: 11 additions & 11 deletions tests/test_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_attachment(tmpdir):

# Save database, path is allowed to be a symlink
audeer.rmdir(db_path)
audeer.mkdir(audeer.path(db_path, folder_path))
audeer.mkdir(db_path, folder_path)
os.symlink(
audeer.path(db_path, folder_path),
audeer.path(db_path, file_path),
Expand All @@ -67,7 +67,7 @@ def test_attachment(tmpdir):

# Replace symlink by file
os.remove(os.path.join(db_path, file_path))
audeer.touch(audeer.path(db_path, file_path))
audeer.touch(db_path, file_path)
db.save(db_path)

# File exist now, folder is empty
Expand All @@ -89,7 +89,7 @@ def test_attachment(tmpdir):
# Load database
#
# path must not exist when loading the database
audeer.rmdir(audeer.path(db_path, os.path.dirname(file_path)))
audeer.rmdir(db_path, os.path.dirname(file_path))
assert not os.path.exists(audeer.path(db_path, file_path))
audformat.Database.load(db_path, load_data=True)
audformat.Database.load(db_path, load_data=False)
Expand Down Expand Up @@ -172,9 +172,9 @@ def test_attachment_files_errors(tmpdir):
attachment.files

# Attached path does not exists
audeer.mkdir(audeer.path(db_path, attachment_path))
audeer.mkdir(db_path, attachment_path)
db.save(db_path)
audeer.rmdir(audeer.path(db_path, attachment_path))
audeer.rmdir(db_path, attachment_path)
error_msg = (
f"The provided path '{attachment_path}' "
"of attachment 'attachment' "
Expand All @@ -185,7 +185,7 @@ def test_attachment_files_errors(tmpdir):

# Attached path is a symlink
folder_link = "extra-link"
audeer.mkdir(audeer.path(db_path, folder_link))
audeer.mkdir(db_path, folder_link)
os.symlink(
audeer.path(db_path, folder_link),
audeer.path(db_path, attachment_path),
Expand All @@ -200,9 +200,9 @@ def test_attachment_files_errors(tmpdir):

# Some files are inside a symlink folder
os.remove(os.path.join(db_path, attachment_path))
audeer.mkdir(audeer.path(db_path, attachment_path))
audeer.touch(audeer.path(db_path, attachment_path, "file1.txt"))
audeer.touch(audeer.path(db_path, folder_link, "file2.txt"))
audeer.mkdir(db_path, attachment_path)
audeer.touch(db_path, attachment_path, "file1.txt")
audeer.touch(db_path, folder_link, "file2.txt")
os.symlink(
audeer.path(db_path, folder_link),
audeer.path(db_path, attachment_path, "link"),
Expand All @@ -217,8 +217,8 @@ def test_attachment_files_errors(tmpdir):

# Some files of the attachments are symlinks
os.remove(os.path.join(db_path, attachment_path, "link"))
audeer.touch(audeer.path(db_path, attachment_path, "file1.txt"))
audeer.touch(audeer.path(db_path, folder_link, "file2.txt"))
audeer.touch(db_path, attachment_path, "file1.txt")
audeer.touch(db_path, folder_link, "file2.txt")
os.symlink(
audeer.path(db_path, folder_link, "file2.txt"),
audeer.path(db_path, attachment_path, "file2.txt"),
Expand Down
15 changes: 12 additions & 3 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,15 @@ def test_save_and_load(tmpdir, db, storage_format, load_data, num_workers):
db[table_id].get()


def test_save_symlink(tmpdir):
folder = audeer.mkdir(tmpdir, "folder")
link = audeer.path(tmpdir, "link")
os.symlink(folder, link)
db = audformat.testing.create_db()
db.save(link)
assert db.root == folder


def test_segments():
db = audformat.testing.create_db()
df = pytest.DB["segments"].get()
Expand All @@ -659,7 +668,7 @@ def test_string():
def test_update(tmpdir):
# original database

db_root = audeer.mkdir(audeer.path(tmpdir, "db"))
db_root = audeer.mkdir(tmpdir, "db")
db = audformat.testing.create_db(minimal=True)
db.author = "author"
db.organization = "organization"
Expand Down Expand Up @@ -731,7 +740,7 @@ def test_update(tmpdir):

# database with same table, but extra column

other1_root = audeer.mkdir(audeer.path(tmpdir, "other1"))
other1_root = audeer.mkdir(tmpdir, "other1")
other1 = audformat.testing.create_db(minimal=True)
other1.raters["rater"] = audformat.Rater()
other1.raters["rater2"] = audformat.Rater()
Expand Down Expand Up @@ -768,7 +777,7 @@ def test_update(tmpdir):

# database with new table

other2_root = audeer.mkdir(audeer.path(tmpdir, "other2"))
other2_root = audeer.mkdir(tmpdir, "other2")
other2 = audformat.testing.create_db(minimal=True)
other2.raters["rater2"] = audformat.Rater()
other2.attachments["attachment2"] = audformat.Attachment("file2.txt")
Expand Down
10 changes: 5 additions & 5 deletions tests/test_database_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def mono_db(tmpdir):
r"""Database with ..."""
name = "mono-db"
path = audeer.mkdir(audeer.path(tmpdir, name))
path = audeer.mkdir(tmpdir, name)
db = audformat.Database(name)

# --- Splits
Expand Down Expand Up @@ -153,7 +153,7 @@ def stereo_db(tmpdir):
"""
name = "stereo-db"
path = audeer.mkdir(audeer.path(tmpdir, name))
path = audeer.mkdir(tmpdir, name)
db = audformat.Database(name)

# --- Schemes
Expand Down Expand Up @@ -206,7 +206,7 @@ def overlapping_data_db(tmpdir):
"""
name = "overlapping_data_db"
path = audeer.mkdir(audeer.path(tmpdir, name))
path = audeer.mkdir(tmpdir, name)
db = audformat.Database(name)

# --- Schemes
Expand Down Expand Up @@ -234,7 +234,7 @@ def overlapping_data_db(tmpdir):
def scheme_not_assigned_db(tmpdir):
r"""Database with matching scheme that is not assigned."""
name = "scheme_not_assigned_db"
path = audeer.mkdir(audeer.path(tmpdir, name))
path = audeer.mkdir(tmpdir, name)
db = audformat.Database(name)

# --- Schemes
Expand Down Expand Up @@ -262,7 +262,7 @@ def scheme_not_assigned_db(tmpdir):
def wrong_scheme_labels_db(tmpdir):
r"""Database with scheme labels that do not match."""
name = "wrong_scheme_labels_db"
path = audeer.mkdir(audeer.path(tmpdir, name))
path = audeer.mkdir(tmpdir, name)
db = audformat.Database(name)

# --- Schemes
Expand Down

0 comments on commit 17332e4

Please sign in to comment.