mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-11 07:18:28 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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"})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user