Get env_var mods from config (#49626)

This commit is contained in:
psakievich 2025-03-20 20:48:50 -06:00 committed by GitHub
parent 070bfa1ed7
commit f2d830cd4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 6 deletions

View File

@ -8,6 +8,7 @@
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.tty.color import colorize from llnl.util.tty.color import colorize
import spack.config
import spack.environment as ev import spack.environment as ev
import spack.repo import spack.repo
import spack.schema.environment import spack.schema.environment
@ -158,7 +159,8 @@ def activate(
# become PATH variables. # become PATH variables.
# #
env_vars_yaml = env.manifest.configuration.get("env_vars", None) with env.manifest.use_config():
env_vars_yaml = spack.config.get("env_vars", None)
if env_vars_yaml: if env_vars_yaml:
env_mods.extend(spack.schema.environment.parse(env_vars_yaml)) env_mods.extend(spack.schema.environment.parse(env_vars_yaml))
@ -195,7 +197,8 @@ def deactivate() -> EnvironmentModifications:
if active is None: if active is None:
return env_mods return env_mods
env_vars_yaml = active.manifest.configuration.get("env_vars", None) with active.manifest.use_config():
env_vars_yaml = spack.config.get("env_vars", None)
if env_vars_yaml: if env_vars_yaml:
env_mods.extend(spack.schema.environment.parse(env_vars_yaml).reversed()) env_mods.extend(spack.schema.environment.parse(env_vars_yaml).reversed())

View File

@ -3065,14 +3065,26 @@ def test_stack_view_activate_from_default(
def test_envvar_set_in_activate(tmp_path, mock_packages, install_mockery): def test_envvar_set_in_activate(tmp_path, mock_packages, install_mockery):
spack_yaml = tmp_path / "spack.yaml" spack_yaml = tmp_path / "spack.yaml"
env_vars_yaml = tmp_path / "env_vars.yaml"
env_vars_yaml.write_text(
"""
env_vars:
set:
CONFIG_ENVAR_SET_IN_ENV_LOAD: "True"
"""
)
spack_yaml.write_text( spack_yaml.write_text(
""" """
spack: spack:
include:
- env_vars.yaml
specs: specs:
- cmake%gcc - cmake%gcc
env_vars: env_vars:
set: set:
ENVAR_SET_IN_ENV_LOAD: "True" SPACK_ENVAR_SET_IN_ENV_LOAD: "True"
""" """
) )
@ -3083,12 +3095,16 @@ def test_envvar_set_in_activate(tmp_path, mock_packages, install_mockery):
test_env = ev.read("test") test_env = ev.read("test")
output = env("activate", "--sh", "test") output = env("activate", "--sh", "test")
assert "ENVAR_SET_IN_ENV_LOAD=True" in output assert "SPACK_ENVAR_SET_IN_ENV_LOAD=True" in output
assert "CONFIG_ENVAR_SET_IN_ENV_LOAD=True" in output
with test_env: with test_env:
with spack.util.environment.set_env(ENVAR_SET_IN_ENV_LOAD="True"): with spack.util.environment.set_env(
SPACK_ENVAR_SET_IN_ENV_LOAD="True", CONFIG_ENVAR_SET_IN_ENV_LOAD="True"
):
output = env("deactivate", "--sh") output = env("deactivate", "--sh")
assert "unset ENVAR_SET_IN_ENV_LOAD" in output assert "unset SPACK_ENVAR_SET_IN_ENV_LOAD" in output
assert "unset CONFIG_ENVAR_SET_IN_ENV_LOAD" in output
def test_stack_view_no_activate_without_default( def test_stack_view_no_activate_without_default(