diff --git a/audbackend/core/api.py b/audbackend/core/api.py index ce7c8755..d5065573 100644 --- a/audbackend/core/api.py +++ b/audbackend/core/api.py @@ -2,9 +2,9 @@ from audbackend.core import utils from audbackend.core.backend import Backend +from audbackend.core.filesystem import FileSystem from audbackend.core.interface import Unversioned from audbackend.core.interface import Versioned -from audbackend.core.filesystem import FileSystem backends = {} diff --git a/audbackend/core/backend.py b/audbackend/core/backend.py index 573ffd73..38a955ec 100644 --- a/audbackend/core/backend.py +++ b/audbackend/core/backend.py @@ -436,7 +436,8 @@ def ls( if pattern: paths = [ - p for p in paths if fnmatch.fnmatch(os.path.basename(p), pattern) + p for p in paths + if fnmatch.fnmatch(os.path.basename(p), pattern) ] return paths @@ -556,7 +557,6 @@ def put_file( ): r"""Put file on backend. - The operation is silently skipped, if a file with the same checksum already exists on the backend. diff --git a/audbackend/core/conftest.py b/audbackend/core/conftest.py index a855ae6c..3a20cfe2 100644 --- a/audbackend/core/conftest.py +++ b/audbackend/core/conftest.py @@ -50,7 +50,12 @@ def prepare_docstring_tests(doctest_namespace): # unversioned interface - unversioned = audbackend.create('file-system', 'host', 'unversioned', versioned=False) + unversioned = audbackend.create( + 'file-system', + 'host', + 'unversioned', + versioned=False, + ) unversioned.put_archive('.', '/a.zip', files=[file]) unversioned.put_file(file, '/a/b.ext') unversioned.put_file(file, '/f.ext') @@ -58,7 +63,12 @@ def prepare_docstring_tests(doctest_namespace): # versioned interface - versioned = audbackend.create('file-system', 'host', 'versioned', versioned=True) + versioned = audbackend.create( + 'file-system', + 'host', + 'versioned', + versioned=True, + ) versioned.put_archive('.', '/a.zip', '1.0.0', files=[file]) versioned.put_file(file, '/a/b.ext', '1.0.0') for version in ['1.0.0', '2.0.0']: diff --git a/audbackend/core/interface.py b/audbackend/core/interface.py index 4a5cd357..d455e6a6 100644 --- a/audbackend/core/interface.py +++ b/audbackend/core/interface.py @@ -1,6 +1,5 @@ import os import re -import tempfile import typing import audeer @@ -214,7 +213,10 @@ def exists( True """ - return self.backend.exists(path, suppress_backend_errors=suppress_backend_errors) + return self.backend.exists( + path, + suppress_backend_errors=suppress_backend_errors, + ) def get_archive( self, @@ -259,7 +261,12 @@ def get_archive( ['src.pth'] """ - return self.backend.get_archive(src_path, dst_root, tmp_root=tmp_root, verbose=verbose) + return self.backend.get_archive( + src_path, + dst_root, + tmp_root=tmp_root, + verbose=verbose, + ) def get_file( self, @@ -369,7 +376,11 @@ def ls( ['/a/b.ext'] """ # noqa: E501 - return self.backend.ls(path, pattern=pattern, suppress_backend_errors=suppress_backend_errors) + return self.backend.ls( + path, + pattern=pattern, + suppress_backend_errors=suppress_backend_errors, + ) def owner( self, @@ -451,7 +462,13 @@ def put_archive( True """ - self.backend.put_archive(src_root, dst_path, files=files, tmp_root=tmp_root, verbose=verbose) + self.backend.put_archive( + src_root, + dst_path, + files=files, + tmp_root=tmp_root, + verbose=verbose, + ) def put_file( self, @@ -634,7 +651,10 @@ def exists( """ path_with_version = self._path_with_version(path, version) - return self.backend.exists(path_with_version, suppress_backend_errors=suppress_backend_errors) + return self.backend.exists( + path_with_version, + suppress_backend_errors=suppress_backend_errors, + ) def get_archive( self, @@ -684,7 +704,12 @@ def get_archive( """ src_path_with_version = self._path_with_version(src_path, version) - return self.backend.get_archive(src_path_with_version, dst_root, tmp_root=tmp_root, verbose=verbose) + return self.backend.get_archive( + src_path_with_version, + dst_root, + tmp_root=tmp_root, + verbose=verbose, + ) def get_file( self, @@ -739,7 +764,11 @@ def get_file( """ src_path_with_version = self._path_with_version(src_path, version) - return self.backend.get_file(src_path_with_version, dst_path, verbose=verbose) + return self.backend.get_file( + src_path_with_version, + dst_path, + verbose=verbose, + ) def latest_version( self, @@ -832,13 +861,21 @@ def ls( """ # noqa: E501 if path.endswith('/'): # find files under sub-path - paths = self.backend.ls(path, pattern=pattern, suppress_backend_errors=suppress_backend_errors) + paths = self.backend.ls( + path, + pattern=pattern, + suppress_backend_errors=suppress_backend_errors, + ) else: # find versions of path root, file = self.split(path) - paths = self.backend.ls(root, pattern=pattern, suppress_backend_errors=suppress_backend_errors) + paths = self.backend.ls( + root, + pattern=pattern, + suppress_backend_errors=suppress_backend_errors, + ) # filter for '/root/version/file' if self._legacy_file_structure: @@ -1005,7 +1042,13 @@ def put_archive( """ dst_path_with_version = self._path_with_version(dst_path, version) - self.backend.put_archive(src_root, dst_path_with_version, files=files, tmp_root=tmp_root, verbose=verbose) + self.backend.put_archive( + src_root, + dst_path_with_version, + files=files, + tmp_root=tmp_root, + verbose=verbose, + ) def put_file( self, @@ -1048,7 +1091,11 @@ def put_file( """ dst_path_with_version = self._path_with_version(dst_path, version) - return self.backend.put_file(src_path, dst_path_with_version, verbose=verbose) + return self.backend.put_file( + src_path, + dst_path_with_version, + verbose=verbose, + ) def remove_file( self, diff --git a/tests/test_artifactory.py b/tests/test_artifactory.py index 7135624f..dfe82169 100644 --- a/tests/test_artifactory.py +++ b/tests/test_artifactory.py @@ -212,6 +212,9 @@ def test_legacy_file_structure(tmpdir, interface, file, version, extensions, interface.put_file(src_path, file, version) url = f'{str(interface.backend._repo.path)}{expected}' - assert interface.backend._expand(interface._path_with_version(file, version)) == url + url_expected = interface.backend._expand( + interface._path_with_version(file, version), + ) + assert url_expected == url assert interface.ls(file) == [(file, version)] assert interface.ls() == [(file, version)] diff --git a/tests/test_filesystem.py b/tests/test_filesystem.py index ad8548fa..27220f12 100644 --- a/tests/test_filesystem.py +++ b/tests/test_filesystem.py @@ -138,6 +138,9 @@ def test_legacy_file_structure(tmpdir, interface, file, version, extensions, interface.put_file(src_path, file, version) path = os.path.join(interface.backend._root, expected) - assert interface.backend._expand(interface._path_with_version(file, version)) == path + path_expected = interface.backend._expand( + interface._path_with_version(file, version), + ) + assert path_expected == path assert interface.ls(file) == [(file, version)] assert interface.ls() == [(file, version)] diff --git a/tests/test_unversioned.py b/tests/test_unversioned.py index c6ff73dd..013b4e20 100644 --- a/tests/test_unversioned.py +++ b/tests/test_unversioned.py @@ -463,31 +463,18 @@ def test_ls(tmpdir, interface): '/file.bar', '/file.foo', ] - root_latest = [ - '/file.bar', - '/file.foo', - ] root_foo = [ '/file.foo', ] root_bar = [ '/file.bar', ] - root_bar_latest = [ - '/file.bar', - ] sub = [ '/sub/file.foo', ] - sub_latest = [ - '/sub/file.foo', - ] hidden = [ '/.sub/.file.foo', ] - hidden_latest = [ - '/.sub/.file.foo', - ] # create content diff --git a/tests/test_versioned.py b/tests/test_versioned.py index 5f9b69c2..12fb4ca7 100644 --- a/tests/test_versioned.py +++ b/tests/test_versioned.py @@ -260,7 +260,12 @@ def test_errors(tmpdir, interface): else: error_msg = "No such file or directory: 'non-existing/..." with pytest.raises(FileNotFoundError, match=error_msg): - interface.get_archive(archive, tmpdir, version, tmp_root='non-existing') + interface.get_archive( + archive, + tmpdir, + version, + tmp_root='non-existing', + ) # extension of `src_path` is not supported error_msg = 'You can only extract ZIP and TAR.GZ files, ...' interface.put_file( @@ -394,7 +399,12 @@ def test_errors(tmpdir, interface): # extension of `dst_path` is not supported error_msg = 'You can only create a ZIP or TAR.GZ archive, not ...' with pytest.raises(RuntimeError, match=error_msg): - interface.put_archive(tmpdir, '/archive.bad', version, files=local_file) + interface.put_archive( + tmpdir, + '/archive.bad', + version, + files=local_file, + ) # --- put_file --- # `src_path` does not exists