erepo: fix DependencyREPO schema

URL should be required and rev or rev_lock should be optional.

Related to #3087
This commit is contained in:
Ruslan Kuprieiev
2020-01-21 12:58:33 +02:00
parent 10a7b9d9a8
commit 2305549460
2 changed files with 27 additions and 2 deletions
+9 -2
View File
@@ -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
@@ -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
@@ -27,7 +33,8 @@ class DependencyREPO(DependencyLOCAL):
@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])
+18
View File
@@ -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"