Skip to content

Commit

Permalink
Improve FindPython hints
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Nov 24, 2024
1 parent 713f074 commit c8e6104
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/py_build_cmake/commands/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@ def get_configure_options_package(self) -> list[Option]:
Option("PY_BUILD_CMAKE_MODULE_NAME", self.package_info.module_name),
]

def get_native_python_prefixes(self) -> str:
"""Get the prefix paths to locate this (native) Python installation in,
as a semicolon-separated string."""
pfxs = [
Path(sys.exec_prefix).as_posix(),
Path(sys.prefix).as_posix(),
Path(sys.base_exec_prefix).as_posix(),
Path(sys.base_prefix).as_posix(),
]
return ";".join(pfxs)

def get_native_python_abi_tuple(self):
cmake_version = self.cmake_settings.minimum_required
has_t_flag = NormalizedVersion("3.30") <= NormalizedVersion(cmake_version)
Expand All @@ -149,15 +138,17 @@ def get_native_python_implementation(self) -> str | None:

def get_native_python_hints(self, prefix):
"""FindPython hints and artifacts for this (native) Python installation."""
yield Option(prefix + "_ROOT_DIR", self.get_native_python_prefixes())
yield Option(prefix + "_ROOT_DIR", Path(sys.prefix).as_posix())
impl = self.get_native_python_implementation()
if impl:
yield Option(prefix + "_FIND_IMPLEMENTATIONS", impl)
if impl == "PyPy":
inc = sysconfig.get_path("platinclude")
if inc:
yield Option(prefix + "_INCLUDE_DIR", Path(inc).as_posix())
return
# FIND_ABI seems to confuse CMake
yield Option(prefix + "_FIND_ABI", self.get_native_python_abi_tuple())
if impl == "PyPy":
yield Option(prefix + "_INCLUDE_DIR", sysconfig.get_path("platinclude"))

def get_cross_python_hints(self, prefix):
"""FindPython hints and artifacts to set when cross-compiling."""
Expand Down

0 comments on commit c8e6104

Please sign in to comment.