Skip to content

Commit db432b7

Browse files
committed
Initial support for build.build-requires injection
1 parent 122ed79 commit db432b7

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,10 @@ build.targets = []
281281
# Verbose printout when building.
282282
build.verbose = false
283283

284+
# Additional ``build-system.requires``. Intended to be used in combination with
285+
# ``overrides``.
286+
build.build-requires = []
287+
284288
# The components to install. If empty, all default components are installed.
285289
install.components = []
286290

src/scikit_build_core/builder/get_requires.py

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def dynamic_metadata(self) -> Generator[str, None, None]:
140140
if self.settings.fail:
141141
return
142142

143+
yield from self.settings.build.build_requires
144+
143145
for dynamic_metadata in self.settings.metadata.values():
144146
if "provider" in dynamic_metadata:
145147
config = dynamic_metadata.copy()

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

+10
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@
299299
"type": "boolean",
300300
"default": false,
301301
"description": "Verbose printout when building."
302+
},
303+
"build-requires": {
304+
"type": "array",
305+
"items": {
306+
"type": "string"
307+
},
308+
"description": "Additional ``build-system.requires``. Intended to be used in combination with ``overrides``."
302309
}
303310
}
304311
},
@@ -560,6 +567,9 @@
560567
},
561568
"targets": {
562569
"$ref": "#/$defs/inherit"
570+
},
571+
"build-requires": {
572+
"$ref": "#/$defs/inherit"
563573
}
564574
}
565575
},

src/scikit_build_core/settings/skbuild_model.py

+6
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ class BuildSettings:
277277
Verbose printout when building.
278278
"""
279279

280+
build_requires: List[str] = dataclasses.field(default_factory=list)
281+
"""
282+
Additional ``build-system.requires``. Intended to be used in combination
283+
with ``overrides``.
284+
"""
285+
280286

281287
@dataclasses.dataclass
282288
class InstallSettings:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[build-system]
2+
requires = ["scikit-build-core"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "more_build_requires"
7+
8+
[tool.scikit-build.build]
9+
build-requires = ["foo"]
10+
11+
[[tool.scikit-build.overrides]]
12+
if.env.LOCAL_FOO = true
13+
build.build-requires = ["foo @ {root:uri}/foo"]

tests/test_dynamic_metadata.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import types
99
import zipfile
1010
from pathlib import Path
11-
from typing import Any
11+
from typing import TYPE_CHECKING, Any
1212

1313
import pytest
1414
from packaging.version import Version
@@ -23,6 +23,9 @@
2323

2424
from pathutils import contained
2525

26+
if TYPE_CHECKING:
27+
from scikit_build_core._compat.typing import Literal
28+
2629

2730
# these are mock plugins returning known results
2831
# it turns out to be easier to create EntryPoint objects pointing to real
@@ -347,3 +350,38 @@ def test_regex_remove(
347350
)
348351

349352
assert version == ("1.2.3dev1" if dev else "1.2.3")
353+
354+
355+
@pytest.mark.usefixtures("package_dynamic_metadata")
356+
@pytest.mark.parametrize("override", [None, "env", "sdist"])
357+
def test_build_requires_field(override, monkeypatch) -> None:
358+
shutil.copy("build_requires_project.toml", "pyproject.toml")
359+
360+
if override == "env":
361+
monkeypatch.setenv("LOCAL_FOO", "True")
362+
else:
363+
monkeypatch.delenv("LOCAL_FOO", raising=False)
364+
365+
with Path("pyproject.toml").open("rb") as ft:
366+
pyproject = tomllib.load(ft)
367+
state: Literal["sdist", "metadata_wheel"] = (
368+
"sdist" if override == "sdist" else "metadata_wheel"
369+
)
370+
settings_reader = SettingsReader(pyproject, {}, state=state)
371+
372+
settings_reader.validate_may_exit()
373+
374+
if override is None:
375+
assert set(GetRequires().dynamic_metadata()) == {
376+
"foo",
377+
}
378+
elif override == "env":
379+
assert set(GetRequires().dynamic_metadata()) == {
380+
# TODO: This should be resolved to actual path
381+
"foo @ {root:uri}/foo",
382+
}
383+
elif override =="sdist":
384+
assert set(GetRequires().dynamic_metadata()) == {
385+
# TODO: Check if special handling should be done for sdist
386+
"foo",
387+
}

0 commit comments

Comments
 (0)