Environments: add run deps to shell modifications (#23485)
When adding an Environment to a user's shell, Spack was only adding root specs. This now includes run dependencies of root specs.
This commit is contained in:
@@ -1276,19 +1276,36 @@ def check_views(self):
|
||||
def _env_modifications_for_default_view(self, reverse=False):
|
||||
all_mods = spack.util.environment.EnvironmentModifications()
|
||||
|
||||
errors = []
|
||||
for _, spec in self.concretized_specs():
|
||||
if spec in self.default_view and spec.package.installed:
|
||||
try:
|
||||
mods = uenv.environment_modifications_for_spec(
|
||||
spec, self.default_view)
|
||||
except Exception as e:
|
||||
msg = ("couldn't get environment settings for %s"
|
||||
% spec.format("{name}@{version} /{hash:7}"))
|
||||
errors.append((msg, str(e)))
|
||||
continue
|
||||
visited = set()
|
||||
|
||||
all_mods.extend(mods.reversed() if reverse else mods)
|
||||
errors = []
|
||||
for _, root_spec in self.concretized_specs():
|
||||
if root_spec in self.default_view and root_spec.package.installed:
|
||||
for spec in root_spec.traverse(deptype='run', root=True):
|
||||
if spec.name in visited:
|
||||
# It is expected that only one instance of the package
|
||||
# can be added to the environment - do not attempt to
|
||||
# add multiple.
|
||||
tty.debug(
|
||||
"Not adding {0} to shell modifications: "
|
||||
"this package has already been added".format(
|
||||
spec.format("{name}/{hash:7}")
|
||||
)
|
||||
)
|
||||
continue
|
||||
else:
|
||||
visited.add(spec.name)
|
||||
|
||||
try:
|
||||
mods = uenv.environment_modifications_for_spec(
|
||||
spec, self.default_view)
|
||||
except Exception as e:
|
||||
msg = ("couldn't get environment settings for %s"
|
||||
% spec.format("{name}@{version} /{hash:7}"))
|
||||
errors.append((msg, str(e)))
|
||||
continue
|
||||
|
||||
all_mods.extend(mods.reversed() if reverse else mods)
|
||||
|
||||
return all_mods, errors
|
||||
|
||||
|
@@ -200,6 +200,19 @@ def setup_error(pkg, env):
|
||||
assert "Warning: couldn't get environment settings" in err
|
||||
|
||||
|
||||
def test_activate_adds_transitive_run_deps_to_path(
|
||||
install_mockery, mock_fetch, monkeypatch):
|
||||
env('create', 'test')
|
||||
install = SpackCommand('install')
|
||||
|
||||
e = ev.read('test')
|
||||
with e:
|
||||
install('depends-on-run-env')
|
||||
|
||||
cmds = spack.environment.activate(e)
|
||||
assert 'DEPENDENCY_ENV_VAR=1' in cmds
|
||||
|
||||
|
||||
def test_env_install_same_spec_twice(install_mockery, mock_fetch):
|
||||
env('create', 'test')
|
||||
|
||||
|
Reference in New Issue
Block a user