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

allow multiple environment decorators #1785

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

Conversation

amerberg
Copy link
Contributor

@amerberg amerberg commented Mar 29, 2024

Allow multiple environment decorators on a step. This is helpful when a user wants to set some environment variables in code and others from the CLI using --with. When multiple environment decorators are supplied, the vars for each decorator are set in order. A message is logged in the case of conflicting values.

I've tested with the following example flow:

import os

from metaflow import (
     environment,
     step,
     FlowSpec,
)


class EnvFlow(FlowSpec):

    @environment(vars={"VAR1": "val1"})
    @environment(vars={"VAR2": "val1"})
    @environment(vars={"VAR3": "val1"})
    @step
    def start(self):
        print(f"VAR1 = {os.getenv('VAR1')}")
        print(f"VAR2 = {os.getenv('VAR2')}")
        print(f"VAR3 = {os.getenv('VAR3')}")
        self.next(self.end)

    @environment(vars={"VAR1": "val2", "VAR2": "val3"})
    @step
    def end(self):
        print(f"VAR1 = {os.getenv('VAR1')}")
        print(f"VAR2 = {os.getenv('VAR2')}")
        pass


if __name__ == "__main__":
    EnvFlow()

I've run --with environment:vars='{"VAR1":"val4", "VAR2":"val3"}' both locally and on Argo Workflows. Environment variables have the correct values in both cases, though in the case of Argo, the messages about the conflicting values are logged when argo-workflows create is run, rather than when the workflow is run.

@romain-intel
Copy link
Contributor

@savingoyal -- could you comment on this one (you had some comments)

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.

None yet

2 participants