diff options
author | Greg Becker <becker33@llnl.gov> | 2019-11-01 12:00:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-01 12:00:16 -0500 |
commit | 24ec9f0ce39e97e4c74595208340bcfa3ffcdadd (patch) | |
tree | 2c3e6e3c3847a9814053e5d7ad8eede7de90597e /lib | |
parent | f6e26c402b649dd06963b659ce42688948d1ce4d (diff) | |
download | spack-24ec9f0ce39e97e4c74595208340bcfa3ffcdadd.tar.gz spack-24ec9f0ce39e97e4c74595208340bcfa3ffcdadd.tar.bz2 spack-24ec9f0ce39e97e4c74595208340bcfa3ffcdadd.tar.xz spack-24ec9f0ce39e97e4c74595208340bcfa3ffcdadd.zip |
environments: make shell modifications partially unconditional (#13523)
* environments: make shell modifications partially unconditional
* flake
* missing module name
* add regression test
* flake
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/environment.py | 24 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/env.py | 14 |
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index b6b1814819..cd0db8d570 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -1034,8 +1034,24 @@ class Environment(object): '': ['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 @@ class Environment(object): # 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 @@ class Environment(object): # 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( diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py index c3fb911336..476f69c019 100644 --- a/lib/spack/spack/test/cmd/env.py +++ b/lib/spack/spack/test/cmd/env.py @@ -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' |