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

lively-exabyte-12840

02/25/2022, 1:14 PM
Curious if anyone is using Doppler - https://docs.doppler.com/docs - with Pants. It seems like a great fit for a Pants project. I ran into an issue of running a test via Pants that depended on loading env vars from my local .env file, and that wasn't working since the .env file of course isn't in the working directory from which Pants runs a test (there's probably a way to fix that, haven't found it yet). Doppler makes .env files go away though, instead injecting env vars into the Pants process. So running e.g.
doppler run -- ./pants test path/to/test.py
works great (though I still need to configure test/extra_env_vars so that env vars in the Pants env carry over to the env running the tests)
e

enough-analyst-54434

02/25/2022, 1:25 PM
I have no doppler experience, but it's surprising to me that
./pants test ...
+
[test] extra_env_vars
isn't enough. If
./pants
is in the right location to pick up
.env
(and it's run in a shell with direnv active I'm guessing?), then
pants
should see those env vars and let them through to
test
.
Is the
.env
in question in the
test/path/to/test.py
subtree and not a sibling of
./pants
?
In other words, this should be enough to get a test to see `FOO`:
FOO=bar ./pants test --extra-env-vars=FOO ...
Aha, maybe you use
doppler
instead of
direnv
? When I see
.env
I think
direnv
, but apparently there are many tools that read
.env
! Pants is not one. I think I've caught up to your problem finally!
l

lively-exabyte-12840

02/25/2022, 3:35 PM
Right, we're using python-dotenv to read the .env file from the root directory of the project (in our current setup). I worked around it by adding this to the root BUILD file:
Copy code
file(
    name="root_env_file",
    source=".env",
)
And then I've had to add this to every BUILD file in a test directory:
Copy code
python_tests(
    name="tests0",
    dependencies=["//:root_env_file"]
)
With Doppler (we haven't adopted it yet), the .env files go away, and then we'd just need to configure extra_env_vars in in the pants.toml file to define all the env vars that should be carried over from the Pants env to the test env; Doppler handles injecting all of its configured env vars into the Pants env. That's equivalent for how Doppler integrates with Docker; while it's a little annoying to have to list out all the env vars that should be carried over, it's a one-time charge and also common with other tools like Gradle that require doing the same thing
e

enough-analyst-54434

02/25/2022, 3:43 PM
Aha, your mention of
.env
threw me off. I did not realize
doppler
didn't use
.env
. Gotcha.
Ah, re-read better and you actually said that 🤦
6 Views