-
Notifications
You must be signed in to change notification settings - Fork 1.3k
get: handle non-DVC repositories #3097
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
Merged
efiop
merged 20 commits into
treeverse:master
from
fabiosantoscode:feature/3089-get-non-dvc-repositories
Jan 11, 2020
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0dd5647
get: handle non-DVC repositories
fabiosantoscode 07637a6
style: improve code flow and move comments
fabiosantoscode f126f24
doc: change get documentation so that it doesn't imply the target mus…
fabiosantoscode 86b9a1c
get: recoup cache optimal location
fabiosantoscode a01f81e
Update dvc/repo/get.py
fabiosantoscode 6cb7308
Revert "get: recoup cache optimal location"
fabiosantoscode 7873abc
remove unused exception class
fabiosantoscode 6a4f403
change command doc string
fabiosantoscode 51f2fa1
Update dvc/command/get.py
fabiosantoscode 04619d5
Update dvc/command/get.py
fabiosantoscode 9a98622
Update dvc/command/get.py
fabiosantoscode 5b36ffd
Update dvc/command/get.py
fabiosantoscode c16f882
import: update documentation
fabiosantoscode f5e40b2
get: leverage external_repo() context manager for DVC repositories
fabiosantoscode 5fb6640
run black
fabiosantoscode 0e2ef47
remove blank line
fabiosantoscode 9f279b3
forbid absolute paths for plain git repositories
fabiosantoscode 1f2eed8
don't manually clean up git repository
fabiosantoscode f3d234e
deduplicate code
fabiosantoscode de303d4
test removing a file outside a raw git repo
fabiosantoscode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,9 @@ | |
| DvcException, | ||
| NotDvcRepoError, | ||
| OutputNotFoundError, | ||
| UrlNotDvcRepoError, | ||
| PathMissingError, | ||
| ) | ||
| from dvc.external_repo import external_repo | ||
| from dvc.external_repo import external_repo, cached_clone | ||
| from dvc.path_info import PathInfo | ||
| from dvc.stage import Stage | ||
| from dvc.utils import resolve_output | ||
|
|
@@ -42,37 +41,47 @@ def get(url, path, out=None, rev=None): | |
| # and won't work with reflink/hardlink. | ||
| dpath = os.path.dirname(os.path.abspath(out)) | ||
| tmp_dir = os.path.join(dpath, "." + str(shortuuid.uuid())) | ||
| repo_dir = None | ||
| try: | ||
| with external_repo(cache_dir=tmp_dir, url=url, rev=rev) as repo: | ||
| # Try any links possible to avoid data duplication. | ||
| # | ||
| # Not using symlink, because we need to remove cache after we are | ||
| # done, and to make that work we would have to copy data over | ||
| # anyway before removing the cache, so we might just copy it | ||
| # right away. | ||
| # | ||
| # Also, we can't use theoretical "move" link type here, because | ||
| # the same cache file might be used a few times in a directory. | ||
| repo.cache.local.cache_types = ["reflink", "hardlink", "copy"] | ||
|
|
||
| try: | ||
| output = repo.find_out_by_relpath(path) | ||
| except OutputNotFoundError: | ||
| output = None | ||
|
|
||
| if output and output.use_cache: | ||
| _get_cached(repo, output, out) | ||
| else: | ||
| try: | ||
| with external_repo(cache_dir=tmp_dir, url=url, rev=rev) as repo: | ||
| # Try any links possible to avoid data duplication. | ||
| # | ||
| # Not using symlink, because we need to remove cache after we | ||
| # are done, and to make that work we would have to copy data | ||
| # over anyway before removing the cache, so we might just copy | ||
| # it right away. | ||
| # | ||
| # Also, we can't use theoretical "move" link type here, because | ||
| # the same cache file might be used a few times in a directory. | ||
| repo.cache.local.cache_types = ["reflink", "hardlink", "copy"] | ||
|
|
||
| try: | ||
| output = repo.find_out_by_relpath(path) | ||
| except OutputNotFoundError: | ||
| output = None | ||
|
|
||
| if output and output.use_cache: | ||
| _get_cached(repo, output, out) | ||
| return | ||
|
|
||
| # Either an uncached out with absolute path or a user error | ||
| if os.path.isabs(path): | ||
| raise FileNotFoundError | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: remove this extra line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| fs_copy(os.path.join(repo.root_dir, path), out) | ||
| repo_dir = repo.root_dir | ||
|
|
||
| except NotDvcRepoError: | ||
| # Not a DVC repository, continue below and copy from git | ||
| pass | ||
|
|
||
| if os.path.isabs(path): | ||
| raise FileNotFoundError | ||
|
|
||
| if not repo_dir: | ||
| repo_dir = cached_clone(url, rev=rev) | ||
|
|
||
| fs_copy(os.path.join(repo_dir, path), out) | ||
| except (OutputNotFoundError, FileNotFoundError): | ||
| raise PathMissingError(path, url) | ||
| except NotDvcRepoError: | ||
| raise UrlNotDvcRepoError(url) | ||
fabiosantoscode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| finally: | ||
| remove(tmp_dir) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.