Skip to content

Commit be90c38

Browse files
committed
summon: nice up summon code
- proper doc-string for prepare_summon() - summon -> summon_dict in summon() to not overwrite a glo bal name. This was not a bug, but a bad practice, which might have caused some issues in the future. - better name for _get_object_spec()
1 parent d0de9d0 commit be90c38

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

dvc/api.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,29 @@ def summon(name, repo=None, rev=None, summon_file="dvcsummon.yaml", args=None):
110110
name, repo=repo, rev=rev, summon_file=summon_file
111111
) as desc:
112112
try:
113-
summon = SUMMON_PYTHON_SCHEMA(desc.obj["summon"])
113+
summon_dict = SUMMON_PYTHON_SCHEMA(desc.obj["summon"])
114114
except Invalid as exc:
115115
raise SummonError(str(exc)) from exc
116116

117-
_args = {**summon.get("args", {}), **(args or {})}
118-
return _invoke_method(summon["call"], _args, path=desc.repo.root_dir)
117+
_args = {**summon_dict.get("args", {}), **(args or {})}
118+
return _invoke_method(summon_dict["call"], _args, desc.repo.root_dir)
119119

120120

121121
@contextmanager
122122
def prepare_summon(name, repo=None, rev=None, summon_file="dvcsummon.yaml"):
123-
"""Instantiate an object described in the summon file."""
123+
"""Does a couple of things every summon needs as a prerequisite:
124+
clones the repo, parses the summon file and pulls the deps.
125+
126+
Calling code is expected to complete the summon logic following
127+
instructions stated in "summon" dict of the object spec.
128+
129+
Returns a SummonDesc instance, which contains references to a Repo object,
130+
named object specification and resolved paths to deps.
131+
"""
124132
with _make_repo(repo, rev=rev) as _repo:
125133
try:
126134
path = os.path.join(_repo.root_dir, summon_file)
127-
obj = _get_object_desc(name, path)
135+
obj = _get_object_spec(name, path)
128136
yield SummonDesc(_repo, obj)
129137
except SummonError as exc:
130138
raise SummonError(
@@ -158,7 +166,7 @@ def _pull_deps(self):
158166
out.checkout()
159167

160168

161-
def _get_object_desc(name, path):
169+
def _get_object_spec(name, path):
162170
"""
163171
Given a summonable object's name, search for it on the given file
164172
and return its description.

0 commit comments

Comments
 (0)