Question from someone at my company: Is it possibl...
# general
j
Question from someone at my company: Is it possible for Pants to set an environment variable when running
./pants repl
? Does
extra_env
work everywhere or is it just a
test
thing?
e
A user definitely can:
Copy code
$ BOB=jake ./pants repl src/python/pants/util
Python 3.7.11 (default, Jul  2 2021, 16:46:08) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import os; os.environ["BOB"]
'jake'
>>>
And you can also permanently set these in pants.toml using
[subprocess-environment] env_vars
(see: https://www.pantsbuild.org/docs/reference-subprocess-environment#section-env-vars) as well (here I use the CLI flag form instead):
Copy code
$ ./pants --subprocess-environment-env-vars="BOB=jane" repl src/python/pants/util
08:47:35.78 [INFO] Starting: Resolving plugins: hdrhistogram, toolchain.pants.plugin==0.13.1
08:47:40.00 [INFO] Completed: Resolving plugins: hdrhistogram, toolchain.pants.plugin==0.13.1
08:47:42.24 [INFO] Completed: Extracting 3 requirements to build requirements.pex from lockfile.pex: ansicolors==1.1.8, packaging==20.9, typing-extensions==3.7.4.3
08:47:52.42 [INFO] Completed: Resolving 3rdparty/python/lockfiles/user_reqs.txt
Python 3.7.11 (default, Jul  2 2021, 16:46:08) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import os; os.environ["BOB"]
'jane'
>>> 
now exiting InteractiveConsole...
👖 1
This is, of course, Pants master / ~2.6.
🤕 1
j
Cool. Another bit on the (put-off-upgrading) camel's back.
e
What version are you on?
j
2.4.1
e
Ok, this all may work there too. You might try if you haven't already.
👍🏽 1
I just reached for Pants main since its sitting there to test.
j
I'll update here after we run some tests.
h
That actually shouldn't be necessary if memory serves correctly. We intentionally leak the environment when in the REPL because it's an interactive process that doesn't get cached and we wanted to facilitate experimentation Are you seeing otherwise?
e
I used one example that demonstrates the intentional leak and another that sets the env var in stone using toml just in case the desire was for the one or the other.
👍 1
👍🏽 1