Skip to content

Commit

Permalink
import: just inform that output not found
Browse files Browse the repository at this point in the history
  • Loading branch information
pared committed Nov 19, 2019
1 parent e5aaf98 commit 5a92c46
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 23 deletions.
6 changes: 3 additions & 3 deletions dvc/dependency/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def _make_repo(self, **overrides):

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"}
Expand All @@ -71,7 +71,7 @@ def fetch(self):
) 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())

Expand Down
9 changes: 3 additions & 6 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)

Expand Down Expand Up @@ -343,9 +342,7 @@ def __init__(self, url, cause=None):


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."
)
2 changes: 1 addition & 1 deletion dvc/external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 4 additions & 10 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,10 @@ def stages(self):
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):
Expand All @@ -438,15 +435,12 @@ def func(out):

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

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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
Expand Down Expand Up @@ -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")

0 comments on commit 5a92c46

Please sign in to comment.