From 05db79e7cf5eb9a261d1e1676028edb99536eb5c Mon Sep 17 00:00:00 2001 From: Dave Berenbaum Date: Fri, 10 May 2024 10:19:03 -0400 Subject: [PATCH] add dvc artifacts get --show-url --- dvc/commands/artifacts.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dvc/commands/artifacts.py b/dvc/commands/artifacts.py index fc96c14eac..38a8b2796c 100644 --- a/dvc/commands/artifacts.py +++ b/dvc/commands/artifacts.py @@ -13,6 +13,9 @@ def run(self): from dvc.scm import CloneError from dvc.ui import ui + if self.args.show_url: + return self._show_url() + try: count, out = Artifacts.get( self.args.url, @@ -36,6 +39,28 @@ def run(self): ) return 1 + def _show_url(self): + from dvc.api import artifacts_show, get_url + from dvc.ui import ui + + artifact = artifacts_show( + self.args.name, + version=self.args.rev, + stage=self.args.stage, + repo=self.args.url, + ) + + url = get_url( + artifact["path"], + repo=self.args.url, + rev=artifact["rev"], + remote=self.args.remote, + remote_config=self.args.remote_config, + ) + ui.write(url, force=True) + + return 0 + def add_parser(subparsers, parent_parser): ARTIFACTS_HELP = "DVC model registry artifact commands." @@ -84,6 +109,14 @@ def add_parser(subparsers, parent_parser): help="Destination path to download artifact to", metavar="", ).complete = completion.DIR + get_parser.add_argument( + "--show-url", + action="store_true", + help=( + "Print the storage location (URL) the target data would be " + "downloaded from, and exit." + ), + ) get_parser.add_argument( "-j", "--jobs",