allow multiple environment decorators
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.
@savingoyal -- could you comment on this one (you had some comments)