diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2024-08-13 10:19:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-13 10:19:26 +0200 |
commit | 7001a2a65ac8643c05a986b03e821fe22ef196ff (patch) | |
tree | efd5eca42accab2355cefe8c86a6f6a8271bcf77 /lib | |
parent | 7c985d643206f3df00c444a470a7785040006121 (diff) | |
download | spack-7001a2a65ac8643c05a986b03e821fe22ef196ff.tar.gz spack-7001a2a65ac8643c05a986b03e821fe22ef196ff.tar.bz2 spack-7001a2a65ac8643c05a986b03e821fe22ef196ff.tar.xz spack-7001a2a65ac8643c05a986b03e821fe22ef196ff.zip |
Fix a bug with automatic tag detection (#45696)
Extracted from #45638
When adding the "detectable" tag to a package class that has the
"tag" attribute inherited from a base class, we need to copy it to
avoid modifying the base class.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/package_base.py | 11 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/external.py | 28 | ||||
-rw-r--r-- | lib/spack/spack/test/tag.py | 2 |
3 files changed, 30 insertions, 11 deletions
diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py index 6f2d4406bc..63aa02cc62 100644 --- a/lib/spack/spack/package_base.py +++ b/lib/spack/spack/package_base.py @@ -197,13 +197,12 @@ class DetectablePackageMeta(type): # that "foo" was a possible executable. # If a package has the executables or libraries attribute then it's - # assumed to be detectable + # assumed to be detectable. Add a tag, so finding them is faster if hasattr(cls, "executables") or hasattr(cls, "libraries"): - # Append a tag to each detectable package, so that finding them is faster - if not hasattr(cls, "tags"): - setattr(cls, "tags", [DetectablePackageMeta.TAG]) - elif DetectablePackageMeta.TAG not in cls.tags: - cls.tags.append(DetectablePackageMeta.TAG) + # To add the tag, we need to copy the tags attribute, and attach it to + # the current class. We don't use append, since it might modify base classes, + # if "tags" is retrieved following the MRO. + cls.tags = getattr(cls, "tags", []) + [DetectablePackageMeta.TAG] @classmethod def platform_executables(cls): diff --git a/lib/spack/spack/test/cmd/external.py b/lib/spack/spack/test/cmd/external.py index 2de6f18b50..0573bc04ae 100644 --- a/lib/spack/spack/test/cmd/external.py +++ b/lib/spack/spack/test/cmd/external.py @@ -114,11 +114,31 @@ def test_find_external_cmd_not_buildable(mutable_config, working_env, mock_execu @pytest.mark.parametrize( "names,tags,exclude,expected", [ - # find --all - (None, ["detectable"], [], ["builtin.mock.find-externals1"]), + # find -all + ( + None, + ["detectable"], + [], + [ + "builtin.mock.find-externals1", + "builtin.mock.gcc", + "builtin.mock.llvm", + "builtin.mock.intel-oneapi-compilers", + ], + ), # find --all --exclude find-externals1 - (None, ["detectable"], ["builtin.mock.find-externals1"], []), - (None, ["detectable"], ["find-externals1"], []), + ( + None, + ["detectable"], + ["builtin.mock.find-externals1"], + ["builtin.mock.gcc", "builtin.mock.llvm", "builtin.mock.intel-oneapi-compilers"], + ), + ( + None, + ["detectable"], + ["find-externals1"], + ["builtin.mock.gcc", "builtin.mock.llvm", "builtin.mock.intel-oneapi-compilers"], + ), # find cmake (and cmake is not detectable) (["cmake"], ["detectable"], [], []), ], diff --git a/lib/spack/spack/test/tag.py b/lib/spack/spack/test/tag.py index 1f5affc549..6a979eca4b 100644 --- a/lib/spack/spack/test/tag.py +++ b/lib/spack/spack/test/tag.py @@ -153,7 +153,7 @@ def test_tag_no_tags(mock_packages): def test_tag_update_package(mock_packages): - mock_index = spack.repo.PATH.tag_index + mock_index = mock_packages.tag_index index = spack.tag.TagIndex(repository=mock_packages) for name in spack.repo.all_package_names(): index.update_package(name) |