summon: allow different YAML file names

This commit is contained in:
Mr. Outis
2019-12-18 23:38:52 -06:00
parent c852d3316d
commit addc56c232
2 changed files with 6 additions and 3 deletions
+4 -3
View File
@@ -76,7 +76,7 @@ def _make_repo(repo_url, rev=None):
yield repo
def summon(name, args=None, repo=None, rev=None):
def summon(name, fname=None, args=None, repo=None, rev=None):
# 1. Read dvcsummon.yaml
# 2. Pull dependencies
# 3. Get the call and parameters
@@ -84,9 +84,10 @@ def summon(name, args=None, repo=None, rev=None):
# 5. Return the result
with _make_repo(repo, rev=rev) as _repo:
dvcsummon_path = os.path.join(_repo.root_dir, "dvcsummon.yaml")
fname = fname or "dvcsummon.yaml"
summon_path = os.path.join(_repo.root_dir, fname)
with open(dvcsummon_path, "r") as fobj:
with open(summon_path, "r") as fobj:
objects = ruamel.yaml.safe_load(fobj.read()).get("objects")
obj = next(x for x in objects if x.get("name") == name)
_summon = obj.get("summon")
+2
View File
@@ -154,6 +154,7 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
erepo_dir.dvc_gen("number", "100", commit="Add number.dvc")
erepo_dir.scm_gen("dvcsummon.yaml", dvcsummon_yaml)
erepo_dir.scm_gen("non-canon.yaml", dvcsummon_yaml)
erepo_dir.scm_gen(
"calculator.py",
"def add_to_num(x): return x + int(open('number').read())",
@@ -164,3 +165,4 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
assert api.summon("sum", repo=repo_url) == 101
assert api.summon("sum", repo=repo_url, args={"x": 2}) == 102
assert api.summon("sum", repo=repo_url, fname="non-canon.yaml") == 101