mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-13 15:28:27 +01:00
summon: grimoire/spells -> artifacts
This commit is contained in:
+10
-10
@@ -75,22 +75,22 @@ def _make_repo(repo_url, rev=None):
|
||||
|
||||
|
||||
def summon(name, repo=None, rev=None):
|
||||
# 1. Read grimoire.yaml
|
||||
# 1. Read artifacts.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:
|
||||
grimoire_path = os.path.join(_repo.root_dir, "grimoire.yaml")
|
||||
artifacts_path = os.path.join(_repo.root_dir, "artifacts.yaml")
|
||||
|
||||
with open(grimoire_path, "r") as fobj:
|
||||
spells = ruamel.yaml.safe_load(fobj.read()).get("spells")
|
||||
spell = next(x for x in spells if x.get("name") == name)
|
||||
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)
|
||||
|
||||
outs = [
|
||||
_repo.find_outs_by_path(os.path.join(_repo.root_dir, dep))[0]
|
||||
for dep in spell.get("deps")
|
||||
for dep in artifact.get("deps")
|
||||
]
|
||||
|
||||
with _repo.state:
|
||||
@@ -102,12 +102,12 @@ def summon(name, repo=None, rev=None):
|
||||
|
||||
os.chdir(_repo.root_dir)
|
||||
|
||||
spell_path = os.path.join(_repo.root_dir, spell.get("file"))
|
||||
spec = importlib.util.spec_from_file_location(name, spell_path)
|
||||
artifact_path = os.path.join(_repo.root_dir, artifact.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, spell.get("method"))
|
||||
result = method(**spell.get("params"))
|
||||
method = getattr(module, artifact.get("method"))
|
||||
result = method(**artifact.get("params"))
|
||||
|
||||
os.chdir(previous_dir)
|
||||
|
||||
|
||||
@@ -131,9 +131,9 @@ def test_open_not_cached(dvc):
|
||||
|
||||
|
||||
def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
|
||||
grimoire_yaml = ruamel.yaml.dump(
|
||||
artifacts_yaml = ruamel.yaml.dump(
|
||||
{
|
||||
"spells": [
|
||||
"artifacts": [
|
||||
{
|
||||
"name": "sum",
|
||||
"description": "Add <x> to <number>",
|
||||
@@ -152,12 +152,12 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch):
|
||||
|
||||
erepo_dir.dvc_gen("number", "100")
|
||||
|
||||
erepo_dir.scm_gen("grimoire.yaml", grimoire_yaml)
|
||||
erepo_dir.scm_gen("artifacts.yaml", artifacts_yaml)
|
||||
erepo_dir.scm_gen(
|
||||
"calculator.py",
|
||||
"def add_to_num(x): return x + int(open('number').read())",
|
||||
)
|
||||
erepo_dir.scm.add(["number.dvc", "calculator.py", "grimoire.yaml"])
|
||||
erepo_dir.scm.add(["number.dvc", "calculator.py", "artifacts.yaml"])
|
||||
erepo_dir.scm.commit("Add files")
|
||||
|
||||
repo_url = "file://{}".format(erepo_dir)
|
||||
|
||||
Reference in New Issue
Block a user