summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-10-29 07:53:06 +0100
committerGitHub <noreply@github.com>2024-10-29 07:53:06 +0100
commit962115b386a1acd7de564ceafba93885dbd12c80 (patch)
tree00a514780c3b4bc9b0b802f847fe17a64ea3b1b9 /lib
parentf81ca0cd89595835b634b77d0f63ab0bd6156331 (diff)
downloadspack-962115b386a1acd7de564ceafba93885dbd12c80.tar.gz
spack-962115b386a1acd7de564ceafba93885dbd12c80.tar.bz2
spack-962115b386a1acd7de564ceafba93885dbd12c80.tar.xz
spack-962115b386a1acd7de564ceafba93885dbd12c80.zip
builder.py: builder_cls should be associated to spack.pkg module (#47269)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/audit.py3
-rw-r--r--lib/spack/spack/builder.py16
2 files changed, 14 insertions, 5 deletions
diff --git a/lib/spack/spack/audit.py b/lib/spack/spack/audit.py
index 3ccdd5b9cd..6596b7e767 100644
--- a/lib/spack/spack/audit.py
+++ b/lib/spack/spack/audit.py
@@ -722,9 +722,8 @@ def _ensure_env_methods_are_ported_to_builders(pkgs, error_cls):
)
builder_cls_names = [spack.builder.BUILDER_CLS[x].__name__ for x in build_system_names]
- module = pkg_cls.module
has_builders_in_package_py = any(
- getattr(module, name, False) for name in builder_cls_names
+ spack.builder.get_builder_class(pkg_cls, name) for name in builder_cls_names
)
if not has_builders_in_package_py:
continue
diff --git a/lib/spack/spack/builder.py b/lib/spack/spack/builder.py
index 098f583d53..b767f15b6d 100644
--- a/lib/spack/spack/builder.py
+++ b/lib/spack/spack/builder.py
@@ -12,6 +12,7 @@ from llnl.util import lang
import spack.error
import spack.multimethod
+import spack.repo
#: Builder classes, as registered by the "builder" decorator
BUILDER_CLS = {}
@@ -74,6 +75,14 @@ class _PhaseAdapter:
return self.phase_fn(self.builder.pkg, spec, prefix)
+def get_builder_class(pkg, name: str) -> Optional[type]:
+ """Return the builder class if a package module defines it."""
+ cls = getattr(pkg.module, name, None)
+ if cls and cls.__module__.startswith(spack.repo.ROOT_PYTHON_NAMESPACE):
+ return cls
+ return None
+
+
def _create(pkg):
"""Return a new builder object for the package object being passed as argument.
@@ -99,9 +108,10 @@ def _create(pkg):
package_buildsystem = buildsystem_name(pkg)
default_builder_cls = BUILDER_CLS[package_buildsystem]
builder_cls_name = default_builder_cls.__name__
- builder_cls = getattr(pkg.module, builder_cls_name, None)
- if builder_cls:
- return builder_cls(pkg)
+ builder_class = get_builder_class(pkg, builder_cls_name)
+
+ if builder_class:
+ return builder_class(pkg)
# Specialized version of a given buildsystem can subclass some
# base classes and specialize certain phases or methods or attributes.