Skip to content

Commit 5f2782f

Browse files
committed
Initial support for build.build-requires injection
1 parent b3b955e commit 5f2782f

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
@@ -7,7 +7,7 @@
77
import types
88
import zipfile
99
from pathlib import Path
10-
from typing import Any
10+
from typing import TYPE_CHECKING, Any
1111

1212
import pytest
1313
from packaging.version import Version
@@ -22,6 +22,9 @@
2222

2323
from pathutils import contained
2424

25+
if TYPE_CHECKING:
26+
from typing import Literal
27+
2528

2629
# these are mock plugins returning known results
2730
# it turns out to be easier to create EntryPoint objects pointing to real
@@ -345,3 +348,38 @@ def test_regex_remove(
345348
)
346349

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

0 commit comments

Comments
 (0)