mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-05 23:09:32 +01:00
summon: params -> args; use summon key in yaml
This commit is contained in:
+9
-7
@@ -76,7 +76,7 @@ def _make_repo(repo_url, rev=None):
|
||||
yield repo
|
||||
|
||||
|
||||
def summon(name, params=None, repo=None, rev=None):
|
||||
def summon(name, args=None, repo=None, rev=None):
|
||||
# 1. Read dvcsummon.yaml
|
||||
# 2. Pull dependencies
|
||||
# 3. Get the call and parameters
|
||||
@@ -89,8 +89,11 @@ def summon(name, params=None, repo=None, rev=None):
|
||||
with open(dvcsummon_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")
|
||||
|
||||
outs = [_repo.find_out_by_relpath(dep) for dep in obj.get("deps", ())]
|
||||
outs = [
|
||||
_repo.find_out_by_relpath(dep) for dep in _summon.get("deps", ())
|
||||
]
|
||||
|
||||
with _repo.state:
|
||||
for out in outs:
|
||||
@@ -98,13 +101,12 @@ def summon(name, params=None, repo=None, rev=None):
|
||||
out.checkout()
|
||||
|
||||
with _chdir_and_syspath(_repo.root_dir):
|
||||
call = _import_string(obj.get("call"))
|
||||
_params = obj.get("params")
|
||||
call = _import_string(_summon.get("call"))
|
||||
|
||||
if params:
|
||||
_params.update(params)
|
||||
if args:
|
||||
_summon.get("args").update(args)
|
||||
|
||||
result = call(**_params)
|
||||
result = call(**_summon.get("args"))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -137,9 +137,12 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
|
||||
{
|
||||
"name": "sum",
|
||||
"description": "Add <x> to <number>",
|
||||
"call": "calculator.add_to_num",
|
||||
"params": {"x": 1},
|
||||
"deps": ["number"],
|
||||
"summon": {
|
||||
"type": "python",
|
||||
"call": "calculator.add_to_num",
|
||||
"args": {"x": 1},
|
||||
"deps": ["number"],
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -160,4 +163,4 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
|
||||
repo_url = "file://{}".format(erepo_dir)
|
||||
|
||||
assert api.summon("sum", repo=repo_url) == 101
|
||||
assert api.summon("sum", repo=repo_url, params={"x": 2}) == 102
|
||||
assert api.summon("sum", repo=repo_url, args={"x": 2}) == 102
|
||||
|
||||
Reference in New Issue
Block a user