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

rapid-bird-79300

02/22/2023, 5:33 PM
Hey Pants Team, curious if there's a recommended way to read environment variable from a plugin subsystem? I know we can set a subsystem option but wanted to see if we can read an existing env var.
e

enough-analyst-54434

02/22/2023, 5:36 PM
Looks like via an `EnvironmentVarsRequest`:
Copy code
$ git grep '"HOME"' **/*.py | grep -v _test.py
build-support/bin/generate_github_workflows.py:            env.update(PANTS_SUBPROCESS_ENVIRONMENT_ENV_VARS="HOME")
src/python/pants/backend/docker/lint/hadolint/rules.py:            env={"HOME": ""},
src/python/pants/backend/helm/util_rules/tool.py:    local_env = await Get(EnvironmentVars, EnvironmentVarsRequest(["HOME", "PATH"]))
src/python/pants/core/subsystems/python_bootstrap.py:    env = await Get(EnvironmentVars, EnvironmentVarsRequest(("PYENV_ROOT", "HOME")))
src/python/pants/core/subsystems/python_bootstrap.py:    home_from_env = env.get("HOME")
src/python/pants/core/util_rules/asdf.py:        home = env.get("HOME")
src/python/pants/core/util_rules/asdf.py:        "HOME",
src/python/pants/core/util_rules/asdf.py:        home = env.get("HOME")
src/python/pants/testutil/rule_runner.py:PYTHON_BOOTSTRAP_ENV = {"PATH", "PYENV_ROOT", "HOME"}
tests/python/pants_test/init/test_plugin_resolver.py:        env_inherit={"PATH", "PYENV_ROOT", "HOME"},
tests/python/pants_test/init/test_plugin_resolver.py:            {**{k: os.environ[k] for k in ["PATH", "HOME", "PYENV_ROOT"] if k in os.environ}, **env}
So my answer is for a rule, not for a subsystem. But I assume you want to actually read the value in a rule in the end.
r

rapid-bird-79300

02/22/2023, 5:40 PM
yeah actually a rule is perfectly fine
e

enough-analyst-54434

02/22/2023, 5:44 PM
It looks like the 2.15 docs have some high-level coverage in the plugin guide: https://www.pantsbuild.org/v2.15/docs/rules-api-process#environment-variables
👀 1
r

rapid-bird-79300

02/22/2023, 5:45 PM
perfect thank you @enough-analyst-54434!
3 Views