Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy file on backend #181

Merged
merged 17 commits into from
Feb 8, 2024
Merged

Copy file on backend #181

merged 17 commits into from
Feb 8, 2024

Conversation

frankenjoe
Copy link
Collaborator

@frankenjoe frankenjoe commented Feb 7, 2024

Relates to #177

Adds backend.Base.copy_file() to copy a file on the backend. A default implementation is provided, which downloads the files to a temporary directory and afterward uploads it to the new location. The behavior can be overwritten by implementing a custom _copy_file() method. In case of a versioned interface, all versions of file are copied unless a specific version is selected.

Documentation

API

backend.Base / backend.Artifactory / backend.FileSystem

image

interface.Unversioned

image

interface.Versioned

image

Usage

image

...

image

Developer

image

@frankenjoe frankenjoe marked this pull request as draft February 7, 2024 16:52
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4e1068d) 0.0% compared to head (df77567) 100.0%.
Report is 1 commits behind head on main.

Additional details and impacted files
Files Coverage Δ
audbackend/core/backend/artifactory.py 100.0% <100.0%> (ø)
audbackend/core/backend/base.py 100.0% <100.0%> (ø)
audbackend/core/backend/filesystem.py 100.0% <100.0%> (ø)
audbackend/core/interface/unversioned.py 100.0% <100.0%> (ø)
audbackend/core/interface/versioned.py 100.0% <100.0%> (ø)

... and 9 files with indirect coverage changes

@frankenjoe frankenjoe marked this pull request as ready for review February 8, 2024 08:53
@frankenjoe frankenjoe requested a review from hagenw February 8, 2024 08:53
audbackend/core/backend/base.py Outdated Show resolved Hide resolved
audbackend/core/interface/unversioned.py Outdated Show resolved Hide resolved
audbackend/core/interface/versioned.py Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
tests/singlefolder.py Show resolved Hide resolved
@frankenjoe
Copy link
Collaborator Author

BTW, what happens if a sub path exists on the backend with the same name as the file. I guess trying to overwrite it will raise an error?
Would be nice to add a test for this case.

Mhh, interesting question. I guess it depends on the backend. E.g. on FileSystem if you have /sub/file.txt and then you try to create a file /sub it will fail. But on other backends, e.g. the SQL database in the developer section, it will work.

@frankenjoe
Copy link
Collaborator Author

E.g. on FileSystem if you have /sub/file.txt and then you try to create a file /sub it will fail.

Actually, it not only depends on the Backend but also the Interface. E.g. with Versioned it should even work on FileSystem since /sub/file.txt is translated to /sub/1.0.0/file.txt and /sub to /1.0.0/sub.

@hagenw
Copy link
Member

hagenw commented Feb 8, 2024

BTW, what happens if a sub path exists on the backend with the same name as the file. I guess trying to overwrite it will raise an error?
Would be nice to add a test for this case.

Mhh, interesting question. I guess it depends on the backend. E.g. on FileSystem if you have /sub/file.txt and then you try to create a file /sub it will fail. But on other backends, e.g. the SQL database in the developer section, it will work.

The case that it might fail is covered by the BackendError in the docstring then I guess?

@frankenjoe
Copy link
Collaborator Author

frankenjoe commented Feb 8, 2024

The case that it might fail is covered by the BackendError in the docstring then I guess?

I was expecting so, but turns out it does not :) This is because FileSystem uses shutil.copy() under the hood, which inteprets /sub as a folder if it exists and in that case creates a file with the name of the source path in that folder. Here is a minimal example that reveals this behavior:

import audeer

import audbackend

with tempfile.TemporaryDirectory() as tmp:

    path = audeer.touch(tmp, 'file.txt')
    backend = audbackend.backend.FileSystem(tmp, 'repo')
    backend.put_file(path, '/sub/file.txt')
    path = audeer.touch(tmp, 'file2.txt')
    backend.put_file(path, '/sub')
    backend.ls()
['/sub/file.txt', '/sub/file2.txt']

@frankenjoe
Copy link
Collaborator Author

But I suggest we discuss this in a separate issue, as it is not directly related to this PR.

@hagenw
Copy link
Member

hagenw commented Feb 8, 2024

OK, I created #184.

@hagenw hagenw merged commit 4e1fab3 into main Feb 8, 2024
9 checks passed
@hagenw hagenw deleted the copy-file branch February 8, 2024 10:28
@frankenjoe frankenjoe mentioned this pull request Feb 9, 2024
hagenw added a commit that referenced this pull request May 3, 2024
* audbackend.Base: add copy_file()

* audbackend.interface.[Unversioned,Versioned]: add copy_file()

* backend.[FileSystem,Artifactory]: add copy_file()

* backend.FileSystem: fix copy file

* backend.Artifactory: create destination directory if it does not exist

* TST: update

* TST: fix long line

* TST: test errors

* DOC: add docstring examples

* DOC: update usage section

* TST: exclude Base._copy_file() from Windows coverage

* DOC: update developer section

* Update audbackend/core/backend/base.py

Co-authored-by: Hagen Wierstorf <[email protected]>

* Update audbackend/core/interface/unversioned.py

Co-authored-by: Hagen Wierstorf <[email protected]>

* Update audbackend/core/interface/versioned.py

Co-authored-by: Hagen Wierstorf <[email protected]>

* Update docs/usage.rst

Co-authored-by: Hagen Wierstorf <[email protected]>

* DOC: fix typo

---------

Co-authored-by: Hagen Wierstorf <[email protected]>
hagenw added a commit that referenced this pull request May 3, 2024
* audbackend.Base: add copy_file()

* audbackend.interface.[Unversioned,Versioned]: add copy_file()

* backend.[FileSystem,Artifactory]: add copy_file()

* backend.FileSystem: fix copy file

* backend.Artifactory: create destination directory if it does not exist

* TST: update

* TST: fix long line

* TST: test errors

* DOC: add docstring examples

* DOC: update usage section

* TST: exclude Base._copy_file() from Windows coverage

* DOC: update developer section

* Update audbackend/core/backend/base.py

Co-authored-by: Hagen Wierstorf <[email protected]>

* Update audbackend/core/interface/unversioned.py

Co-authored-by: Hagen Wierstorf <[email protected]>

* Update audbackend/core/interface/versioned.py

Co-authored-by: Hagen Wierstorf <[email protected]>

* Update docs/usage.rst

Co-authored-by: Hagen Wierstorf <[email protected]>

* DOC: fix typo

---------

Co-authored-by: Hagen Wierstorf <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants