Skip to content

Commit 8e41cf9

Browse files
committed
Generate config reference
Signed-off-by: Cristian Le <[email protected]>
1 parent 0e6a34a commit 8e41cf9

File tree

5 files changed

+373
-5
lines changed

5 files changed

+373
-5
lines changed

docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ about/changelog
7373
7474
api/scikit_build_core
7575
schema
76+
reference/configs
7677
```
7778

7879
## Indices and tables

docs/reference/configs.rst

+290
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
Configurations
2+
==============
3+
4+
.. confval:: cmake.minimum-version
5+
:type: ``Version``
6+
7+
8+
DEPRECATED in 0.8; use version instead.
9+
10+
.. confval:: cmake.version
11+
:type: ``SpecifierSet``
12+
13+
14+
The versions of CMake to allow. If CMake is not present on the system or does not pass this specifier, it will be downloaded via PyPI if possible. An empty string will disable this check. The default on 0.10+ is "CMakeLists.txt", which will read it from the project's CMakeLists.txt file, or ">=3.15" if unreadable or <0.10.
15+
16+
.. confval:: cmake.args
17+
:type: ``list[str]``
18+
19+
20+
A list of args to pass to CMake when configuring the project. Setting this in config or envvar will override toml. See also ``cmake.define``.
21+
22+
.. confval:: cmake.define
23+
:type: ``EnvVar``
24+
25+
26+
A table of defines to pass to CMake when configuring the project. Additive.
27+
28+
.. confval:: cmake.verbose
29+
:type: ``bool``
30+
31+
32+
DEPRECATED in 0.10, use build.verbose instead.
33+
34+
.. confval:: cmake.build-type
35+
:type: ``str``
36+
:default: "Release"
37+
38+
The build type to use when building the project. Valid options are: "Debug", "Release", "RelWithDebInfo", "MinSizeRel", "", etc.
39+
40+
.. confval:: cmake.source-dir
41+
:type: ``Path``
42+
:default: "."
43+
44+
The source directory to use when building the project. Currently only affects the native builder (not the setuptools plugin).
45+
46+
.. confval:: cmake.targets
47+
:type: ``list[str]``
48+
49+
50+
DEPRECATED in 0.10; use build.targets instead.
51+
52+
.. confval:: ninja.minimum-version
53+
:type: ``Version``
54+
55+
56+
DEPRECATED in 0.8; use version instead.
57+
58+
.. confval:: ninja.version
59+
:type: ``SpecifierSet``
60+
:default: ">=1.5"
61+
62+
The versions of Ninja to allow. If Ninja is not present on the system or does not pass this specifier, it will be downloaded via PyPI if possible. An empty string will disable this check.
63+
64+
.. confval:: ninja.make-fallback
65+
:type: ``bool``
66+
:default: true
67+
68+
If Ninja is not present on the system or is older than required, it will be downloaded via PyPI if this is false.
69+
70+
.. confval:: logging.level
71+
:type: ``"NOTSET" | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL"``
72+
:default: "WARNING"
73+
74+
The logging level to display, "DEBUG", "INFO", "WARNING", and "ERROR" are possible options.
75+
76+
.. confval:: sdist.include
77+
:type: ``list[str]``
78+
79+
80+
Files to include in the SDist even if they are skipped by default. Supports gitignore syntax.
81+
82+
.. confval:: sdist.exclude
83+
:type: ``list[str]``
84+
85+
86+
Files to exclude from the SDist even if they are included by default. Supports gitignore syntax.
87+
88+
.. confval:: sdist.reproducible
89+
:type: ``bool``
90+
:default: true
91+
92+
If set to True, try to build a reproducible distribution (Unix and Python 3.9+ recommended). ``SOURCE_DATE_EPOCH`` will be used for timestamps, or a fixed value if not set.
93+
94+
.. confval:: sdist.cmake
95+
:type: ``bool``
96+
:default: false
97+
98+
If set to True, CMake will be run before building the SDist.
99+
100+
.. confval:: wheel.packages
101+
:type: ``list[str]``
102+
:default: ["src/<package>", "python/<package>", "<package>"]
103+
104+
A list of packages to auto-copy into the wheel. If this is not set, it will default to the first of ``src/<package>``, ``python/<package>``, or ``<package>`` if they exist. The prefix(s) will be stripped from the package name inside the wheel. If a dict, provides a mapping of package name to source directory.
105+
106+
.. confval:: wheel.py-api
107+
:type: ``str``
108+
109+
110+
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.
111+
112+
.. confval:: wheel.expand-macos-universal-tags
113+
:type: ``bool``
114+
:default: false
115+
116+
Fill out extra tags that are not required. This adds "x86_64" and "arm64" to the list of platforms when "universal2" is used, which helps older Pip's (before 21.0.1) find the correct wheel.
117+
118+
.. confval:: wheel.install-dir
119+
:type: ``str``
120+
121+
122+
The install directory for the wheel. This is relative to the platlib root. You might set this to the package name. The original dir is still at SKBUILD_PLATLIB_DIR (also SKBUILD_DATA_DIR, etc. are available). EXPERIMENTAL: An absolute path will be one level higher than the platlib root, giving access to "/platlib", "/data", "/headers", and "/scripts".
123+
124+
.. confval:: wheel.license-files
125+
:type: ``list[str]``
126+
127+
128+
A list of license files to include in the wheel. Supports glob patterns. The default is ``["LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*"]``. Must not be set if ``project.license-files`` is set.
129+
130+
.. confval:: wheel.cmake
131+
:type: ``bool``
132+
:default: true
133+
134+
If set to True (the default), CMake will be run before building the wheel.
135+
136+
.. confval:: wheel.platlib
137+
:type: ``bool``
138+
139+
140+
Target the platlib or the purelib. If not set, the default is to target the platlib if wheel.cmake is true, and the purelib otherwise.
141+
142+
.. confval:: wheel.exclude
143+
:type: ``list[str]``
144+
145+
146+
A set of patterns to exclude from the wheel. This is additive to the SDist exclude patterns. This applies to the final paths in the wheel, and can exclude files from CMake output as well. Editable installs may not respect this exclusion.
147+
148+
.. confval:: wheel.build-tag
149+
:type: ``str``
150+
151+
152+
The build tag to use for the wheel. If empty, no build tag is used.
153+
154+
.. confval:: backport.find-python
155+
:type: ``Version``
156+
:default: "3.26.1"
157+
158+
If CMake is less than this value, backport a copy of FindPython. Set to 0 disable this, or the empty string.
159+
160+
.. confval:: editable.mode
161+
:type: ``"redirect" | "inplace"``
162+
:default: "redirect"
163+
164+
Select the editable mode to use. Can be "redirect" (default) or "inplace".
165+
166+
.. confval:: editable.verbose
167+
:type: ``bool``
168+
:default: true
169+
170+
Turn on verbose output for the editable mode rebuilds.
171+
172+
.. confval:: editable.rebuild
173+
:type: ``bool``
174+
:default: false
175+
176+
Rebuild the project when the package is imported. The build-directory must be set.
177+
178+
.. confval:: build.tool-args
179+
:type: ``list[str]``
180+
181+
182+
Extra args to pass directly to the builder in the build step.
183+
184+
.. confval:: build.targets
185+
:type: ``list[str]``
186+
187+
188+
The build targets to use when building the project. Empty builds the default target.
189+
190+
.. confval:: build.verbose
191+
:type: ``bool``
192+
:default: false
193+
194+
Verbose printout when building.
195+
196+
.. confval:: build.requires
197+
:type: ``list[str]``
198+
199+
200+
Additional ``build-system.requires``. Intended to be used in combination with ``overrides``.
201+
202+
.. confval:: install.components
203+
:type: ``list[str]``
204+
205+
206+
The components to install. If empty, all default components are installed.
207+
208+
.. confval:: install.strip
209+
:type: ``bool``
210+
:default: true
211+
212+
Whether to strip the binaries. True for release builds on scikit-build-core 0.5+ (0.5-0.10.5 also incorrectly set this for debug builds).
213+
214+
.. confval:: generate[].path
215+
:type: ``Path``
216+
217+
218+
The path (relative to platlib) for the file to generate.
219+
220+
.. confval:: generate[].template
221+
:type: ``str``
222+
223+
224+
The template to use for the file. This includes string.Template style placeholders for all the metadata. If empty, a template-path must be set.
225+
226+
.. confval:: generate[].template-path
227+
:type: ``Path``
228+
229+
230+
The path to the template file. If empty, a template must be set.
231+
232+
.. confval:: generate[].location
233+
:type: ``"install" | "build" | "source"``
234+
:default: "install"
235+
236+
The place to put the generated file. The "build" directory is useful for CMake files, and the "install" directory is useful for Python files, usually. You can also write directly to the "source" directory, will overwrite existing files & remember to gitignore the file.
237+
238+
.. confval:: messages.after-failure
239+
:type: ``str``
240+
241+
242+
A message to print after a build failure.
243+
244+
.. confval:: messages.after-success
245+
:type: ``str``
246+
247+
248+
A message to print after a successful build.
249+
250+
.. confval:: search.site-packages
251+
:type: ``bool``
252+
:default: true
253+
254+
Add the python build environment site_packages folder to the CMake prefix paths.
255+
256+
.. confval:: metadata
257+
:type: ``dict[str,dict[str,Any]]``
258+
259+
260+
List dynamic metadata fields and hook locations in this table.
261+
262+
.. confval:: strict-config
263+
:type: ``bool``
264+
:default: true
265+
266+
Strictly check all config options. If False, warnings will be printed for unknown options. If True, an error will be raised.
267+
268+
.. confval:: experimental
269+
:type: ``bool``
270+
:default: false
271+
272+
Enable early previews of features not finalized yet.
273+
274+
.. confval:: minimum-version
275+
:type: ``Version``
276+
:default: "0.11" # current version
277+
278+
If set, this will provide a method for backward compatibility.
279+
280+
.. confval:: build-dir
281+
:type: ``str``
282+
283+
284+
The build directory. Defaults to a temporary directory, but can be set.
285+
286+
.. confval:: fail
287+
:type: ``bool``
288+
:default: false
289+
290+
Immediately fail the build. This is only useful in overrides.

noxfile.py

+23
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ def generate_schema(session: nox.Session) -> None:
9292
schema_file.write_text(schema_txt)
9393

9494

95+
@nox.session(reuse_venv=True, tags=["gen"])
96+
def generate_config_reference(session: nox.Session) -> None:
97+
"""
98+
(Re)generate configure reference
99+
"""
100+
session.install("-e.")
101+
sphinx_txt = session.run(
102+
"python",
103+
"-m",
104+
"scikit_build_core.settings.skbuild_docs",
105+
"--format=sphinx",
106+
silent=True,
107+
)
108+
assert isinstance(sphinx_txt, str)
109+
configs_file = DIR / "docs/reference/configs.rst"
110+
configs_file.write_text(f"""\
111+
Configurations
112+
==============
113+
114+
{sphinx_txt}
115+
""")
116+
117+
95118
@nox.session
96119
def tests(session: nox.Session) -> None:
97120
"""

src/scikit_build_core/settings/documentation.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import inspect
66
import textwrap
77
from pathlib import Path
8-
from typing import TYPE_CHECKING, TypeVar, cast
8+
from typing import TYPE_CHECKING, Literal, TypeVar, Union, cast
99

1010
from packaging.specifiers import SpecifierSet
1111
from packaging.version import Version
1212

1313
from .. import __version__
14-
from .._compat.typing import get_args, get_origin
14+
from .._compat.typing import Annotated, get_args, get_origin
1515

1616
if TYPE_CHECKING:
1717
from collections.abc import Generator
@@ -56,6 +56,7 @@ def pull_docs(dc: type[object]) -> dict[str, str]:
5656
@dataclasses.dataclass
5757
class DCDoc:
5858
name: str
59+
type: str
5960
default: str
6061
docs: str
6162
deprecated: bool = False
@@ -78,6 +79,33 @@ def sanitize_default_field(text: str) -> str:
7879
return text # noqa: RET504
7980

8081

82+
def is_optional(field: type) -> bool:
83+
return get_origin(field) is Union and type(None) in get_args(field)
84+
85+
86+
def get_display_type(field_type: type | str) -> str:
87+
if isinstance(field_type, str):
88+
return field_type
89+
if is_optional(field_type):
90+
# Special case for optional, we just take the first part
91+
return get_display_type(get_args(field_type)[0])
92+
# Handle built-ins
93+
if get_origin(field_type) is dict:
94+
key_display = get_display_type(get_args(field_type)[0])
95+
val_display = get_display_type(get_args(field_type)[1])
96+
return f"dict[{key_display},{val_display}]"
97+
if get_origin(field_type) is list:
98+
return f"list[{get_display_type(get_args(field_type)[0])}]"
99+
# Handle other typing specials
100+
if get_origin(field_type) is Literal:
101+
return " | ".join(f'"{x}"' for x in get_args(field_type))
102+
if get_origin(field_type) is Annotated:
103+
# For annotated assume we always want the second item
104+
return get_display_type(get_args(field_type)[1])
105+
# Otherwise just get the formatted form of the `type` object
106+
return field_type.__name__
107+
108+
81109
def mk_docs(dc: type[object], prefix: str = "") -> Generator[DCDoc, None, None]:
82110
"""
83111
Makes documentation for a dataclass.
@@ -115,6 +143,9 @@ def mk_docs(dc: type[object], prefix: str = "") -> Generator[DCDoc, None, None]:
115143

116144
yield DCDoc(
117145
name=f"{prefix}{field.name}".replace("_", "-"),
146+
type=get_metadata_field(
147+
field, "display_type", get_display_type(field.type)
148+
),
118149
default=sanitize_default_field(default),
119150
docs=docs[field.name],
120151
deprecated=get_metadata_field(field, "deprecated", False), # noqa: FBT003

0 commit comments

Comments
 (0)