Skip to content

Commit

Permalink
api.get_url: use index remote storage for getting remote URL
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Jul 3, 2023
1 parent 24d9a05 commit 83a6f9f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions dvc/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,27 @@ def get_url(path, repo=None, rev=None, remote=None):
NOTE: This function does not check for the actual existence of the file or
directory in the remote storage.
"""
with Repo.open(repo, rev=rev, subrepos=True, uninitialized=True) as _repo:
from dvc.config import NoRemoteError
from dvc_data.index import StorageKeyError

repo_kwargs: Dict[str, Any] = {}
if remote:
repo_kwargs["config"] = {"core": {"remote": remote}}
with Repo.open(
repo, rev=rev, subrepos=True, uninitialized=True, **repo_kwargs
) as _repo:
with _wrap_exceptions(_repo, path):
fs_path = _repo.dvcfs.from_os_path(path)

with reraise(FileNotFoundError, PathMissingError(path, repo)):
info = _repo.dvcfs.info(fs_path)

dvc_info = info.get("dvc_info")
if not dvc_info:
raise OutputNotFoundError(path, repo)

dvc_repo = info["repo"] # pylint: disable=unsubscriptable-object
md5 = dvc_info["md5"]

return dvc_repo.cloud.get_url_for(remote, checksum=md5)
key = _repo.fs.path.relparts(fs_path, _repo.root_dir)
index = _repo.index.data["repo"]
with reraise(KeyError, OutputNotFoundError(path, repo)):
entry = index[key]
with reraise(
(StorageKeyError, ValueError),
NoRemoteError(f"no remote specified in {_repo}"),
):
remote_fs, remote_path = index.storage_map.get_remote(entry)
return remote_fs.unstrip_protocol(remote_path)


class _OpenContextManager(GCM):
Expand Down

0 comments on commit 83a6f9f

Please sign in to comment.