environments: make shell modifications partially unconditional (#13523)
* environments: make shell modifications partially unconditional * flake * missing module name * add regression test * flake
This commit is contained in:
parent
f6e26c402b
commit
24ec9f0ce3
2 changed files with 37 additions and 1 deletions
|
@ -1034,8 +1034,24 @@ def regenerate_views(self):
|
|||
'': ['CMAKE_PREFIX_PATH']
|
||||
}
|
||||
|
||||
def unconditional_environment_modifications(self, view):
|
||||
"""List of environment (shell) modifications to be processed for view.
|
||||
|
||||
This list does not depend on the specs in this environment"""
|
||||
env = spack.util.environment.EnvironmentModifications()
|
||||
|
||||
for subdir, vars in self.prefix_inspections.items():
|
||||
full_subdir = os.path.join(view.root, subdir)
|
||||
for var in vars:
|
||||
env.prepend_path(var, full_subdir)
|
||||
|
||||
return env
|
||||
|
||||
def environment_modifications_for_spec(self, spec, view=None):
|
||||
"""List of environment modifications to be processed."""
|
||||
"""List of environment (shell) modifications to be processed for spec.
|
||||
|
||||
This list is specific to the location of the spec or its projection in
|
||||
the view."""
|
||||
spec = spec.copy()
|
||||
if view:
|
||||
spec.prefix = Prefix(view.view().get_projection_for_spec(spec))
|
||||
|
@ -1068,6 +1084,9 @@ def add_default_view_to_shell(self, shell):
|
|||
# No default view to add to shell
|
||||
return env_mod.shell_modifications(shell)
|
||||
|
||||
env_mod.extend(self.unconditional_environment_modifications(
|
||||
self.default_view))
|
||||
|
||||
for _, spec in self.concretized_specs():
|
||||
if spec in self.default_view:
|
||||
env_mod.extend(self.environment_modifications_for_spec(
|
||||
|
@ -1086,6 +1105,9 @@ def rm_default_view_from_shell(self, shell):
|
|||
# No default view to add to shell
|
||||
return env_mod.shell_modifications(shell)
|
||||
|
||||
env_mod.extend(self.unconditional_environment_modifications(
|
||||
self.default_view).reversed())
|
||||
|
||||
for _, spec in self.concretized_specs():
|
||||
if spec in self.default_view:
|
||||
env_mod.extend(
|
||||
|
|
|
@ -1703,6 +1703,20 @@ def test_env_activate_csh_prints_shell_output(
|
|||
assert "alias despacktivate" in out
|
||||
|
||||
|
||||
@pytest.mark.regression('12719')
|
||||
def test_env_activate_default_view_root_unconditional(env_deactivate,
|
||||
mutable_mock_env_path):
|
||||
"""Check that the root of the default view in the environment is added
|
||||
to the shell unconditionally."""
|
||||
env('create', 'test', add_view=True)
|
||||
|
||||
with ev.read('test') as e:
|
||||
viewdir = e.default_view.root
|
||||
|
||||
out = env('activate', '--sh', 'test')
|
||||
assert 'PATH=%s' % os.path.join(viewdir, 'bin') in out
|
||||
|
||||
|
||||
def test_concretize_user_specs_together():
|
||||
e = ev.create('coconcretization')
|
||||
e.concretization = 'together'
|
||||
|
|
Loading…
Reference in a new issue