api: data: set default remote instead of using it directly

Fixes #9139
Fixes #7341 (see https://github.com/iterative/dvc/pull/7363#issuecomment-1032959843)
This commit is contained in:
Ruslan Kuprieiev
2023-04-05 02:47:35 +03:00
parent cf52efb8c3
commit 40f7f34889
3 changed files with 7 additions and 12 deletions
+6 -8
View File
@@ -1,6 +1,6 @@
from contextlib import _GeneratorContextManager as GCM
from contextlib import contextmanager
from typing import Optional
from typing import Any, Dict, Optional
from funcy import reraise
@@ -214,7 +214,11 @@ def open( # noqa, pylint: disable=redefined-builtin
def _open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
with Repo.open(repo, rev=rev, subrepos=True, uninitialized=True) as _repo:
repo_kwargs: Dict[str, Any] = {"subrepos": True, "uninitialized": True}
if remote:
repo_kwargs["config"] = {"core": {"remote": remote}}
with Repo.open(repo, rev=rev, **repo_kwargs) as _repo:
with _wrap_exceptions(_repo, path):
import os
from typing import TYPE_CHECKING, Union
@@ -235,12 +239,6 @@ def _open(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
fs_path = fs.from_os_path(path)
try:
if remote:
remote_odb = _repo.cloud.get_remote_odb(name=remote)
oid = fs.info(fs_path)["dvc_info"]["md5"]
fs = remote_odb.fs
fs_path = remote_odb.oid_to_path(oid)
with fs.open(
fs_path,
mode=mode,
+1
View File
@@ -43,6 +43,7 @@ def external_repo(
config = _get_remote_config(url) if os.path.isdir(url) else {}
config.update(cache_config)
config.update(kwargs.pop("config", None) or {})
main_root = "/"
if for_write:
-4
View File
@@ -193,10 +193,6 @@ def test_get_url_subrepos(tmp_dir, scm, local_cloud):
assert api.get_url("subrepo/bar") == expected_url
@pytest.mark.xfail(
raises=PathMissingError,
reason="https://github.com/iterative/dvc/issues/7341",
)
def test_open_from_remote(tmp_dir, erepo_dir, cloud, local_cloud):
erepo_dir.add_remote(config=cloud.config, name="other")
erepo_dir.add_remote(config=local_cloud.config, default=True)