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:
		| @@ -1034,8 +1034,24 @@ def regenerate_views(self): | |||||||
|         '': ['CMAKE_PREFIX_PATH'] |         '': ['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): |     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() |         spec = spec.copy() | ||||||
|         if view: |         if view: | ||||||
|             spec.prefix = Prefix(view.view().get_projection_for_spec(spec)) |             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 |             # No default view to add to shell | ||||||
|             return env_mod.shell_modifications(shell) |             return env_mod.shell_modifications(shell) | ||||||
|  |  | ||||||
|  |         env_mod.extend(self.unconditional_environment_modifications( | ||||||
|  |             self.default_view)) | ||||||
|  |  | ||||||
|         for _, spec in self.concretized_specs(): |         for _, spec in self.concretized_specs(): | ||||||
|             if spec in self.default_view: |             if spec in self.default_view: | ||||||
|                 env_mod.extend(self.environment_modifications_for_spec( |                 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 |             # No default view to add to shell | ||||||
|             return env_mod.shell_modifications(shell) |             return env_mod.shell_modifications(shell) | ||||||
|  |  | ||||||
|  |         env_mod.extend(self.unconditional_environment_modifications( | ||||||
|  |             self.default_view).reversed()) | ||||||
|  |  | ||||||
|         for _, spec in self.concretized_specs(): |         for _, spec in self.concretized_specs(): | ||||||
|             if spec in self.default_view: |             if spec in self.default_view: | ||||||
|                 env_mod.extend( |                 env_mod.extend( | ||||||
|   | |||||||
| @@ -1703,6 +1703,20 @@ def test_env_activate_csh_prints_shell_output( | |||||||
|     assert "alias despacktivate" in out |     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(): | def test_concretize_user_specs_together(): | ||||||
|     e = ev.create('coconcretization') |     e = ev.create('coconcretization') | ||||||
|     e.concretization = 'together' |     e.concretization = 'together' | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Greg Becker
					Greg Becker