Skip to content
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

introduce environment_variable_groups to Step class #160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kenneth-Schroeder
Copy link

I want to make the environment_variable_groups setting accessible from the CLI and from the valohai yaml.
To achieve this, I have created a PR in valohai-cli as well (valohai-cli#323).

I could test my changes on valohai-cli and the local linting here on valohai-yaml, however, the API endpoint seems to validate with an older valohai-yaml version as well, causing an API validation error.

@@ -38,6 +38,7 @@ def __init__(
outputs: Iterable[Any] = (),
mounts: Iterable[Mount] = (),
environment_variables: Iterable[EnvironmentVariable] = (),
environment_variable_groups: List[str] = [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
environment_variable_groups: List[str] = [],
environment_variable_groups: Iterable[str] = (),

Having a list as the type is too restrictive, and especially having a list as the default argument leads to unintuitive behavior.

@@ -68,6 +69,7 @@ def __init__(
EnvironmentVariable,
"name",
)
self.environment_variable_groups = environment_variable_groups
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.environment_variable_groups = environment_variable_groups
self.environment_variable_groups = list(environment_variable_groups)

The argument can be listified here. Calling list() ensures we take a copy of a list, or iterate an iterable into a new list.

Otherwise, doing

foo = []
s1 = Step(..., environment_variable_groups=foo)
s2 = Step(..., environment_variable_groups=foo)
foo.append("bar")

would end up the EVGs for both steps being modified.

That said, we could do better still:

Suggested change
self.environment_variable_groups = environment_variable_groups
self.environment_variable_groups = [str(evg) for evg in environment_variable_groups if evg]

This would implicitly filter out falsy values, and ensure everything else actually is str.

@@ -85,6 +87,7 @@ def parse(cls, data: SerializedDict) -> "Step":
kwargs["stop_condition"] = kwargs.pop("stop-condition", None)
kwargs["upload_store"] = kwargs.pop("upload-store", None)
kwargs["resources"] = WorkloadResources.parse(kwargs.pop("resources", {}))
kwargs["environment_variable_groups"] = kwargs.pop("environment-variable-groups", None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As currently is, None would not be a valid argument for Step(). An empty tuple would be.

Suggested change
kwargs["environment_variable_groups"] = kwargs.pop("environment-variable-groups", None)
kwargs["environment_variable_groups"] = kwargs.pop("environment-variable-groups", ())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants