Compare commits

..

1 Commits

Author SHA1 Message Date
Wouter Deconinck
af81387e6f on_package_attributes: pass checks to pkg in builder 2024-07-20 10:37:40 -05:00
2 changed files with 5 additions and 3 deletions

View File

@@ -10,4 +10,4 @@ pytest==8.2.2
isort==5.13.2
black==24.4.2
flake8==7.1.0
mypy==1.11.0
mypy==1.10.1

View File

@@ -358,12 +358,14 @@ def on_package_attributes(**attr_dict):
def _execute_under_condition(func):
@functools.wraps(func)
def _wrapper(instance, *args, **kwargs):
# Support both builders and packages
pkg = instance.pkg if isinstance(instance, spack.builder.Builder) else instance
# If all the attributes have the value we require, then execute
has_all_attributes = all([hasattr(instance, key) for key in attr_dict])
has_all_attributes = all([hasattr(pkg, key) for key in attr_dict])
if has_all_attributes:
has_the_right_values = all(
[
getattr(instance, key) == value for key, value in attr_dict.items()
getattr(pkg, key) == value for key, value in attr_dict.items()
] # NOQA: ignore=E501
)
if has_the_right_values: