summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2023-09-14 18:26:40 +0200
committerGitHub <noreply@github.com>2023-09-14 18:26:40 +0200
commit34402beeb7bf323cbcb89cc8d44572c5db9ec9be (patch)
treee2e04d4f84be594f2fcd6360ca78aae84124c5fa
parent6a249944f56ad942910b70cecb4623130ad8e14c (diff)
downloadspack-34402beeb7bf323cbcb89cc8d44572c5db9ec9be.tar.gz
spack-34402beeb7bf323cbcb89cc8d44572c5db9ec9be.tar.bz2
spack-34402beeb7bf323cbcb89cc8d44572c5db9ec9be.tar.xz
spack-34402beeb7bf323cbcb89cc8d44572c5db9ec9be.zip
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.
-rw-r--r--lib/spack/spack/build_systems/python.py82
1 files 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."""