mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
summon: allow different YAML file names
This commit is contained in:
+4
-3
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user