Hello, I have built some PEX binaries that serve a...
# general
f
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
I'd try something like
FOO=bar ./pants run
f
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
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
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
In most cases
.env
files shouldn't even be versioned
So it shouldn't be managed by Pants either
f
I will try with direnv, it should works. Thank you.
c
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