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:
Peter Scheibel 2021-05-11 14:30:57 -07:00 committed by GitHub
parent 57ce5f390b
commit 5230730941
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 12 deletions

View File

@ -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

View File

@ -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')

View File

@ -0,0 +1,22 @@
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
class DependsOnRunEnv(Package):
"""This package has a runtime dependency on another package which needs
to perform shell modifications to run.
"""
homepage = "http://www.example.com"
url = "http://www.example.com/a-1.0.tar.gz"
version('1.0', '0123456789abcdef0123456789abcdef')
depends_on('modifies-run-env', type=('run',))
def install(self, spec, prefix):
mkdirp(prefix.bin)

View File

@ -0,0 +1,21 @@
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
class ModifiesRunEnv(Package):
"""Dependency package which needs to make shell modifications to run"""
homepage = "http://www.example.com"
url = "http://www.example.com/a-1.0.tar.gz"
version('1.0', '0123456789abcdef0123456789abcdef')
def setup_run_environment(self, env):
env.set('DEPENDENCY_ENV_VAR', '1')
def install(self, spec, prefix):
mkdirp(prefix.bin)