mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
api: fallback to external_repo on error
This commit is contained in:
+8
-5
@@ -10,7 +10,7 @@ import ruamel.yaml
|
||||
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
|
||||
|
||||
|
||||
@@ -110,10 +110,13 @@ def read(path, repo=None, rev=None, remote=None, mode="r", encoding=None):
|
||||
@contextmanager
|
||||
def _make_repo(repo_url, rev=None):
|
||||
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:
|
||||
yield repo
|
||||
try:
|
||||
yield Repo(repo_url)
|
||||
return
|
||||
except NotDvcRepoError:
|
||||
pass # fallthrough to external_repo
|
||||
with external_repo(url=repo_url, rev=rev) as repo:
|
||||
yield repo
|
||||
|
||||
|
||||
def summon(name, repo=None, rev=None, summon_file="dvcsummon.yaml", args=None):
|
||||
|
||||
@@ -128,10 +128,10 @@ class ExternalGitRepo:
|
||||
raise PathMissingError(path, self.url)
|
||||
|
||||
@contextmanager
|
||||
def open_by_relpath(self, path, mode="r", encoding=None):
|
||||
def open_by_relpath(self, path, mode="r", encoding=None, **kwargs):
|
||||
try:
|
||||
abs_path = os.path.join(self.root_dir, path)
|
||||
with open(abs_path, mode, encoding) as fd:
|
||||
with open(abs_path, mode, encoding=encoding) as fd:
|
||||
yield fd
|
||||
except FileNotFoundError:
|
||||
raise PathMissingError(path, self.url)
|
||||
|
||||
@@ -8,7 +8,7 @@ import pytest
|
||||
from dvc import api
|
||||
from dvc.api import SummonError, UrlNotDvcRepoError
|
||||
from dvc.compat import fspath
|
||||
from dvc.exceptions import FileMissingError, NotDvcRepoError
|
||||
from dvc.exceptions import FileMissingError
|
||||
from dvc.main import main
|
||||
from dvc.path_info import URLInfo
|
||||
from dvc.remote.config import RemoteConfig
|
||||
@@ -54,7 +54,7 @@ def test_get_url_external(erepo_dir, remote_url):
|
||||
def test_get_url_requires_dvc(tmp_dir, scm):
|
||||
tmp_dir.scm_gen({"foo": "foo"}, commit="initial")
|
||||
|
||||
with pytest.raises(NotDvcRepoError, match="not inside of a DVC repo"):
|
||||
with pytest.raises(UrlNotDvcRepoError, match="not a DVC repository"):
|
||||
api.get_url("foo", repo=fspath(tmp_dir))
|
||||
|
||||
with pytest.raises(UrlNotDvcRepoError):
|
||||
|
||||
Reference in New Issue
Block a user