Merge pull request #3222 from skshetry/fallback-external-repo

api: fallback to external_repo if not a DVC repository
This commit is contained in:
Ruslan Kuprieiev
2020-01-23 13:24:33 +02:00
committed by GitHub
3 changed files with 15 additions and 11 deletions
+11 -7
View File
@@ -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
@@ -108,12 +108,16 @@ 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
def _make_repo(repo_url=None, rev=None):
repo_url = repo_url or os.getcwd()
if rev is None and os.path.exists(repo_url):
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):
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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):