Skip to content

Commit cf6d1ff

Browse files
authored
feat: configure FindPython backport (#103)
Exposing this (largely so users can disable it if they want to). Signed-off-by: Henry Schreiner <[email protected]>
1 parent 300ee76 commit cf6d1ff

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ wheel.expand-macos-universal-tags = false
165165
# available)
166166
wheel.install-dir = "."
167167

168+
# This will backport an internal copy of FindPython if CMake is less than this
169+
# value. Set to 0 or the empty string to disable. The default will be kept in
170+
# sync with the version of FindPython stored in scikit-build-core.
171+
backport.find-python = "3.24"
172+
168173
# Enable experimental features if any are available
169174
experimental = false
170175

src/scikit_build_core/builder/builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def configure(
7878
if site_packages != DIR.parent.parent:
7979
self.config.prefix_dirs.append(DIR.parent.parent)
8080

81-
if self.config.cmake.version < Version("3.24"):
81+
fp_backport = self.settings.backport.find_python
82+
if fp_backport and self.config.cmake.version < Version(fp_backport):
8283
self.config.module_dirs.append(Path(find_python.__file__).parent.resolve())
8384

8485
if sys.platform.startswith("win32"):

src/scikit_build_core/settings/skbuild_model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,21 @@ class WheelSettings:
9494
install_dir: str = ""
9595

9696

97+
@dataclasses.dataclass
98+
class BackportSettings:
99+
#: If CMake is less than this value, backport a copy of FindPython. Set
100+
#: to 0 disable this, or the empty string.
101+
find_python: str = "3.24"
102+
103+
97104
@dataclasses.dataclass
98105
class ScikitBuildSettings:
99106
cmake: CMakeSettings = dataclasses.field(default_factory=CMakeSettings)
100107
ninja: NinjaSettings = dataclasses.field(default_factory=NinjaSettings)
101108
logging: LoggingSettings = dataclasses.field(default_factory=LoggingSettings)
102109
sdist: SDistSettings = dataclasses.field(default_factory=SDistSettings)
103110
wheel: WheelSettings = dataclasses.field(default_factory=WheelSettings)
111+
backport: BackportSettings = dataclasses.field(default_factory=BackportSettings)
104112

105113
#: Strictly check all config options. If False, warnings will be
106114
#: printed for unknown options. If True, an error will be raised.

tests/test_skbuild_settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def test_skbuild_settings_default(tmp_path):
3232
assert settings.wheel.packages is None
3333
assert settings.wheel.py_api == ""
3434
assert not settings.wheel.expand_macos_universal_tags
35+
assert settings.backport.find_python == "3.24"
3536
assert settings.strict_config
3637
assert not settings.experimental
3738
assert settings.minimum_version is None
@@ -55,6 +56,7 @@ def test_skbuild_settings_envvar(tmp_path, monkeypatch):
5556
monkeypatch.setenv("SKBUILD_WHEEL_PACKAGES", "j; k; l")
5657
monkeypatch.setenv("SKBUILD_WHEEL_PY_API", "cp39")
5758
monkeypatch.setenv("SKBUILD_WHEEL_EXPAND_MACOS_UNIVERSAL_TAGS", "True")
59+
monkeypatch.setenv("SKBUILD_BACKPORT_FIND_PYTHON", "0")
5860
monkeypatch.setenv("SKBUILD_STRICT_CONFIG", "0")
5961
monkeypatch.setenv("SKBUILD_EXPERIMENTAL", "1")
6062
monkeypatch.setenv("SKBUILD_MINIMUM_VERSION", "0.1")
@@ -83,6 +85,7 @@ def test_skbuild_settings_envvar(tmp_path, monkeypatch):
8385
assert settings.wheel.packages == ["j", "k", "l"]
8486
assert settings.wheel.py_api == "cp39"
8587
assert settings.wheel.expand_macos_universal_tags
88+
assert settings.backport.find_python == "0"
8689
assert not settings.strict_config
8790
assert settings.experimental
8891
assert settings.minimum_version == "0.1"
@@ -112,6 +115,7 @@ def test_skbuild_settings_config_settings(tmp_path, monkeypatch):
112115
"wheel.packages": ["j", "k", "l"],
113116
"wheel.py-api": "cp39",
114117
"wheel.expand-macos-universal-tags": "True",
118+
"backport.find-python": "",
115119
"strict-config": "false",
116120
"experimental": "1",
117121
"minimum-version": "0.1",
@@ -135,6 +139,7 @@ def test_skbuild_settings_config_settings(tmp_path, monkeypatch):
135139
assert settings.wheel.packages == ["j", "k", "l"]
136140
assert settings.wheel.py_api == "cp39"
137141
assert settings.wheel.expand_macos_universal_tags
142+
assert settings.backport.find_python == ""
138143
assert not settings.strict_config
139144
assert settings.experimental
140145
assert settings.minimum_version == "0.1"
@@ -163,6 +168,7 @@ def test_skbuild_settings_pyproject_toml(tmp_path, monkeypatch):
163168
wheel.packages = ["j", "k", "l"]
164169
wheel.py-api = "cp39"
165170
wheel.expand-macos-universal-tags = true
171+
backport.find-python = "3.18"
166172
strict-config = false
167173
experimental = true
168174
minimum-version = "0.1"
@@ -191,6 +197,7 @@ def test_skbuild_settings_pyproject_toml(tmp_path, monkeypatch):
191197
assert settings.wheel.packages == ["j", "k", "l"]
192198
assert settings.wheel.py_api == "cp39"
193199
assert settings.wheel.expand_macos_universal_tags
200+
assert settings.backport.find_python == "3.18"
194201
assert not settings.strict_config
195202
assert settings.experimental
196203
assert settings.minimum_version == "0.1"

0 commit comments

Comments
 (0)