Skip to content

Commit

Permalink
TaskSpec.with_contraint takes kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
epwalsh committed Nov 7, 2022
1 parent 207b5e6 commit 7a075b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use patch releases for compatibility fixes instead.

## Unreleased

### Changed

- `TaskSpec.with_contraint` now takes `**kwargs` instead of two positional arguments.

## [v1.11.3](https://github.com/allenai/beaker-py/releases/tag/v1.11.3) - 2022-10-28

### Added
Expand Down
9 changes: 4 additions & 5 deletions beaker/data_model/experiment_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,25 +583,24 @@ def with_env_var(
},
)

def with_constraint(self, constraint_type: str, constraint_values: List[str]) -> "TaskSpec":
def with_constraint(self, **kwargs: List[str]) -> "TaskSpec":
"""
Return a new :class:`TaskSpec` with the given :data:`constraint`.
:param constraint_type: The type of constraint, e.g. :data:`cluster`.
:param constraint_values: The list of constraint values, such as a list of cluster names.
:param kwargs: Constraint name, constraint values.
:examples:
>>> task_spec = TaskSpec.new(
... "hello-world",
... docker_image="hello-world",
... ).with_constraint('cluster', ['ai2/cpu-cluster'])
... ).with_constraint(cluster=['ai2/cpu-cluster'])
>>> assert task_spec.constraints['cluster'] == ['ai2/cpu-cluster']
"""
return self.copy(
deep=True,
update={
"constraints": {**(self.constraints or {}), constraint_type: constraint_values},
"constraints": {**(self.constraints or {}), **kwargs},
},
)

Expand Down

0 comments on commit 7a075b9

Please sign in to comment.