-
Couldn't load subscription status.
- Fork 1.3k
get: implement --show-url to display only url/path to remote #3156
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
4509f82
eb252e0
fadf60e
f130e18
aa7119a
50206d4
02a73a0
98f6d56
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 | ||
| from dvc.exceptions import DvcException, NotDvcRepoError | ||
| from dvc.external_repo import external_repo | ||
|
|
||
|
|
||
|
|
@@ -43,13 +43,27 @@ class SummonError(DvcException): | |
| pass | ||
|
|
||
|
|
||
| class UrlNotDvcRepoError(DvcException): | ||
| """Thrown if given url is not a DVC repository. | ||
|
|
||
| Args: | ||
| url (str): url to the repository. | ||
| """ | ||
|
|
||
| def __init__(self, url): | ||
| super().__init__("URL '{}' is not a dvc repository.".format(url)) | ||
jorgeorpinel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def get_url(path, repo=None, rev=None, remote=None): | ||
| """Returns an url of a resource specified by path in repo""" | ||
| 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)) | ||
| 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) | ||
|
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'll raise this same error in |
||
|
|
||
|
|
||
| def open(path, repo=None, rev=None, remote=None, mode="r", encoding=None): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,27 @@ | |
|
|
||
|
|
||
| class CmdGet(CmdBaseNoRepo): | ||
| def _show_url(self): | ||
| from dvc.api import get_url | ||
|
|
||
| try: | ||
| url = get_url( | ||
| self.args.path, repo=self.args.url, rev=self.args.rev | ||
| ) | ||
skshetry marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logger.info(url) | ||
| except DvcException: | ||
| logger.exception("failed to show url") | ||
|
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. Capitalization: "Failed to show URL" Maybe end in period 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, the lowercase seems to be used everywhere in the codebase. And, because this is a ➜ dvc get https://github.com/schacon/cowsay install.sh --show-url
ERROR: failed to show url - URL 'https://github.com/schacon/cowsay' is not a dvc repository.
➜ dvc get . dir/file --show-url
ERROR: failed to show url - unable to find DVC-file with output 'dir/file'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. @shcheklein, it's not something that I add, but, I'm utilizing the fact that something will be there. So, it's more like "(what failed) - (the reason)". 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. And, yes, regarding lowercase, I just looked into it and it's not everywhere for other cases of logging, but for 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.
Thanks, good to know this.
➕ 1️⃣ No need to use bad grammar on purpose because of existing bad grammar.
So then 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.
OK I changed this in ec0c39a#diff-3b2745249f7139953ab4b45b382e69e9 but this whole conversation kind of opened a can of worms and that PR (#3220) grew quite a bit 😅 Hoping core team doesn't flip out.
Thanks for the tip. I may review some of these too 😋 |
||
| return 1 | ||
|
|
||
| return 0 | ||
|
|
||
| def run(self): | ||
| if self.args.show_url: | ||
| return self._show_url() | ||
|
|
||
| return self._get_file_from_repo() | ||
|
|
||
| def _get_file_from_repo(self): | ||
| from dvc.repo import Repo | ||
|
|
||
| try: | ||
|
|
@@ -55,4 +75,9 @@ def add_parser(subparsers, parent_parser): | |
| get_parser.add_argument( | ||
| "--rev", nargs="?", help="Git revision (e.g. branch, tag, SHA)" | ||
| ) | ||
| get_parser.add_argument( | ||
| "--show-url", | ||
| action="store_true", | ||
| help="Returns path/url to the location in remote for specified path", | ||
|
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. Could use the description from https://github.com/iterative/dvc/pull/3130/files 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. Though, looks like it is still up for discussion, so i'm sure we will modify it while working on the docs. Let's keep it as is for now 👍 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. Ah yeah I would change this description, its confusing. Sorry, didn't notice before merge...
This comment was marked as resolved.
Sorry, something went wrong. |
||
| ) | ||
| get_parser.set_defaults(func=CmdGet) | ||
Uh oh!
There was an error while loading. Please reload this page.