mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-07 07:18:27 +01:00
- Overriding a config value : foo.bar=value - Appending a config value : +foo.bar=value - Appending or overriding a config value : ++foo.bar=value - Removing a config value : ~foo.bar, ~foo.bar=value See https://hydra.cc/docs/advanced/override_grammar/basic/#modifying-the-config-object --- Breaking changes: To modify a list, `foo[0]=bar` must now be passed as `foo.0=bar`. Modifying a nested list inside a dictionary is not supported by omegaconf. --- Closes #4883 Closes #5868 Closes #6129
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from collections import defaultdict
|
|
from typing import Dict, Iterable, List
|
|
|
|
|
|
def parse_params(path_params: Iterable[str]) -> List[Dict[str, List[str]]]:
|
|
"""Normalizes the shape of params from the CLI to dict."""
|
|
from dvc.dependency.param import ParamsDependency
|
|
|
|
ret: Dict[str, List[str]] = defaultdict(list)
|
|
for path_param in path_params:
|
|
path, _, params_str = path_param.rpartition(":")
|
|
# remove empty strings from params, on condition such as `-p "file1:"`
|
|
params = filter(bool, params_str.split(","))
|
|
if not path:
|
|
path = ParamsDependency.DEFAULT_PARAMS_FILE
|
|
ret[path].extend(params)
|
|
return [{path: params} for path, params in ret.items()]
|
|
|
|
|
|
def to_path_overrides(
|
|
path_params: Iterable[str],
|
|
) -> Dict[str, List[str]]:
|
|
"""Group overrides by path"""
|
|
from dvc.dependency.param import ParamsDependency
|
|
|
|
path_overrides = defaultdict(list)
|
|
for path_param in path_params:
|
|
|
|
path_and_name = path_param.partition("=")[0]
|
|
if ":" not in path_and_name:
|
|
override = path_param
|
|
path = ParamsDependency.DEFAULT_PARAMS_FILE
|
|
else:
|
|
path, _, override = path_param.partition(":")
|
|
|
|
path_overrides[path].append(override)
|
|
|
|
return dict(path_overrides)
|