Skip to content

Commit 360c1c7

Browse files
LecrisUThenryiii
authored andcommitted
Add an option to avoid passing the python hints
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent 0bf9c0c commit 360c1c7

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ cmake.source-dir = "."
175175
# The CMAKE_TOOLCHAIN_FILE used for cross-compilation.
176176
cmake.toolchain-file = ""
177177

178+
# Do not pass the current environment's python hints such as ``Python_EXECUTABLE``.
179+
cmake.python-hints = true
180+
178181
# The versions of Ninja to allow.
179182
ninja.version = ">=1.5"
180183

docs/reference/configs.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ print(mk_skbuild_docs())
198198
DEPRECATED in 0.8; use version instead.
199199
```
200200

201+
```{eval-rst}
202+
.. confval:: cmake.python-hints
203+
:type: ``bool``
204+
:default: true
205+
206+
Do not pass the current environment's python hints such as ``Python_EXECUTABLE``.
207+
Primarily used for cross-compilation where the CMAKE_TOOLCHAIN_FILE should handle it
208+
instead.
209+
```
210+
201211
```{eval-rst}
202212
.. confval:: cmake.source-dir
203213
:type: ``Path``

src/scikit_build_core/builder/builder.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,26 @@ def configure(
245245
if self.settings.cmake.toolchain_file:
246246
cache_config["CMAKE_TOOLCHAIN_FILE"] = self.settings.cmake.toolchain_file
247247

248-
# Classic Find Python
249-
cache_config["PYTHON_EXECUTABLE"] = Path(sys.executable)
250-
cache_config["PYTHON_INCLUDE_DIR"] = python_include_dir
251-
if python_library:
252-
cache_config["PYTHON_LIBRARY"] = python_library
253-
254-
# Modern Find Python
255-
for prefix in ("Python", "Python3"):
256-
cache_config[f"{prefix}_EXECUTABLE"] = Path(sys.executable)
257-
cache_config[f"{prefix}_ROOT_DIR"] = Path(sys.base_exec_prefix)
258-
cache_config[f"{prefix}_INCLUDE_DIR"] = python_include_dir
259-
cache_config[f"{prefix}_FIND_REGISTRY"] = "NEVER"
260-
# FindPython may break if this is set - only useful on Windows
261-
if python_library and sysconfig.get_platform().startswith("win"):
262-
cache_config[f"{prefix}_LIBRARY"] = python_library
263-
if python_sabi_library and sysconfig.get_platform().startswith("win"):
264-
cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library
265-
if numpy_include_dir:
266-
cache_config[f"{prefix}_NumPy_INCLUDE_DIR"] = numpy_include_dir
248+
if self.settings.cmake.python_hints:
249+
# Classic Find Python
250+
cache_config["PYTHON_EXECUTABLE"] = Path(sys.executable)
251+
cache_config["PYTHON_INCLUDE_DIR"] = python_include_dir
252+
if python_library:
253+
cache_config["PYTHON_LIBRARY"] = python_library
254+
255+
# Modern Find Python
256+
for prefix in ("Python", "Python3"):
257+
cache_config[f"{prefix}_EXECUTABLE"] = Path(sys.executable)
258+
cache_config[f"{prefix}_ROOT_DIR"] = Path(sys.base_exec_prefix)
259+
cache_config[f"{prefix}_INCLUDE_DIR"] = python_include_dir
260+
cache_config[f"{prefix}_FIND_REGISTRY"] = "NEVER"
261+
# FindPython may break if this is set - only useful on Windows
262+
if python_library and sysconfig.get_platform().startswith("win"):
263+
cache_config[f"{prefix}_LIBRARY"] = python_library
264+
if python_sabi_library and sysconfig.get_platform().startswith("win"):
265+
cache_config[f"{prefix}_SABI_LIBRARY"] = python_sabi_library
266+
if numpy_include_dir:
267+
cache_config[f"{prefix}_NumPy_INCLUDE_DIR"] = numpy_include_dir
267268

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

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

Lines changed: 5 additions & 0 deletions
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+
"python-hints": {
111+
"type": "boolean",
112+
"default": true,
113+
"description": "Do not pass the current environment's python hints such as ``Python_EXECUTABLE``."
109114
}
110115
}
111116
},

src/scikit_build_core/settings/skbuild_model.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ class CMakeSettings:
142142
The CMAKE_TOOLCHAIN_FILE used for cross-compilation.
143143
"""
144144

145+
python_hints: bool = True
146+
"""
147+
Do not pass the current environment's python hints such as ``Python_EXECUTABLE``.
148+
Primarily used for cross-compilation where the CMAKE_TOOLCHAIN_FILE should handle it
149+
instead.
150+
"""
151+
145152

146153
@dataclasses.dataclass
147154
class SearchSettings:

0 commit comments

Comments
 (0)