diff --git a/dvc/dependency/repo.py b/dvc/dependency/repo.py index 68cd044a1..20439c024 100644 --- a/dvc/dependency/repo.py +++ b/dvc/dependency/repo.py @@ -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()) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 369b33ac7..ce30ffa88 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -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." ) diff --git a/dvc/external_repo.py b/dvc/external_repo.py index d528af6a5..e86c02926 100644 --- a/dvc/external_repo.py +++ b/dvc/external_repo.py @@ -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() diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index 86d6a343c..9f6284ef4 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -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 diff --git a/dvc/repo/fetch.py b/dvc/repo/fetch.py index 0440dddae..531fd4d53 100644 --- a/dvc/repo/fetch.py +++ b/dvc/repo/fetch.py @@ -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( diff --git a/dvc/repo/get.py b/dvc/repo/get.py index 64ca5eaf0..21d01ed7e 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -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)) diff --git a/tests/func/test_import.py b/tests/func/test_import.py index 06e8f8c83..067d5be8e 100644 --- a/tests/func/test_import.py +++ b/tests/func/test_import.py @@ -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")