import: just inform that output not found

This commit is contained in:
Paweł Redzyński
2019-11-19 14:48:28 +01:00
parent e5aaf98776
commit 5a92c46033
7 changed files with 19 additions and 23 deletions
+3 -3
View File
@@ -49,10 +49,10 @@ class DependencyREPO(DependencyLOCAL):
def status(self):
with self._make_repo() as repo:
current = repo.find_out_by_path(self.def_path).info
current = repo.find_out_by_relpath(self.def_path).info
with self._make_repo(rev_lock=None) as repo:
updated = repo.find_out_by_path(self.def_path).info
updated = repo.find_out_by_relpath(self.def_path).info
if current != updated:
return {str(self): "update available"}
@@ -71,7 +71,7 @@ class DependencyREPO(DependencyLOCAL):
) as repo:
self.def_repo[self.PARAM_REV_LOCK] = repo.scm.get_rev()
out = repo.find_out_by_path(self.def_path)
out = repo.find_out_by_relpath(self.def_path)
with repo.state:
repo.cloud.pull(out.get_used_cache())
+3 -6
View File
@@ -61,10 +61,9 @@ class OutputNotFoundError(DvcException):
def __init__(self, output, repo=None):
self.repo = repo
self.failed_output = output
super(OutputNotFoundError, self).__init__(
"unable to find DVC-file with output '{path}'".format(
path=relpath(self.failed_output)
path=relpath(output)
)
)
@@ -343,9 +342,7 @@ class RemoteNotSpecifiedInExternalRepoError(DvcException):
class NoOutputInExternalRepoError(DvcException):
def __init__(self, repo_url, path):
def __init__(self):
super(NoOutputInExternalRepoError, self).__init__(
"Output '{}' not found in target repository: '{}'".format(
path, repo_url
)
"Output not found in target repository."
)
+1 -1
View File
@@ -29,7 +29,7 @@ def external_repo(url=None, rev=None, rev_lock=None, cache_dir=None):
raise RemoteNotSpecifiedInExternalRepoError(url, cause=exc)
except OutputNotFoundError as exc:
if exc.repo is repo:
raise NoOutputInExternalRepoError(url, exc.failed_output)
raise NoOutputInExternalRepoError()
raise
repo.close()
+4 -10
View File
@@ -418,13 +418,10 @@ class Repo(object):
return get_stages(self.graph)
def find_outs_by_path(self, path, outs=None, recursive=False):
abs_path = (
path if os.path.isabs(path) else os.path.join(self.root_dir, path)
)
if not outs:
outs = [out for stage in self.stages for out in stage.outs]
abs_path = os.path.abspath(path)
is_dir = self.tree.isdir(abs_path)
def func(out):
@@ -438,15 +435,12 @@ class Repo(object):
matched = list(filter(func, outs))
if not matched:
if abs_path.startswith(self.root_dir):
failed_output = relpath(abs_path)
else:
failed_output = path
raise OutputNotFoundError(failed_output, self)
raise OutputNotFoundError(path, self)
return matched
def find_out_by_path(self, path):
def find_out_by_relpath(self, relpath):
path = os.path.join(self.root_dir, relpath)
out, = self.find_outs_by_path(path)
return out
+1 -1
View File
@@ -81,7 +81,7 @@ def _fetch_external(self, repo_url, repo_rev, files):
cache = NamedCache()
for name in files:
try:
out = repo.find_out_by_path(name)
out = repo.find_out_by_relpath(name)
except OutputNotFoundError:
failed += 1
logger.exception(
+1 -1
View File
@@ -49,7 +49,7 @@ def get(url, path, out=None, rev=None):
# the same cache file might be used a few times in a directory.
repo.cache.local.cache_types = ["reflink", "hardlink", "copy"]
o = repo.find_out_by_path(path)
o = repo.find_out_by_relpath(path)
with repo.state:
repo.cloud.pull(o.get_used_cache())
o.path_info = PathInfo(os.path.abspath(out))
+6 -1
View File
@@ -8,7 +8,7 @@ import pytest
from mock import patch
from dvc.config import Config
from dvc.exceptions import DownloadError
from dvc.exceptions import DownloadError, NoOutputInExternalRepoError
from dvc.stage import Stage
from dvc.system import System
from dvc.utils import makedirs
@@ -154,3 +154,8 @@ def test_pull_non_workspace(git, dvc_repo, erepo):
os.remove(stage.outs[0].cache_path)
dvc_repo.fetch(all_tags=True)
assert os.path.exists(stage.outs[0].cache_path)
def test_import_non_existing(dvc_repo, erepo):
with pytest.raises(NoOutputInExternalRepoError):
dvc_repo.imp(erepo.root_dir, "invalid_output")