-
Notifications
You must be signed in to change notification settings - Fork 1.3k
use cache dir as a default remote when importing from local repo #2915
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
Changes from all commits
0dd310d
9e24be1
779a0a1
e1c5f6c
ca20a1c
c6050ef
610e43a
17d47ce
84616e8
5b9daea
b271368
a1ae357
40c392d
e6285f7
e1e0cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,9 @@ | |
|
|
||
| from funcy import retry | ||
|
|
||
| from dvc.config import NoRemoteError | ||
maykulkarni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from dvc.config import NoRemoteError, ConfigError | ||
| from dvc.exceptions import NoRemoteInExternalRepoError | ||
| from dvc.remote import RemoteConfig | ||
| from dvc.exceptions import NoOutputInExternalRepoError | ||
| from dvc.exceptions import OutputNotFoundError | ||
| from dvc.utils.fs import remove | ||
|
|
@@ -69,6 +70,22 @@ def _external_repo(url=None, rev=None, cache_dir=None): | |
|
|
||
| repo = Repo(new_path) | ||
| try: | ||
| # check if the URL is local and no default remote is present | ||
| # add default remote pointing to the original repo's cache location | ||
| if os.path.isdir(url): | ||
maykulkarni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rconfig = RemoteConfig(repo.config) | ||
| if not _default_remote_set(rconfig): | ||
|
Comment on lines
+73
to
+77
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. @maykulkarni @efiop does this logic mean that if there's a default remote setup, still DVC skips the local cache? Because I think it should try the local cache first regardless of remotes.
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. @jorgeorpinel Yes, precisely. It is hard for us to try both right now, as we don't have that kind of cascading remote logic implemented. I would wait for someone to ask for this.
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. Sorry, I'm not sure I understand:
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.
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. I see. OK! |
||
| original_repo = Repo(url) | ||
| try: | ||
| rconfig.add( | ||
| "auto-generated-upstream", | ||
| original_repo.cache.local.cache_dir, | ||
| default=True, | ||
| level=Config.LEVEL_LOCAL, | ||
| ) | ||
| finally: | ||
| original_repo.close() | ||
|
|
||
| if cache_dir is not None: | ||
| cache_config = CacheConfig(repo.config) | ||
| cache_config.set_dir(cache_dir, level=Config.LEVEL_LOCAL) | ||
|
|
@@ -113,3 +130,19 @@ def _clone_repo(url, path): | |
|
|
||
| git = Git.clone(url, path) | ||
| git.close() | ||
|
|
||
|
|
||
| def _default_remote_set(rconfig): | ||
| """ | ||
| Checks if default remote config is present. | ||
| Args: | ||
| rconfig: a remote config | ||
|
|
||
| Returns: | ||
| True if the default remote config is set, else False | ||
| """ | ||
| try: | ||
| rconfig.get_default() | ||
| return True | ||
| except ConfigError: | ||
| return False | ||
Uh oh!
There was an error while loading. Please reload this page.