diff options
author | Peter Josef Scheibel <scheibel1@llnl.gov> | 2021-04-29 10:12:02 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2021-05-07 10:07:53 -0700 |
commit | 320eb4872d1c2e776948786a344f403754261389 (patch) | |
tree | d357ebb5b38597ec8166e8cad131a7159fa99761 | |
parent | d82a0c6799878be5a09242be8af9e5acbdc285cf (diff) | |
download | spack-320eb4872d1c2e776948786a344f403754261389.tar.gz spack-320eb4872d1c2e776948786a344f403754261389.tar.bz2 spack-320eb4872d1c2e776948786a344f403754261389.tar.xz spack-320eb4872d1c2e776948786a344f403754261389.zip |
fix check when retrieving matching spec from environment when there is a match with a root spec as well as with a dependency of a root spec
-rw-r--r-- | lib/spack/spack/environment.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/common/arguments.py | 18 | ||||
-rw-r--r-- | var/spack/repos/builtin.mock/packages/b/package.py | 1 |
3 files changed, 20 insertions, 1 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py index 218cd11095..a919ee5cee 100644 --- a/lib/spack/spack/environment.py +++ b/lib/spack/spack/environment.py @@ -1574,7 +1574,7 @@ class Environment(object): if abstract) if len(root_matches) == 1: - return root_matches[0][1] + return list(root_matches.items())[0][1] # More than one spec matched, and either multiple roots matched or # none of the matches were roots diff --git a/lib/spack/spack/test/cmd/common/arguments.py b/lib/spack/spack/test/cmd/common/arguments.py index 27648ee383..8797626d60 100644 --- a/lib/spack/spack/test/cmd/common/arguments.py +++ b/lib/spack/spack/test/cmd/common/arguments.py @@ -96,3 +96,21 @@ def test_multiple_env_match_raises_error(mock_packages, mutable_mock_env_path): spack.cmd.matching_spec_from_env(spack.cmd.parse_specs(['a'])[0]) assert 'matches multiple specs' in exc_info.value.message + + +@pytest.mark.usefixtures('config') +def test_root_and_dep_match_returns_root(mock_packages, mutable_mock_env_path): + e = ev.create('test') + e.add('b@0.9') + e.add('a foobar=bar') # Depends on b, should choose b@1.0 + e.concretize() + with e: + # This query matches the root b and b as a dependency of a. In that + # case the root instance should be preferred. + env_spec1 = spack.cmd.matching_spec_from_env( + spack.cmd.parse_specs(['b'])[0]) + assert env_spec1.satisfies('@0.9') + + env_spec2 = spack.cmd.matching_spec_from_env( + spack.cmd.parse_specs(['b@1.0'])[0]) + assert env_spec2 diff --git a/var/spack/repos/builtin.mock/packages/b/package.py b/var/spack/repos/builtin.mock/packages/b/package.py index 2ddc30f69b..24190d4b7e 100644 --- a/var/spack/repos/builtin.mock/packages/b/package.py +++ b/var/spack/repos/builtin.mock/packages/b/package.py @@ -13,5 +13,6 @@ class B(Package): url = "http://www.example.com/b-1.0.tar.gz" version('1.0', '0123456789abcdef0123456789abcdef') + version('0.9', 'abcd456789abcdef0123456789abcdef') depends_on('test-dependency', type='test') |