From 34402beeb7bf323cbcb89cc8d44572c5db9ec9be Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Thu, 14 Sep 2023 18:26:40 +0200 Subject: Ensure PythonExtension is consistent when finding externals (#40012) PythonExtension is a base class for PythonPackage, and is meant to be used for any package that is a Python extension but is not built using "python_pip". The "update_external_dependency" method in the base class calls another method that is defined in the derived class. Push "get_external_python_for_prefix" up in the hierarchy to make method calls consistent. --- lib/spack/spack/build_systems/python.py | 82 ++++++++++++++++----------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/spack/spack/build_systems/python.py b/lib/spack/spack/build_systems/python.py index 00dd72c253..c791ab804f 100644 --- a/lib/spack/spack/build_systems/python.py +++ b/lib/spack/spack/build_systems/python.py @@ -229,6 +229,47 @@ class PythonExtension(spack.package_base.PackageBase): python._mark_concrete() self.spec.add_dependency_edge(python, depflag=dt.BUILD | dt.LINK | dt.RUN, virtuals=()) + def get_external_python_for_prefix(self): + """ + For an external package that extends python, find the most likely spec for the python + it depends on. + + First search: an "installed" external that shares a prefix with this package + Second search: a configured external that shares a prefix with this package + Third search: search this prefix for a python package + + Returns: + spack.spec.Spec: The external Spec for python most likely to be compatible with self.spec + """ + python_externals_installed = [ + s for s in spack.store.STORE.db.query("python") if s.prefix == self.spec.external_path + ] + if python_externals_installed: + return python_externals_installed[0] + + python_external_config = spack.config.get("packages:python:externals", []) + python_externals_configured = [ + spack.spec.parse_with_version_concrete(item["spec"]) + for item in python_external_config + if item["prefix"] == self.spec.external_path + ] + if python_externals_configured: + return python_externals_configured[0] + + python_externals_detection = spack.detection.by_path( + ["python"], path_hints=[self.spec.external_path] + ) + + python_externals_detected = [ + d.spec + for d in python_externals_detection.get("python", []) + if d.prefix == self.spec.external_path + ] + if python_externals_detected: + return python_externals_detected[0] + + raise StopIteration("No external python could be detected for %s to depend on" % self.spec) + class PythonPackage(PythonExtension): """Specialized class for packages that are built using pip.""" @@ -274,47 +315,6 @@ class PythonPackage(PythonExtension): name = cls.pypi.split("/")[0] return "https://pypi.org/simple/" + name + "/" - def get_external_python_for_prefix(self): - """ - For an external package that extends python, find the most likely spec for the python - it depends on. - - First search: an "installed" external that shares a prefix with this package - Second search: a configured external that shares a prefix with this package - Third search: search this prefix for a python package - - Returns: - spack.spec.Spec: The external Spec for python most likely to be compatible with self.spec - """ - python_externals_installed = [ - s for s in spack.store.STORE.db.query("python") if s.prefix == self.spec.external_path - ] - if python_externals_installed: - return python_externals_installed[0] - - python_external_config = spack.config.get("packages:python:externals", []) - python_externals_configured = [ - spack.spec.parse_with_version_concrete(item["spec"]) - for item in python_external_config - if item["prefix"] == self.spec.external_path - ] - if python_externals_configured: - return python_externals_configured[0] - - python_externals_detection = spack.detection.by_path( - ["python"], path_hints=[self.spec.external_path] - ) - - python_externals_detected = [ - d.spec - for d in python_externals_detection.get("python", []) - if d.prefix == self.spec.external_path - ] - if python_externals_detected: - return python_externals_detected[0] - - raise StopIteration("No external python could be detected for %s to depend on" % self.spec) - @property def headers(self): """Discover header files in platlib.""" -- cgit v1.2.3-60-g2f50