Skip to content

Commit

Permalink
Merge pull request #3204 from efiop/3087
Browse files Browse the repository at this point in the history
erepo: fix DependencyREPO schema
  • Loading branch information
efiop authored Jan 21, 2020
2 parents cb64491 + 2305549 commit 6958901
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dvc/dependency/repo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from voluptuous import Required

from .local import DependencyLOCAL
from dvc.exceptions import OutputNotFoundError
from dvc.path_info import PathInfo
Expand All @@ -11,7 +13,11 @@ class DependencyREPO(DependencyLOCAL):
PARAM_REV = "rev"
PARAM_REV_LOCK = "rev_lock"

REPO_SCHEMA = {PARAM_URL: str, PARAM_REV: str, PARAM_REV_LOCK: str}
REPO_SCHEMA = {
Required(PARAM_URL): str,
PARAM_REV: str,
PARAM_REV_LOCK: str,
}

def __init__(self, def_repo, stage, *args, **kwargs):
self.def_repo = def_repo
Expand All @@ -27,7 +33,8 @@ def is_in_repo(self):
@property
def repo_pair(self):
d = self.def_repo
return d[self.PARAM_URL], d[self.PARAM_REV_LOCK] or d[self.PARAM_REV]
rev = d.get(self.PARAM_REV_LOCK) or d.get(self.PARAM_REV)
return d[self.PARAM_URL], rev

def __str__(self):
return "{} ({})".format(self.def_path, self.def_repo[self.PARAM_URL])
Expand Down
18 changes: 18 additions & 0 deletions tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,21 @@ def test_import_non_existing(erepo_dir, tmp_dir, dvc):
# https://github.com/iterative/dvc/pull/2837#discussion_r352123053
with pytest.raises(PathMissingError):
tmp_dir.dvc.imp(fspath(erepo_dir), "/root/", "root")


def test_pull_no_rev_lock(erepo_dir, tmp_dir, dvc):
with erepo_dir.chdir():
erepo_dir.dvc_gen("foo", "contents", commit="create foo")

stage = dvc.imp(fspath(erepo_dir), "foo", "foo_imported")
assert "rev" not in stage.deps[0].def_repo
stage.deps[0].def_repo.pop("rev_lock")
stage.dump()

os.remove(stage.outs[0].cache_path)
(tmp_dir / "foo_imported").unlink()

dvc.pull([stage.path])

assert (tmp_dir / "foo_imported").is_file()
assert (tmp_dir / "foo_imported").read_text() == "contents"

0 comments on commit 6958901

Please sign in to comment.