-
Couldn't load subscription status.
- Fork 1.3k
external: refactor external_repo() and its users #3190
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
033ef88
9de0643
ee022ea
eb97e0b
72812b5
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 |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| from voluptuous import Schema, Required, Invalid | ||
|
|
||
| from dvc.repo import Repo | ||
| from dvc.exceptions import DvcException, NotDvcRepoError | ||
| from dvc.exceptions import DvcException | ||
| from dvc.external_repo import external_repo | ||
|
|
||
|
|
||
|
|
@@ -60,14 +60,11 @@ def get_url(path, repo=None, rev=None, remote=None): | |
| `repo`. | ||
| NOTE: There is no guarantee that the file actually exists in that location. | ||
| """ | ||
| try: | ||
| with _make_repo(repo, rev=rev) as _repo: | ||
| abspath = os.path.join(_repo.root_dir, path) | ||
| out, = _repo.find_outs_by_path(abspath) | ||
| remote_obj = _repo.cloud.get_remote(remote) | ||
| return str(remote_obj.checksum_to_path_info(out.checksum)) | ||
| except NotDvcRepoError: | ||
| raise UrlNotDvcRepoError(repo) | ||
| with _make_repo(repo, rev=rev) as _repo: | ||
| _require_dvc(_repo) | ||
| out = _repo.find_out_by_relpath(path) | ||
| remote_obj = _repo.cloud.get_remote(remote) | ||
| return str(remote_obj.checksum_to_path_info(out.checksum)) | ||
|
|
||
|
|
||
| def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | ||
|
|
@@ -96,9 +93,8 @@ def __getattr__(self, name): | |
|
|
||
| def _open(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | ||
| with _make_repo(repo, rev=rev) as _repo: | ||
| abspath = os.path.join(_repo.root_dir, path) | ||
| with _repo.open( | ||
| abspath, remote=remote, mode=mode, encoding=encoding | ||
| with _repo.open_by_relpath( | ||
| path, remote=remote, mode=mode, encoding=encoding | ||
| ) as fd: | ||
| yield fd | ||
|
|
||
|
|
@@ -113,10 +109,7 @@ def read(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | |
|
|
||
| @contextmanager | ||
| def _make_repo(repo_url, rev=None): | ||
| if not repo_url or os.path.exists(repo_url): | ||
| assert ( | ||
| rev is None | ||
| ), "Git revisions are not supported for local DVC projects." | ||
| if rev is None and (not repo_url or os.path.exists(repo_url)): | ||
| yield Repo(repo_url) | ||
| else: | ||
| with external_repo(url=repo_url, rev=rev) as repo: | ||
|
Comment on lines
+112
to
115
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. Why is
This comment was marked as resolved.
Sorry, something went wrong. 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, it should just clone the current repo and checkout to given 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. Testing this, I see it works anyway. But is it using 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. p.s. my test script: import dvc.api
print(dvc.api.read('data', rev='HEAD^'))
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. My point is I think 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.
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. Got it. I was just confused by the name |
||
|
|
@@ -149,6 +142,7 @@ def prepare_summon(name, repo=None, rev=None, summon_file="dvcsummon.yaml"): | |
| named object specification and resolved paths to deps. | ||
| """ | ||
| with _make_repo(repo, rev=rev) as _repo: | ||
| _require_dvc(_repo) | ||
| try: | ||
| path = os.path.join(_repo.root_dir, summon_file) | ||
| obj = _get_object_spec(name, path) | ||
|
|
@@ -242,3 +236,8 @@ def _import_string(import_name): | |
| else: | ||
| return importlib.import_module(import_name) | ||
| return getattr(importlib.import_module(module), obj) | ||
|
|
||
|
|
||
| def _require_dvc(repo): | ||
| if not isinstance(repo, Repo): | ||
| raise UrlNotDvcRepoError(repo.url) | ||
Uh oh!
There was an error while loading. Please reload this page.