Dvc: get/import: consider lstrip("/") for data path

Created on 15 Oct 2019  路  16Comments  路  Source: iterative/dvc

E.g. dvc get https://github.com/user/proj /path/to/data -> dvc get https://github.com/user/proj path/to/data. https://discordapp.com/channels/485586884165107732/485596304961962003/633731542539173889 So far, not seeing any reason against it.

enhancement good first issue hacktoberfest help wanted p2-medium ui

Most helpful comment

@shcheklein /path/to/data is an absolute path, but when it is supplied as an argument to dvc get/import we can assume that user meant path/to/data, because abs path in this context doesn't make any sense unless the user is confused by the "root" concept and thinks that "root" is the repo he is importing from.

All 16 comments

it sounds a bit confusing to alter the path that way - /path/to/data is a valid path by itself and is not the same as path/to/data

@shcheklein It is the same for us, because it is a path relative to the dvc repo that we are importing from. It is a safe assumption to prevent errors when users are confused about the concept of root.

@efiop I think I don't get the point tbh. /path/to/data is an absolute path that has a very precise meaning. If we don't want to support them (absolute path), let's just fail fast a write an error instead of some magic.

@shcheklein /path/to/data is an absolute path, but when it is supplied as an argument to dvc get/import we can assume that user meant path/to/data, because abs path in this context doesn't make any sense unless the user is confused by the "root" concept and thinks that "root" is the repo he is importing from.

kk, I think I misunderstood the intention here, was thinking about -o option for whatever reason (not a path inside the project to pull the artifact from).

Hey @efiop , I have just started contributing to open source. I would like to resolve this issue. Can I know in which file the changes need to be made? Or do I need to search for it.

Thank you @efiop . Looks like it has been resolved now.

Oops, thanks for the heads up!

As an alternative we can try first find an absolute path, after that strip and find the relative one. There will be some really rare edge cases where it can backfire.

Another option would be just notifying users that they probably meant a relative path if absolute is not found and let them fix it

+1 for hint

Hi, is this issue open to work on? I would like to take this @efiop @shcheklein
I am thinking of using os.path.exists to check if the path is present. This would work if it's an abs path or a relative path without / on left, else doing path = path.lstrip("/") should remove the slash from relative paths. If anyone would like to share some better approach, please do so.

@SanchiMittal sure, go for it.

Another option would be just notifying users that they probably meant a relative path if absolute is not found and let them fix it

I would personally go with this option though. Any magic can backfire, it's better to be explicit to my mind.

Okay then, shall I raise an error when os.path.exists() returns false? Also how can I check if my changes worked? Is there any specific test for it? Thanks.

If path is not found it probably already raises some error?

In this case all we need to do is to add a message in case path is an absolute one.

Also how can I check if my changes worked?

There are tests for get/import out there, I hope one of them can be adjusted for this case.

I guess you can first locally run any simple get/import with an absolute path? Here are some examples that can be modified - https://dvc.org/doc/start/data-access

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robguinness picture robguinness  路  3Comments

dmpetrov picture dmpetrov  路  3Comments

shcheklein picture shcheklein  路  3Comments

tc-ying picture tc-ying  路  3Comments

anotherbugmaster picture anotherbugmaster  路  3Comments