summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/audit.py16
-rw-r--r--lib/spack/spack/test/repo.py13
2 files changed, 16 insertions, 13 deletions
diff --git a/lib/spack/spack/audit.py b/lib/spack/spack/audit.py
index faef15393d..c5e12017e2 100644
--- a/lib/spack/spack/audit.py
+++ b/lib/spack/spack/audit.py
@@ -351,6 +351,22 @@ def _wrongly_named_spec(error_cls):
return errors
+@config_packages
+def _ensure_all_virtual_packages_have_default_providers(error_cls):
+ """All virtual packages must have a default provider explicitly set."""
+ configuration = spack.config.create()
+ defaults = configuration.get("packages", scope="defaults")
+ default_providers = defaults["all"]["providers"]
+ virtuals = spack.repo.PATH.provider_index.providers
+ default_providers_filename = configuration.scopes["defaults"].get_section_filename("packages")
+
+ return [
+ error_cls(f"'{virtual}' must have a default provider in {default_providers_filename}", [])
+ for virtual in virtuals
+ if virtual not in default_providers
+ ]
+
+
def _make_config_error(config_data, summary, error_cls):
s = io.StringIO()
s.write("Occurring in the following file:\n")
diff --git a/lib/spack/spack/test/repo.py b/lib/spack/spack/test/repo.py
index e08d148289..a013078a82 100644
--- a/lib/spack/spack/test/repo.py
+++ b/lib/spack/spack/test/repo.py
@@ -131,19 +131,6 @@ def test_relative_import_spack_packages_as_python_modules(mock_packages):
assert issubclass(Mpileaks, spack.package_base.PackageBase)
-def test_all_virtual_packages_have_default_providers():
- """All virtual packages must have a default provider explicitly set."""
- configuration = spack.config.create()
- defaults = configuration.get("packages", scope="defaults")
- default_providers = defaults["all"]["providers"]
- providers = spack.repo.PATH.provider_index.providers
- default_providers_filename = configuration.scopes["defaults"].get_section_filename("packages")
- for provider in providers:
- assert provider in default_providers, (
- "all providers must have a default in %s" % default_providers_filename
- )
-
-
def test_get_all_mock_packages(mock_packages):
"""Get the mock packages once each too."""
for name in mock_packages.all_package_names():