summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGreg Becker <becker33@llnl.gov>2019-12-09 12:23:03 -0800
committerPeter Scheibel <scheibel1@llnl.gov>2019-12-09 12:23:03 -0800
commitda9a56218273dd6d778b341e685520e03edc4e58 (patch)
treec5d9f083ee5f9046e7ca849ebe01de3df92bfe7e /lib
parent23faffa2d0f18d95c6938c9da75ce6ae4818194a (diff)
downloadspack-da9a56218273dd6d778b341e685520e03edc4e58.tar.gz
spack-da9a56218273dd6d778b341e685520e03edc4e58.tar.bz2
spack-da9a56218273dd6d778b341e685520e03edc4e58.tar.xz
spack-da9a56218273dd6d778b341e685520e03edc4e58.zip
environments: allow 'add' command to add virtuals (#13787)
This PR allows virtual packages to be added to the specs list using the add command. Virtual packages are already allowed in named lists in spack environments/stacks, and they are already allowed in the specs list when added using the yaml directly.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/environment.py5
-rw-r--r--lib/spack/spack/test/cmd/env.py23
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 2c7a0cf098..2be355df2d 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -813,7 +813,10 @@ class Environment(object):
raise SpackEnvironmentError(
'cannot add anonymous specs to an environment!')
elif not spack.repo.path.exists(spec.name):
- raise SpackEnvironmentError('no such package: %s' % spec.name)
+ virtuals = spack.repo.path.provider_index.providers.keys()
+ if spec.name not in virtuals:
+ msg = 'no such package: %s' % spec.name
+ raise SpackEnvironmentError(msg)
list_to_change = self.spec_lists[list_name]
existing = str(spec) in list_to_change.yaml_list
diff --git a/lib/spack/spack/test/cmd/env.py b/lib/spack/spack/test/cmd/env.py
index 9b3ca6e66e..85413a7939 100644
--- a/lib/spack/spack/test/cmd/env.py
+++ b/lib/spack/spack/test/cmd/env.py
@@ -63,6 +63,27 @@ def test_add():
assert Spec('mpileaks') in e.user_specs
+def test_env_add_virtual():
+ env('create', 'test')
+
+ e = ev.read('test')
+ e.add('mpi')
+ e.concretize()
+
+ hashes = e.concretized_order
+ assert len(hashes) == 1
+ spec = e.specs_by_hash[hashes[0]]
+ assert spec.satisfies('mpi')
+
+
+def test_env_add_nonexistant_fails():
+ env('create', 'test')
+
+ e = ev.read('test')
+ with pytest.raises(ev.SpackEnvironmentError, match=r'no such package'):
+ e.add('thispackagedoesnotexist')
+
+
def test_env_list(mutable_mock_env_path):
env('create', 'foo')
env('create', 'bar')
@@ -1777,7 +1798,7 @@ def test_duplicate_packages_raise_when_concretizing_together():
def test_env_write_only_non_default():
- print(env('create', 'test'))
+ env('create', 'test')
e = ev.read('test')
with open(e.manifest_path, 'r') as f: