diff --git a/dvc/api.py b/dvc/api.py index 7bde1b0be..013eb0a51 100644 --- a/dvc/api.py +++ b/dvc/api.py @@ -9,12 +9,13 @@ try: except ImportError: from contextlib import GeneratorContextManager as GCM +from dvc.utils.compat import urlparse, builtin_str + import ruamel.yaml from voluptuous import Schema, Required, Invalid -from dvc.utils.compat import urlparse, builtin_str from dvc.repo import Repo -from dvc.exceptions import SummonError, FileMissingError +from dvc.exceptions import DvcException, FileMissingError from dvc.external_repo import external_repo @@ -36,6 +37,10 @@ SUMMON_SCHEMA = Schema( ) +class SummonError(DvcException): + pass + + def get_url(path, repo=None, rev=None, remote=None): """Returns an url of a resource specified by path in repo""" with _make_repo(repo, rev=rev) as _repo: @@ -109,7 +114,7 @@ def summon(name, repo=None, rev=None, summon_file="dvcsummon.yaml", args=None): cause=exc.cause, ) - _pull_dependencies(_repo, info.get("deps")) + _pull_dependencies(_repo, info.get("deps", [])) _args = copy.deepcopy(info.get("args", {})) _args.update(args or {}) diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 18ec671f2..7151e2e2f 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -353,7 +353,3 @@ class PathMissingError(DvcException): " neighther as an output nor a git-handled file." ) super(PathMissingError, self).__init__(msg.format(path, repo)) - - -class SummonError(DvcException): - pass diff --git a/tests/func/test_api.py b/tests/func/test_api.py index bff3abe51..ba05e9a9c 100644 --- a/tests/func/test_api.py +++ b/tests/func/test_api.py @@ -8,12 +8,12 @@ import ruamel.yaml import pytest from dvc import api +from dvc.api import SummonError from dvc.exceptions import FileMissingError from dvc.main import main from dvc.path_info import URLInfo from dvc.remote.config import RemoteConfig from dvc.utils.compat import fspath -from dvc.exceptions import SummonError from tests.remotes import Azure, GCP, HDFS, Local, OSS, S3, SSH @@ -148,27 +148,21 @@ def test_summon(tmp_dir, erepo_dir, dvc, monkeypatch): ] } - different_objects = copy.deepcopy(objects) - different_objects["objects"][0]["summon"]["args"]["x"] = 100 + other_objects = copy.deepcopy(objects) + other_objects["objects"][0]["summon"]["args"]["x"] = 100 dup_objects = copy.deepcopy(objects) dup_objects["objects"] *= 2 - dvcsummon_yaml = ruamel.yaml.dump(objects) - different_yaml = ruamel.yaml.dump(different_objects) - dup_yaml = ruamel.yaml.dump(dup_objects) - invalid_yaml = ruamel.yaml.dump({"name": "sum"}) - not_yaml = "a: - this is not a valid YAML file" - with monkeypatch.context() as m: m.chdir(fspath(erepo_dir)) erepo_dir.dvc_gen("number", "100", commit="Add number.dvc") - erepo_dir.scm_gen("dvcsummon.yaml", dvcsummon_yaml) - erepo_dir.scm_gen("different.yaml", different_yaml) - erepo_dir.scm_gen("dup.yaml", dup_yaml) - erepo_dir.scm_gen("invalid.yaml", invalid_yaml) - erepo_dir.scm_gen("not_yaml.yaml", not_yaml) + erepo_dir.scm_gen("dvcsummon.yaml", ruamel.yaml.dump(objects)) + erepo_dir.scm_gen("other.yaml", ruamel.yaml.dump(other_objects)) + erepo_dir.scm_gen("dup.yaml", ruamel.yaml.dump(dup_objects)) + erepo_dir.scm_gen("invalid.yaml", ruamel.yaml.dump({"name": "sum"})) + erepo_dir.scm_gen("not_yaml.yaml", "a: - this is not a YAML file") erepo_dir.scm_gen( "calculator.py", "def add_to_num(x): return x + int(open('number').read())", @@ -179,9 +173,7 @@ 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, summon_file="different.yaml") == 200 - ) + assert api.summon("sum", repo=repo_url, summon_file="other.yaml") == 200 try: api.summon("sum", repo=repo_url, summon_file="missing.yaml")