Skip to content

Commit 1acc621

Browse files
committed
Add an option to avoid passing the python hints
Signed-off-by: Cristian Le <[email protected]>
1 parent 31a9f96 commit 1acc621

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ cmake.targets = ""
184184
# The CMAKE_TOOLCHAIN_FILE used for cross-compilation.
185185
cmake.toolchain-file = ""
186186

187+
# Do not pass the current environment's python hints such as
188+
# ``Python_EXECUTABLE``. Primarily used for cross-compilation where the
189+
# CMAKE_TOOLCHAIN_FILE should handle it instead.
190+
cmake.no-python-hints = false
191+
187192
# The versions of Ninja to allow. If Ninja is not present on the system or does
188193
# not pass this specifier, it will be downloaded via PyPI if possible. An empty
189194
# string will disable this check.

src/scikit_build_core/builder/builder.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,26 @@ def configure(
234234
if self.settings.cmake.toolchain_file:
235235
cache_config["CMAKE_TOOLCHAIN_FILE"] = self.settings.cmake.toolchain_file
236236

237-
# Classic Find Python
238-
cache_config["PYTHON_EXECUTABLE"] = sys.executable
239-
cache_config["PYTHON_INCLUDE_DIR"] = python_include_dir
240-
if python_library:
241-
cache_config["PYTHON_LIBRARY"] = python_library
242-
243-
# Modern Find Python
244-
for prefix in ("Python", "Python3"):
245-
cache_config[f"{prefix}_EXECUTABLE"] = sys.executable
246-
cache_config[f"{prefix}_ROOT_DIR"] = sys.base_exec_prefix
247-
cache_config[f"{prefix}_INCLUDE_DIR"] = python_include_dir
248-
cache_config[f"{prefix}_FIND_REGISTRY"] = "NEVER"
249-
# FindPython may break if this is set - only useful on Windows
250-
if python_library and sysconfig.get_platform().startswith("win"):
251-
cache_config[f"{prefix}_LIBRARY"] = python_library
252-
if python_sabi_library and sysconfig.get_platform().startswith("win"):
253-
cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library
254-
if numpy_include_dir:
255-
cache_config[f"{prefix}_NumPy_INCLUDE_DIR"] = numpy_include_dir
237+
if not self.settings.cmake.no_python_hints:
238+
# Classic Find Python
239+
cache_config["PYTHON_EXECUTABLE"] = sys.executable
240+
cache_config["PYTHON_INCLUDE_DIR"] = python_include_dir
241+
if python_library:
242+
cache_config["PYTHON_LIBRARY"] = python_library
243+
244+
# Modern Find Python
245+
for prefix in ("Python", "Python3"):
246+
cache_config[f"{prefix}_EXECUTABLE"] = sys.executable
247+
cache_config[f"{prefix}_ROOT_DIR"] = sys.base_exec_prefix
248+
cache_config[f"{prefix}_INCLUDE_DIR"] = python_include_dir
249+
cache_config[f"{prefix}_FIND_REGISTRY"] = "NEVER"
250+
# FindPython may break if this is set - only useful on Windows
251+
if python_library and sysconfig.get_platform().startswith("win"):
252+
cache_config[f"{prefix}_LIBRARY"] = python_library
253+
if python_sabi_library and sysconfig.get_platform().startswith("win"):
254+
cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library
255+
if numpy_include_dir:
256+
cache_config[f"{prefix}_NumPy_INCLUDE_DIR"] = numpy_include_dir
256257

257258
cache_config["SKBUILD_SOABI"] = get_soabi(self.config.env, abi3=limited_api)
258259

src/scikit_build_core/resources/scikit-build.schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106
"toolchain-file": {
107107
"type": "string",
108108
"description": "The CMAKE_TOOLCHAIN_FILE used for cross-compilation."
109+
},
110+
"no-python-hints": {
111+
"type": "boolean",
112+
"default": false,
113+
"description": "Do not pass the current environment's python hints such as ``Python_EXECUTABLE``. Primarily used for cross-compilation where the CMAKE_TOOLCHAIN_FILE should handle it instead."
109114
}
110115
}
111116
},

src/scikit_build_core/settings/skbuild_model.py

+7
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ class CMakeSettings:
108108
The CMAKE_TOOLCHAIN_FILE used for cross-compilation.
109109
"""
110110

111+
no_python_hints: bool = False
112+
"""
113+
Do not pass the current environment's python hints such as ``Python_EXECUTABLE``.
114+
Primarily used for cross-compilation where the CMAKE_TOOLCHAIN_FILE should handle it
115+
instead.
116+
"""
117+
111118

112119
@dataclasses.dataclass
113120
class SearchSettings:

0 commit comments

Comments
 (0)