From a137da1cd54cce912f26603bd9d2558e5bad902c Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Wed, 12 Feb 2025 17:30:14 +0100 Subject: [PATCH] Spec.validate_detection -> spack.detection.path.validate_detection (#48987) --- lib/spack/spack/detection/path.py | 7 ++++++- lib/spack/spack/spec.py | 18 ------------------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/spack/spack/detection/path.py b/lib/spack/spack/detection/path.py index d3fed2180f4..d0c642225b4 100644 --- a/lib/spack/spack/detection/path.py +++ b/lib/spack/spack/detection/path.py @@ -259,6 +259,8 @@ def detect_specs( ) return [] + from spack.repo import PATH as repo_path + result = [] for candidate_path, items_in_prefix in _group_by_prefix( llnl.util.lang.dedupe(paths) @@ -305,7 +307,10 @@ def detect_specs( resolved_specs[spec] = candidate_path try: - spec.validate_detection() + # Validate the spec calling a package specific method + pkg_cls = repo_path.get_pkg_class(spec.name) + validate_fn = getattr(pkg_cls, "validate_detected_spec", lambda x, y: None) + validate_fn(spec, spec.extra_attributes) except Exception as e: msg = ( f'"{spec}" has been detected on the system but will ' diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 6c3605f8c60..dc5a4f5a09e 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -2826,24 +2826,6 @@ def from_detection( s.extra_attributes = extra_attributes return s - def validate_detection(self): - """Validate the detection of an external spec. - - This method is used as part of Spack's detection protocol, and is - not meant for client code use. - """ - # Assert that _extra_attributes is a Mapping and not None, - # which likely means the spec was created with Spec.from_detection - msg = 'cannot validate "{0}" since it was not created ' "using Spec.from_detection".format( - self - ) - assert isinstance(self.extra_attributes, collections.abc.Mapping), msg - - # Validate the spec calling a package specific method - pkg_cls = spack.repo.PATH.get_pkg_class(self.name) - validate_fn = getattr(pkg_cls, "validate_detected_spec", lambda x, y: None) - validate_fn(self, self.extra_attributes) - def _patches_assigned(self): """Whether patches have been assigned to this spec by the concretizer.""" # FIXME: _patches_in_order_of_appearance is attached after concretization