Skip to content

Commit e7d80bc

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

File tree

5 files changed

+59
-19
lines changed

5 files changed

+59
-19
lines changed

README.md

Lines changed: 5 additions & 0 deletions
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.python-hints = true
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.

docs/reference/configs.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ print(mk_skbuild_docs())
176176
DEPRECATED in 0.8; use version instead.
177177
```
178178

179+
```{eval-rst}
180+
.. confval:: cmake.python-hints
181+
:type: ``bool``
182+
:default: true
183+
184+
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.
185+
```
186+
179187
```{eval-rst}
180188
.. confval:: cmake.source-dir
181189
:type: ``Path``
@@ -191,6 +199,13 @@ print(mk_skbuild_docs())
191199
DEPRECATED in 0.10; use build.targets instead.
192200
```
193201

202+
```{eval-rst}
203+
.. confval:: cmake.toolchain-file
204+
:type: ``Path``
205+
206+
The CMAKE_TOOLCHAIN_FILE used for cross-compilation.
207+
```
208+
194209
```{eval-rst}
195210
.. confval:: cmake.verbose
196211
:type: ``bool``
@@ -440,4 +455,11 @@ print(mk_skbuild_docs())
440455
The Python tags. The default (empty string) will use the default Python version. You can also set this to "cp38" to enable the CPython 3.8+ Stable ABI / Limited API (only on CPython and if the version is sufficient, otherwise this has no effect). Or you can set it to "py3" or "py2.py3" to ignore Python ABI compatibility. The ABI tag is inferred from this tag.
441456
```
442457

458+
```{eval-rst}
459+
.. confval:: wheel.tags
460+
:type: ``list[str]``
461+
462+
Manually specify the wheel tags to use, ignoring other inputs such as ``wheel.py-api``. Each tag must be of the format {interpreter}-{abi}-{platform}. If not specified, these tags are automatically calculated.
463+
```
464+
443465
<!-- [[[end]]] -->

src/scikit_build_core/builder/builder.py

Lines changed: 20 additions & 19 deletions
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"] = Path(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"] = Path(sys.executable)
246-
cache_config[f"{prefix}_ROOT_DIR"] = Path(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 self.settings.cmake.python_hints:
238+
# Classic Find Python
239+
cache_config["PYTHON_EXECUTABLE"] = Path(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"] = Path(sys.executable)
247+
cache_config[f"{prefix}_ROOT_DIR"] = Path(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

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``. 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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ class CMakeSettings:
116116
The CMAKE_TOOLCHAIN_FILE used for cross-compilation.
117117
"""
118118

119+
python_hints: bool = True
120+
"""
121+
Do not pass the current environment's python hints such as ``Python_EXECUTABLE``.
122+
Primarily used for cross-compilation where the CMAKE_TOOLCHAIN_FILE should handle it
123+
instead.
124+
"""
125+
119126

120127
@dataclasses.dataclass
121128
class SearchSettings:

0 commit comments

Comments
 (0)