mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
summon: artifacs.yaml -> dvcsummon.yaml; artifact -> object
This commit is contained in:
+9
-11
@@ -75,22 +75,20 @@ def _make_repo(repo_url, rev=None):
|
||||
|
||||
|
||||
def summon(name, params=None, repo=None, rev=None):
|
||||
# 1. Read artifacts.yaml
|
||||
# 1. Read dvcsummon.yaml
|
||||
# 2. Pull dependencies
|
||||
# 3. Get the call and parameters
|
||||
# 4. Invoke the call with the given parameters
|
||||
# 5. Return the result
|
||||
|
||||
with _make_repo(repo, rev=rev) as _repo:
|
||||
artifacts_path = os.path.join(_repo.root_dir, "artifacts.yaml")
|
||||
dvcsummon_path = os.path.join(_repo.root_dir, "dvcsummon.yaml")
|
||||
|
||||
with open(artifacts_path, "r") as fobj:
|
||||
artifacts = ruamel.yaml.safe_load(fobj.read()).get("artifacts")
|
||||
artifact = next(x for x in artifacts if x.get("name") == name)
|
||||
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)
|
||||
|
||||
outs = [
|
||||
_repo.find_out_by_relpath(dep) for dep in artifact.get("deps", ())
|
||||
]
|
||||
outs = [_repo.find_out_by_relpath(dep) for dep in obj.get("deps", ())]
|
||||
|
||||
with _repo.state:
|
||||
for out in outs:
|
||||
@@ -101,12 +99,12 @@ def summon(name, params=None, repo=None, rev=None):
|
||||
|
||||
os.chdir(_repo.root_dir)
|
||||
|
||||
artifact_path = os.path.join(_repo.root_dir, artifact.get("file"))
|
||||
artifact_path = os.path.join(_repo.root_dir, obj.get("file"))
|
||||
spec = importlib.util.spec_from_file_location(name, artifact_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
method = getattr(module, artifact.get("method"))
|
||||
_params = artifact.get("params")
|
||||
method = getattr(module, obj.get("method"))
|
||||
_params = obj.get("params")
|
||||
|
||||
if params:
|
||||
_params.update(params)
|
||||
|
||||
@@ -131,9 +131,9 @@ def test_open_not_cached(dvc):
|
||||
|
||||
|
||||
def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
|
||||
artifacts_yaml = ruamel.yaml.dump(
|
||||
dvcsummon_yaml = ruamel.yaml.dump(
|
||||
{
|
||||
"artifacts": [
|
||||
"objects": [
|
||||
{
|
||||
"name": "sum",
|
||||
"description": "Add <x> to <number>",
|
||||
@@ -151,7 +151,7 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
|
||||
m.chdir(fspath(erepo_dir))
|
||||
|
||||
erepo_dir.dvc_gen("number", "100", commit="Add number.dvc")
|
||||
erepo_dir.scm_gen("artifacts.yaml", artifacts_yaml)
|
||||
erepo_dir.scm_gen("dvcsummon.yaml", dvcsummon_yaml)
|
||||
erepo_dir.scm_gen(
|
||||
"calculator.py",
|
||||
"def add_to_num(x): return x + int(open('number').read())",
|
||||
|
||||
Reference in New Issue
Block a user