mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
Skip loading globally used params section again locally for stages (#4859)
We were still trying to load params file used in `use` for local stages which was throwing overwrite error. Thanks to @dmpetrov for pointing out.
This commit is contained in:
+13
-6
@@ -89,12 +89,19 @@ class DataResolver:
|
||||
"%s does not exist for stage %s", params_yaml_file, name
|
||||
)
|
||||
|
||||
params_file = definition.get(PARAMS_KWD, [])
|
||||
for item in params_file:
|
||||
if item and isinstance(item, dict):
|
||||
contexts.append(
|
||||
Context.load_from(self.repo.tree, str(wdir / first(item)))
|
||||
)
|
||||
params_deps = definition.get(PARAMS_KWD, [])
|
||||
params_files = {
|
||||
wdir / first(item)
|
||||
for item in params_deps
|
||||
if item and isinstance(item, dict)
|
||||
}
|
||||
for params_file in params_files - {
|
||||
self.global_ctx_source,
|
||||
params_yaml_file,
|
||||
}:
|
||||
contexts.append(
|
||||
Context.load_from(self.repo.tree, str(params_file))
|
||||
)
|
||||
|
||||
context.merge_update(*contexts)
|
||||
|
||||
|
||||
@@ -429,3 +429,56 @@ def test_set_with_foreach_and_on_stage_definition(tmp_dir, dvc):
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_local_tries_to_load_globally_used_files(tmp_dir, dvc):
|
||||
iterable = {"bar": "bar", "foo": "foo"}
|
||||
dump_json(tmp_dir / "params.json", iterable)
|
||||
|
||||
d = {
|
||||
"use": "params.json",
|
||||
"stages": {
|
||||
"build": {
|
||||
"cmd": "command --value ${bar}",
|
||||
"params": [{"params.json": ["foo"]}],
|
||||
},
|
||||
},
|
||||
}
|
||||
resolver = DataResolver(dvc, PathInfo(str(tmp_dir)), d)
|
||||
assert_stage_equal(
|
||||
resolver.resolve(),
|
||||
{
|
||||
"stages": {
|
||||
"build": {
|
||||
"cmd": "command --value bar",
|
||||
"params": [{"params.json": ["bar", "foo"]}],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_local_tries_to_load_globally_used_params_yaml(tmp_dir, dvc):
|
||||
iterable = {"bar": "bar", "foo": "foo"}
|
||||
dump_yaml(tmp_dir / "params.yaml", iterable)
|
||||
|
||||
d = {
|
||||
"stages": {
|
||||
"build": {
|
||||
"cmd": "command --value ${bar}",
|
||||
"params": [{"params.yaml": ["foo"]}],
|
||||
},
|
||||
},
|
||||
}
|
||||
resolver = DataResolver(dvc, PathInfo(str(tmp_dir)), d)
|
||||
assert_stage_equal(
|
||||
resolver.resolve(),
|
||||
{
|
||||
"stages": {
|
||||
"build": {
|
||||
"cmd": "command --value bar",
|
||||
"params": [{"params.yaml": ["bar", "foo"]}],
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user