faint-waitress-55925
09/15/2022, 11:21 AM.env file and get the values with python-dotenv. Here is a quick example:
import os
from dotenv import load_dotenv
load_dotenv()
if __name__ == "__main__":
print(os.environ["ENVVAR"])
I have a .env file with ENVVAR=test . When I run using Pants 2.12.0 it prints "test" without problem but I get this in Pants 2.13.0:
File "/tmp/pants-sandbox-9ZiWSR/tasks/helloworld/main.py", line 7, in <module>
print(os.environ["ENVVAR"])
File "/home/soheil/.pyenv/versions/3.10.6/lib/python3.10/os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'ENVVAR'
Any recommendation?bitter-ability-32190
09/15/2022, 2:26 PMbitter-ability-32190
09/15/2022, 2:28 PMrun sandbox was under the build root .pants.d but now it's under /tmp.
You should declare a file target for your .env file and make sure the right targets depend on it, so it shows up in the sandboxfaint-waitress-55925
09/15/2022, 2:32 PM.env file in the root folder and a tasks/ folder in which I have several Python project which are configured with environment variables. I deploy the PEX files in Amazon ECS in container images, and the environment variables is automatically set in the container in production. But during development I want to rely on an .env file.faint-waitress-55925
09/15/2022, 2:32 PMbitter-ability-32190
09/15/2022, 2:37 PMfaint-waitress-55925
09/20/2022, 10:34 PMfile target and declaring a dependency to have the .env file in the run sandbox, and it worked. I have a problem now with CI/CD. When I try to run Pants in GitHub Actions (so without an .env file), it fails because there isn't an .env file available (the environment variables are already set up by GitHub Action). Do you have a solution for that?bitter-ability-32190
09/20/2022, 10:56 PMtouch one?curved-manchester-66006
11/10/2022, 1:33 AMfaint-waitress-55925
11/17/2022, 5:22 PM