https://pantsbuild.org/ logo
j

jolly-midnight-72759

07/30/2021, 3:25 PM
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

enough-analyst-54434

07/30/2021, 3:49 PM
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

jolly-midnight-72759

07/30/2021, 3:52 PM
Cool. Another bit on the (put-off-upgrading) camel's back.
e

enough-analyst-54434

07/30/2021, 3:53 PM
What version are you on?
j

jolly-midnight-72759

07/30/2021, 3:53 PM
2.4.1
e

enough-analyst-54434

07/30/2021, 3:55 PM
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

jolly-midnight-72759

07/30/2021, 4:10 PM
I'll update here after we run some tests.
h

hundreds-father-404

07/30/2021, 4:19 PM
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

enough-analyst-54434

07/30/2021, 4:19 PM
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
5 Views