Skip to content

Commit

Permalink
Warn but don't die if a pipeline parameter is missing targets (#144)
Browse files Browse the repository at this point in the history
* Add more commits to git-blame-ignore-revs

* Warn but don't die if a pipeline parameter is missing targets
  • Loading branch information
akx committed Feb 22, 2024
1 parent 26e3279 commit e19979c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Reformatted with Black
e77db53f6c52c37e8a0bfa79f7bf3f07f0fa19d8

# Enable COM rule
98bf400c9017be60841d15df306faccd2ba71c90

# Reformat with ruff-format
f02536612abdaefec2b9eaf19d5a5c4c3507a3cb
9 changes: 9 additions & 0 deletions tests/__snapshots__/test_validation.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,12 @@

'''
# ---
# name: test_warning_examples_cli[targetless-pipeline-params.yaml]
'''
>>> targetless-pipeline-params.yaml
warning: Pipeline "Example Pipeline with Parameter with no Target" parameter "id": no targets.
------------------------------------------------------------
*** 0 errors, 1 warnings

'''
# ---
20 changes: 20 additions & 0 deletions tests/warning_examples/targetless-pipeline-params.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- step:
name: train_step
image: python:3.10
command:
- pip install valohai-utils
- python ./train.py {parameters}
parameters:
- name: id
type: string

- pipeline:
name: Example Pipeline with Parameter with no Target
parameters:
- name: id
default: 123
nodes:
- name: train
step: train_step
type: execution
edges: []
10 changes: 8 additions & 2 deletions valohai_yaml/objs/pipelines/pipeline_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def __init__(
self,
*,
name: str,
targets: Union[List[str], str],
targets: Optional[Union[List[str], str]] = None,
value: Optional[str] = None,
default: Optional[str] = None,
) -> None:
self.name = name
self.default = default if value is None else value
if isinstance(targets, str):
if not targets:
self.targets = []
elif isinstance(targets, str):
self.targets = [targets]
else:
self.targets = check_type_and_listify(targets, str)
Expand All @@ -45,6 +47,10 @@ def lint(self, lint_result: LintResult, context: LintContext) -> None:
config: Config = context["config"]
steps = config.steps
node_map = pipeline.node_map
if not self.targets:
lint_result.add_warning(
f'Pipeline "{pipeline.name}" parameter "{self.name}": no targets.',
)
for target in self.targets:
target_node_name, socket_type, target_parameter_name = split_socket_str(
target,
Expand Down

0 comments on commit e19979c

Please sign in to comment.