big-stone-5971
11/30/2021, 12:25 AM@environment
decorator? If I use the @environment
decorator for them, it doesn’t allow them to call @environment
!straight-shampoo-11124
11/30/2021, 12:49 AMos.environ['SOME_VAR'] = 'SOME_VALUE'
at the top of the modulestraight-shampoo-11124
11/30/2021, 12:50 AM@environment
is only needed if you need to set env vars for the container running on remote systems before the Python code executesbig-stone-5971
11/30/2021, 2:26 AMstraight-shampoo-11124
11/30/2021, 2:28 AMbig-stone-5971
11/30/2021, 2:38 PM@environment(...) # optionally add other env vars
@my_deco # automatically applies API Key default here
@step
def step(...)
straight-shampoo-11124
12/01/2021, 5:40 AMfrom metaflow import FlowSpec, step, Parameter, environment
from functools import wraps
import os
def mykey(f):
@wraps(f)
def func(self):
env_key = os.environ.get('MYKEY')
if env_key:
self.my_key = env_key
else:
self.my_key = self.key
return f(self)
return func
class OverrideableKey(FlowSpec):
key = Parameter('key')
@environment(vars={'MYKEY': 'SOMETHING'})
@mykey
@step
def start(self):
print('the key is', self.my_key)
self.next(self.end)
@step
def end(self):
pass
if __name__ == '__main__':
OverrideableKey()
straight-shampoo-11124
12/01/2021, 5:40 AM@environment
is not specified, otherwise the env var is usedstraight-shampoo-11124
12/01/2021, 5:42 AMMETAFLOW_RUN_KEY=test
in the above examplestraight-shampoo-11124
12/01/2021, 5:42 AMbig-stone-5971
12/01/2021, 7:45 PMflow.key = "YOUR_API_KEY"
which seems unsafefresh-laptop-72652
12/01/2021, 7:58 PM