diff --git a/dvc/api.py b/dvc/api.py index 38b324a65..7f963a4b1 100644 --- a/dvc/api.py +++ b/dvc/api.py @@ -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") diff --git a/tests/func/test_api.py b/tests/func/test_api.py index 0bc124765..0b019d42f 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -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