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

purple-plastic-57801

03/07/2023, 9:29 PM
Is there a way to detect that this is running with pants? So I can flag in resource loading logic conditionally. Specifically python logic.
b

broad-processor-92400

03/07/2023, 10:08 PM
When we were migrating to pants, we handled potentially-similar situations (e.g. the way we initialised a database within tests was slightly different when running within pants vs. the old style of running with poetry) by doing both: first try the pants way, and if it fails (in the expected way), try the old way. Alternatively, you might be able to set a
RUNNING_WITHIN_PANTS=1
variable within https://www.pantsbuild.org/docs/reference-subprocess-environment. I'm just guessing at what you're doing, though. What type of logic are you having to conditiionalise? Deciding when to use
importlib.resources....
?
p

purple-plastic-57801

03/07/2023, 10:09 PM
Essentially yes.
Currently a bunch of http sources are pulled onto a host to the users home dir for a "cache" it's clunky, but underpins a bunch of thing. So preserving that for the transition would be critical.
Can we set subprocess environment variables in the pants.toml?
b

broad-processor-92400

03/07/2023, 10:40 PM
yeah, all options can be set via env vars, via CLI options and via pants.toml. For the pages like the one linked above "Config section" says the heading (
[subprocess-environment]
in this case), and the bold heading for each option says the config key (
env_vars
). So, for that one, it'd be something like:
Copy code
[subprocess-environment]
env_vars = ["RUNNING_WITHIN_PANTS=1"]
p

purple-plastic-57801

03/07/2023, 10:41 PM
Ah - not _ 😃