metaflow icon indicating copy to clipboard operation
metaflow copied to clipboard

Parse environment variables passed from CLI

Open LarsDu opened this issue 4 years ago • 14 comments

Right now if one attempted to pass environment variables to the @environment decorator using the following type of syntax:

python workflow/myflow.py --with environment:vars=FOO:$(FOO),BAR:$(BAR)

vars would incorrectly register as a string rather than parsing the the contents as a dict.

This PR enables parsing of environment for the environment decorator which are passed using --with

LarsDu avatar Jul 13 '21 17:07 LarsDu

Nice catch! The only thing that gives me a bit of a pause here is that it is not uncommon to have : in env variable values (eg $PATH). On the other hand I don't have a good idea how to support those without making decospec syntax even more complicated.

oavdeev avatar Jul 14 '21 00:07 oavdeev

Nice catch! The only thing that gives me a bit of a pause here is that it is not uncommon to have : in env variable values (eg $PATH). On the other hand I don't have a good idea how to support those without making decospec syntax even more complicated.

Perhaps I can update this to only parse the first : in each comma delimited block

LarsDu avatar Jul 14 '21 16:07 LarsDu

After testing this a bit more, this doesn't seem to work with --batch. In that case gets converted back to --with CLI arg here, and it turns it into --with 'environment:vars={'\"MY_FOO\"': '\"bar\"', '\"MY_BAR\"': '\"baz\"'}'. Let me take a deeper look, there gotta be a way around this

oavdeev avatar Jul 20 '21 01:07 oavdeev

Something like this https://github.com/Netflix/metaflow/commit/d654bc8727b18f88c27e90bb95288a0f52ff8c3c should work but may still need a bit more testing

oavdeev avatar Jul 20 '21 03:07 oavdeev

Something like this d654bc8 should work but may still need a bit more testing

This looks good, though probably still need to limit the split on : to 1. This implementation should make it so that the only disallowed character in env var values would be ,.

corleyma avatar Jul 20 '21 07:07 corleyma

Something like this d654bc8 should work but may still need a bit more testing

This looks good, though probably still need to limit the split on : to 1. This implementation should make it so that the only disallowed character in env var values would be ,.

I've updated this to split on the first colon

LarsDu avatar Jul 20 '21 17:07 LarsDu

Something like this d654bc8 should work but may still need a bit more testing

I've updated the PR to incorporate these changes, but I have not thoroughly tested this.

LarsDu avatar Jul 20 '21 17:07 LarsDu

@oavdeev @LarsDu still needs some testing but i've made the changes I think would make this work for both step-functions and batch plugins.

corleyma avatar Jul 20 '21 19:07 corleyma

LGTM!

LarsDu avatar Jul 23 '21 16:07 LarsDu

@savingoyal had a suggestion that we could solve it in a slightly more elegant way by making @environment a "varargs" style decorator. So instead of @environment(vars={"FOO": "BAR"}) you could support @environment(FOO="BAR"). Metaflow already supports passing multiple parameters to a decorator from the command line, so it allows to implement this without making --with syntax special for @environment.

I've implemented it on top of this PR here https://github.com/Netflix/metaflow/commit/31519fe -- please take a look

oavdeev avatar Aug 03 '21 00:08 oavdeev

Also, this is how we currently resolve a similar issue in @conda.

savingoyal avatar Aug 05 '21 15:08 savingoyal

Any updates on this PR?

savingoyal avatar Oct 02 '21 08:10 savingoyal

See also https://github.com/Netflix/metaflow/pull/768

oavdeev avatar Nov 09 '21 20:11 oavdeev

A bit busy at the moment. Will try to revisit this by the end of the week.

LarsDu avatar Nov 15 '21 18:11 LarsDu