-
Notifications
You must be signed in to change notification settings - Fork 1.3k
refactor/test multistage load for params and outputs #3949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d4e7806
f9a6687
6a0028e
45cb261
40ae3c7
44cb837
3a0a9b8
54a450e
339d833
0fdd944
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,26 +87,29 @@ def loads_from(stage, s_list, erepo=None): | |
| return ret | ||
|
|
||
|
|
||
| def _parse_params(path_params): | ||
| path, _, params_str = path_params.rpartition(":") | ||
| params = params_str.split(",") | ||
| return path, params | ||
| def _merge_params(s_list): | ||
| d = defaultdict(list) | ||
| default_file = ParamsDependency.DEFAULT_PARAMS_FILE | ||
| for key in s_list: | ||
| if isinstance(key, str): | ||
| d[default_file].append(key) | ||
| continue | ||
| if not isinstance(key, dict): | ||
| msg = "Only list of str/dict is supported. Got: " | ||
| msg += f"'{type(key).__name__}'." | ||
| raise ValueError(msg) | ||
|
|
||
| for k, params in key.items(): | ||
| if not isinstance(params, list): | ||
| msg = "Expected list of params for custom params file " | ||
| msg += f"'{k}', got '{type(params).__name__}'." | ||
| raise ValueError(msg) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't want to add assertions, so, I have used ValueError. They are purely internal, as error are likely to be raised by schema validators before even reaching here. |
||
| d[k].extend(params) | ||
| return d | ||
|
|
||
|
|
||
| def loads_params(stage, s_list): | ||
| # Creates an object for each unique file that is referenced in the list | ||
| params_by_path = defaultdict(list) | ||
| for s in s_list: | ||
| path, params = _parse_params(s) | ||
| params_by_path[path].extend(params) | ||
|
|
||
| d_list = [] | ||
| for path, params in params_by_path.items(): | ||
| d_list.append( | ||
| { | ||
| BaseOutput.PARAM_PATH: path, | ||
| ParamsDependency.PARAM_PARAMS: params, | ||
| } | ||
| ) | ||
|
|
||
| return loadd_from(stage, d_list) | ||
| d = _merge_params(s_list) | ||
| return [ | ||
| ParamsDependency(stage, path, params) for path, params in d.items() | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import os | ||
|
|
||
| from funcy import concat, first | ||
| from funcy import concat, first, lfilter | ||
|
|
||
| from dvc.exceptions import InvalidArgumentError | ||
| from dvc.stage.exceptions import ( | ||
|
|
@@ -20,6 +20,19 @@ def is_valid_name(name: str): | |
| return not INVALID_STAGENAME_CHARS & set(name) | ||
|
|
||
|
|
||
| def parse_params(path_params): | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function outputs same structure as present in pipeline file. |
||
| ret = [] | ||
| for path_param in path_params: | ||
| path, _, params_str = path_param.rpartition(":") | ||
| # remove empty strings from params, on condition such as `-p "file1:"` | ||
| params = lfilter(bool, params_str.split(",")) | ||
| if not path: | ||
| ret.extend(params) | ||
| else: | ||
| ret.append({path: params}) | ||
| return ret | ||
|
|
||
|
|
||
| def _get_file_path(kwargs): | ||
| from dvc.dvcfile import DVC_FILE_SUFFIX, DVC_FILE | ||
|
|
||
|
|
@@ -72,7 +85,10 @@ def run(self, fname=None, no_exec=False, single_stage=False, **kwargs): | |
| if not is_valid_name(stage_name): | ||
| raise InvalidStageName | ||
|
|
||
| stage = create_stage(stage_cls, repo=self, path=path, **kwargs) | ||
| params = parse_params(kwargs.pop("params", [])) | ||
| stage = create_stage( | ||
| stage_cls, repo=self, path=path, params=params, **kwargs | ||
| ) | ||
| if stage is None: | ||
| return None | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this function to
repo.run().