pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.35k stars 640 forks source link

Support glob patterns in subprocess-environment env_vars #20291

Open olivercoleman-switchdin opened 11 months ago

olivercoleman-switchdin commented 11 months ago

It was bad enough that I had to spend half a day figuring out why environment variables didn't seem to be working in tests executed via pants as one might reasonably expect 🤪 (when digging around just now I noticed there's been some suggestions that this should be the default behaviour, so consider that a secondary request if you will!)

I eventually found the subprocess-environment.env_vars option and added the necessary env vars in there.

This feature request is for adding support for specifying env var names with glob patterns. This would be especially handy for:

olivercoleman-switchdin commented 11 months ago

Guessing this should also be applied to the extra_env_vars option, if it were to be applied at all.

huonw commented 10 months ago

Here's a fun edge case: I think * is technically valid as an env var name, e.g. env 'ABC_*_GHI=1' env includes an ABC_*_GHI=1 line. Thus, supporting glowing here would mean one could not pass through only ABC_*_GHI, literally (it'd also allow passing through ABC_DEF_GHI etc.).

This is probably acceptable, though.

d-m commented 1 month ago

Agree this would also be helpful for passing in Terraform environment variables all at once (TF_VAR_*).

cognifloyd commented 3 weeks ago

Some kind of prefix matching would be really helpful in the StackStorm repo where I've been adding test-specific-config env vars. So far I have 23 vars listed in pants.toml [test].extra_env_vars. https://github.com/StackStorm/st2/blob/e97b7d2c6efa97a4507e0a2b7aea5ba6da76ac3d/pants.toml#L238-L267

All but 2 of them have the same prefix ST2TESTS_, so if I could glob/regex or do a prefix match on vars that would vastly simplify the config.