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

feat(dataset): use posix mv semantics when adding with destination #2612

Merged
merged 4 commits into from Feb 17, 2022

Conversation

m-alisafaee
Copy link
Contributor

@m-alisafaee m-alisafaee commented Jan 30, 2022

Description

Adding data to a dataset with passing a destination using --destination flag, acts similar to posix cp and mv commands: Added file is renamed it destination doesn't exists or it's a file and it's copied to the destination otherwise.

Fixes #1765

Examples:

renku dataset create my-data
renku dataset add my-data https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc -d sample.doc
renku dataset add /some/directory/* -d new-directory

@m-alisafaee m-alisafaee force-pushed the 1765-dataset-destination branch 3 times, most recently from fdbbb13 to 961bd2f Compare January 31, 2022 10:42
@m-alisafaee m-alisafaee marked this pull request as ready for review January 31, 2022 15:23
@m-alisafaee m-alisafaee requested a review from a team as a code owner January 31, 2022 15:23
"""Add a file or directory from a local filesystem."""
src = Path(os.path.abspath(path))
action = "symlink" if external else "copy"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not something you need to change here, but action seems to be a good candidate for using an Enum

renku/core/management/datasets.py Outdated Show resolved Hide resolved
if multiple_sources and destination_exists and not destination_is_dir:
raise errors.ParameterError(f"Destination is not a directory: '{destination}'")

name = path.name if has_multiple_paths or (destination_exists and destination_is_dir) else ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also with the empty string path join

@@ -59,22 +68,23 @@ def get_relative_paths(base: Union[Path, str], paths: List[Union[Path, str]]) ->
return relative_paths


def get_files_recursively(path: Path) -> Generator[Path, None, None]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is an issue, but the method is called get_files_recursively but then the body is not actually recursive. Should this be

            if not subpath.is_dir():
                yield subpath
            else:
                yield from get_files_recursively(subpath)

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed it to get_files

@m-alisafaee m-alisafaee merged commit 24f843a into develop Feb 17, 2022
@m-alisafaee m-alisafaee deleted the 1765-dataset-destination branch February 17, 2022 13:33
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.

semantics of "destination" on "renku dataset add --destination"
2 participants