From 24ec9f0ce39e97e4c74595208340bcfa3ffcdadd Mon Sep 17 00:00:00 2001 From: Greg Becker Date: Fri, 1 Nov 2019 12:00:16 -0500 Subject: environments: make shell modifications partially unconditional (#13523) * environments: make shell modifications partially unconditional * flake * missing module name * add regression test * flake --- lib/spack/spack/environment.py | 24 +++++++++++++++++++++++- lib/spack/spack/test/cmd/env.py | 14 ++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'lib') 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' -- cgit v1.2.3-70-g09d2