summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam J. Stewart <ajstewart426@gmail.com>2023-08-08 09:29:49 -0500
committerGitHub <noreply@github.com>2023-08-08 09:29:49 -0500
commit361632fc4be915651fe5751bf499c069b3ca168c (patch)
treec6637d8cc0067ab5e1e1b26cca0d83376df8f647 /lib
parent6576655137b847af102ebcea20278a6d4f9f09e7 (diff)
downloadspack-361632fc4be915651fe5751bf499c069b3ca168c.tar.gz
spack-361632fc4be915651fe5751bf499c069b3ca168c.tar.bz2
spack-361632fc4be915651fe5751bf499c069b3ca168c.tar.xz
spack-361632fc4be915651fe5751bf499c069b3ca168c.zip
Ensure that all variants have a description (#39025)
* Ensure that all variants have a description * Update mock packages too * Fix test invocations * Black fix * mgard: update variant descriptions * flake8 fix * black fix * Add to audit tests * Relax type hints * Older Python support * Undo all changes to mock packages * Flake8 fix
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/audit.py15
-rw-r--r--lib/spack/spack/directives.py56
2 files changed, 41 insertions, 30 deletions
diff --git a/lib/spack/spack/audit.py b/lib/spack/spack/audit.py
index e59ffaae55..2222ac9c88 100644
--- a/lib/spack/spack/audit.py
+++ b/lib/spack/spack/audit.py
@@ -710,6 +710,21 @@ def _ensure_variant_defaults_are_parsable(pkgs, error_cls):
@package_directives
+def _ensure_variants_have_descriptions(pkgs, error_cls):
+ """Ensures that all variants have a description."""
+ errors = []
+ for pkg_name in pkgs:
+ pkg_cls = spack.repo.path.get_pkg_class(pkg_name)
+ for variant_name, entry in pkg_cls.variants.items():
+ variant, _ = entry
+ if not variant.description:
+ error_msg = "Variant '{}' in package '{}' is missing a description"
+ errors.append(error_cls(error_msg.format(variant_name, pkg_name), []))
+
+ return errors
+
+
+@package_directives
def _version_constraints_are_satisfiable_by_some_version_in_repo(pkgs, error_cls):
"""Report if version constraints used in directives are not satisfiable"""
errors = []
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py
index b997a190c8..e1bb4d73e3 100644
--- a/lib/spack/spack/directives.py
+++ b/lib/spack/spack/directives.py
@@ -33,7 +33,7 @@ import collections.abc
import functools
import os.path
import re
-from typing import List, Optional, Set, Union
+from typing import Any, Callable, List, Optional, Set, Tuple, Union
import llnl.util.lang
import llnl.util.tty.color
@@ -663,39 +663,35 @@ def patch(url_or_filename, level=1, when=None, working_dir=".", **kwargs):
@directive("variants")
def variant(
- name,
- default=None,
- description="",
- values=None,
- multi=None,
- validator=None,
- when=None,
- sticky=False,
+ name: str,
+ default: Optional[Any] = None,
+ description: str = "",
+ values: Optional[Union[collections.abc.Sequence, Callable[[Any], bool]]] = None,
+ multi: Optional[bool] = None,
+ validator: Optional[Callable[[str, str, Tuple[Any, ...]], None]] = None,
+ when: Optional[Union[str, bool]] = None,
+ sticky: bool = False,
):
- """Define a variant for the package. Packager can specify a default
- value as well as a text description.
+ """Define a variant for the package.
+
+ Packager can specify a default value as well as a text description.
Args:
- name (str): name of the variant
- default (str or bool): default value for the variant, if not
- specified otherwise the default will be False for a boolean
- variant and 'nothing' for a multi-valued variant
- description (str): description of the purpose of the variant
- values (tuple or typing.Callable): either a tuple of strings containing the
- allowed values, or a callable accepting one value and returning
- True if it is valid
- multi (bool): if False only one value per spec is allowed for
- this variant
- validator (typing.Callable): optional group validator to enforce additional
- logic. It receives the package name, the variant name and a tuple
- of values and should raise an instance of SpackError if the group
- doesn't meet the additional constraints
- when (spack.spec.Spec, bool): optional condition on which the
- variant applies
- sticky (bool): the variant should not be changed by the concretizer to
- find a valid concrete spec.
+ name: Name of the variant
+ default: Default value for the variant, if not specified otherwise the default will be
+ False for a boolean variant and 'nothing' for a multi-valued variant
+ description: Description of the purpose of the variant
+ values: Either a tuple of strings containing the allowed values, or a callable accepting
+ one value and returning True if it is valid
+ multi: If False only one value per spec is allowed for this variant
+ validator: Optional group validator to enforce additional logic. It receives the package
+ name, the variant name and a tuple of values and should raise an instance of SpackError
+ if the group doesn't meet the additional constraints
+ when: Optional condition on which the variant applies
+ sticky: The variant should not be changed by the concretizer to find a valid concrete spec
+
Raises:
- DirectiveError: if arguments passed to the directive are invalid
+ DirectiveError: If arguments passed to the directive are invalid
"""
def format_error(msg, pkg):