parsing: resolve relative paths when loading parameters (#5734)

* parsing: resolve relative paths when loading parameters

* test with git commits as well
This commit is contained in:
Saugat Pachhai
2021-03-30 23:50:04 +03:00
committed by GitHub
parent b5f31daab0
commit 3b3b5c8997
2 changed files with 17 additions and 3 deletions
+2 -2
View File
@@ -401,9 +401,9 @@ class Context(CtxDict):
):
path, _, keys_str = item.partition(":")
select_keys = lfilter(bool, keys_str.split(",")) if keys_str else None
path_info = wdir / path
abspath = os.path.abspath(path_info)
abspath = os.path.abspath(wdir / path)
path_info = PathInfo(abspath)
if abspath in self.imports:
if not select_keys and self.imports[abspath] is None:
return # allow specifying complete filepath multiple times
+15 -1
View File
@@ -1,10 +1,11 @@
import os
from copy import deepcopy
import pytest
from dvc.parsing import DEFAULT_PARAMS_FILE, DataResolver, ResolveError
from dvc.parsing.context import Context
from dvc.utils.serialize import dump_json, dump_yaml
from dvc.utils.serialize import dump_json, dump_yaml, dumps_yaml
from . import CONTEXT_DATA, RESOLVED_DVC_YAML_DATA, TEMPLATED_DVC_YAML_DATA
@@ -67,6 +68,19 @@ def test_load_vars_from_file(tmp_dir, dvc):
assert resolver.context == expected
def test_load_vars_with_relpath(tmp_dir, scm, dvc):
tmp_dir.scm_gen(DEFAULT_PARAMS_FILE, dumps_yaml(DATA), commit="add params")
subdir = tmp_dir / "subdir"
d = {"vars": [os.path.relpath(tmp_dir / DEFAULT_PARAMS_FILE, subdir)]}
revisions = ["HEAD", "workspace"]
for rev in dvc.brancher(revs=["HEAD"]):
assert rev == revisions.pop()
resolver = DataResolver(dvc, subdir, d)
assert resolver.context == deepcopy(DATA)
def test_partial_vars_doesnot_exist(tmp_dir, dvc):
dump_yaml("test_params.yaml", {"sub1": "sub1"})