https://pantsbuild.org/ logo
#general
Title
# general
f

faint-waitress-55925

10/05/2022, 11:21 AM
Hello, I have built some PEX binaries that serve as data processing tasks, and they need some environment variables to run (they will be deployed in Amazon ECS where these environment variables are already set up). I would like to be able to test them locally by running
./pants run
but I don't find a way to pass environment variables in the subprocess. Does anyone have a recommendation for that?
b

bumpy-noon-80834

10/05/2022, 11:24 AM
I'd try something like
FOO=bar ./pants run
f

faint-waitress-55925

10/05/2022, 11:35 AM
The problem is that I have a lot of PEX binaries (one to process data for each data source). I would like to pass the secrets to access these data sources as environment variables. Is there something to do that in a more flexible way (like using a
.env
or something else)?
b

bumpy-noon-80834

10/05/2022, 11:37 AM
I do not think pants is able to read
.env
files. It's the dotenv library's job. You can use it in your code directly.
f

faint-waitress-55925

10/05/2022, 11:41 AM
I tried. I put a
.env
file my root folder (as a
file
target), and declared it as a dependency for each PEX binary. Then I used
python-dotenv
package to load these environments variables. Problem: It doesn't work with a
file
target when using a PEX binary, and I don't want to declare it as a
resource
because I don't want to package the secrets in it.
b

bumpy-noon-80834

10/05/2022, 11:47 AM
In most cases
.env
files shouldn't even be versioned
So it shouldn't be managed by Pants either
f

faint-waitress-55925

10/05/2022, 12:18 PM
I will try with direnv, it should works. Thank you.
c

cold-vr-15232

05/26/2023, 6:42 PM
This is an old thread, but maybe it is useful to mention that dotenv.load_dotenv() works fine if you specify the absolute path to the .env file. In usual cases, you would use *f*"{os.getcwd()}/.env" or similar.
🙏 1
3 Views