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

cli: add: add an --output argument #5284

Closed
wants to merge 1 commit into from

Conversation

mrstegeman
Copy link
Contributor

Allow users to add files from outside of the repo. This is a first
step toward achieving #4657.

References iterative/dvc.org#2101

Thank you for the contribution - we'll try to review it as soon as possible. πŸ™

Allow users to add files from outside of the repo. This is a first
step toward achieving iterative#4657.

References iterative/dvc.org#2101
if dname and not os.path.isdir(dname):
os.makedirs(dname)

shutil.copy2(targets[0], output)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be really slow with big files/dirs. We could be able to add it without this uneeded copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, you are checking that there is only one target in CLI, but not in API (they could be used separately), so targets[0] needs some reassurance.

assert ret == 1

md5, _ = file_md5(fname)
stage = dvc.add(fname, output="foo")[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

You are actually implementing straight-to-cache functionality #4520 for local files here πŸ™‚ We have a WIP for a general straight-to-remote, where we also use -o in add, they are in no way contradictory though.

],
}

os.unlink(fname)
Copy link
Contributor

@efiop efiop Jan 18, 2021

Choose a reason for hiding this comment

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

maybe let's just use tmp_path fixture or smth like that to avoid doing this manually and using file descriptors?

Comment on lines +93 to +99
parser.add_argument(
"-o",
"--output",
type=str,
metavar="<path>",
help="Output path for the file, if it lives outside the repo.",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will clash with --out being introduced in #5198

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be --out, but it won't clash otherwise. They are actually the same thing :)

Copy link
Contributor

@jorgeorpinel jorgeorpinel Jan 19, 2021

Choose a reason for hiding this comment

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

p.s. looking at this to try to understand iterative/dvc.org/pull/2101

Can someone explain what this does with an example, perhaps?

It's also not obvious to me how this is a step towards #4657 which doesn't seem to involve adding external data (but this does).

Thanks!

Copy link
Contributor

@jorgeorpinel jorgeorpinel Jan 19, 2021

Choose a reason for hiding this comment

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

I just noticed your answer @efiop but my questions remain because

They are actually the same thing

--out (from #5198) is not stand-alone, it can only be used along with --to-remote.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW should this maybe be a stand-alone, general option that add can always use (whether the target is external or not)? As disucssed in #5198 (review) πŸ™‚

@efiop
Copy link
Contributor

efiop commented Jan 19, 2021

@mrstegeman We've introduced --out flag as a part of straight-to-remote functionality #4520 , take a look at the upstream, maybe that's enough to get you going with #4657 We are currently working on straight-to-cache that avoids copying the artifact.

Also, feel free to create a WIP draft for #4657 without creating pre-requisite PRs for now. If we agree on implementation, we could take a step back and just send pre-requisites separately. πŸ™‚

@efiop efiop closed this Jan 19, 2021
@mrstegeman mrstegeman deleted the dvc-add-output branch January 19, 2021 20:46
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.

3 participants