Skip to content

Commit b07e098

Browse files
committed
Generate config reference
Signed-off-by: Cristian Le <[email protected]>
1 parent 46fa770 commit b07e098

File tree

5 files changed

+346
-5
lines changed

5 files changed

+346
-5
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
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

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
Configurations
2+
==============
3+
4+
.. confval:: cmake.minimum-version
5+
:type: ``Version``
6+
7+
DEPRECATED in 0.8; use version instead.
8+
9+
.. confval:: cmake.version
10+
:type: ``SpecifierSet``
11+
12+
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.
13+
14+
.. confval:: cmake.args
15+
:type: ``list[str]``
16+
17+
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``.
18+
19+
.. confval:: cmake.define
20+
:type: ``EnvVar``
21+
22+
A table of defines to pass to CMake when configuring the project. Additive.
23+
24+
.. confval:: cmake.verbose
25+
:type: ``bool``
26+
27+
DEPRECATED in 0.10, use build.verbose instead.
28+
29+
.. confval:: cmake.build-type
30+
:type: ``str``
31+
:default: "Release"
32+
33+
The build type to use when building the project. Valid options are: "Debug", "Release", "RelWithDebInfo", "MinSizeRel", "", etc.
34+
35+
.. confval:: cmake.source-dir
36+
:type: ``Path``
37+
:default: "."
38+
39+
The source directory to use when building the project. Currently only affects the native builder (not the setuptools plugin).
40+
41+
.. confval:: cmake.targets
42+
:type: ``list[str]``
43+
44+
DEPRECATED in 0.10; use build.targets instead.
45+
46+
.. confval:: ninja.minimum-version
47+
:type: ``Version``
48+
49+
DEPRECATED in 0.8; use version instead.
50+
51+
.. confval:: ninja.version
52+
:type: ``SpecifierSet``
53+
:default: ">=1.5"
54+
55+
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.
56+
57+
.. confval:: ninja.make-fallback
58+
:type: ``bool``
59+
:default: true
60+
61+
If Ninja is not present on the system or is older than required, it will be downloaded via PyPI if this is false.
62+
63+
.. confval:: logging.level
64+
:type: ``"NOTSET" | "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL"``
65+
:default: "WARNING"
66+
67+
The logging level to display, "DEBUG", "INFO", "WARNING", and "ERROR" are possible options.
68+
69+
.. confval:: sdist.include
70+
:type: ``list[str]``
71+
72+
Files to include in the SDist even if they are skipped by default. Supports gitignore syntax.
73+
74+
.. confval:: sdist.exclude
75+
:type: ``list[str]``
76+
77+
Files to exclude from the SDist even if they are included by default. Supports gitignore syntax.
78+
79+
.. confval:: sdist.reproducible
80+
:type: ``bool``
81+
:default: true
82+
83+
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.
84+
85+
.. confval:: sdist.cmake
86+
:type: ``bool``
87+
:default: false
88+
89+
If set to True, CMake will be run before building the SDist.
90+
91+
.. confval:: wheel.packages
92+
:type: ``list[str]``
93+
:default: ["src/<package>", "python/<package>", "<package>"]
94+
95+
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.
96+
97+
.. confval:: wheel.py-api
98+
:type: ``str``
99+
100+
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.
101+
102+
.. confval:: wheel.expand-macos-universal-tags
103+
:type: ``bool``
104+
:default: false
105+
106+
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.
107+
108+
.. confval:: wheel.install-dir
109+
:type: ``str``
110+
111+
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".
112+
113+
.. confval:: wheel.license-files
114+
:type: ``list[str]``
115+
116+
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.
117+
118+
.. confval:: wheel.cmake
119+
:type: ``bool``
120+
:default: true
121+
122+
If set to True (the default), CMake will be run before building the wheel.
123+
124+
.. confval:: wheel.platlib
125+
:type: ``bool``
126+
127+
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.
128+
129+
.. confval:: wheel.exclude
130+
:type: ``list[str]``
131+
132+
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.
133+
134+
.. confval:: wheel.build-tag
135+
:type: ``str``
136+
137+
The build tag to use for the wheel. If empty, no build tag is used.
138+
139+
.. confval:: backport.find-python
140+
:type: ``Version``
141+
:default: "3.26.1"
142+
143+
If CMake is less than this value, backport a copy of FindPython. Set to 0 disable this, or the empty string.
144+
145+
.. confval:: editable.mode
146+
:type: ``"redirect" | "inplace"``
147+
:default: "redirect"
148+
149+
Select the editable mode to use. Can be "redirect" (default) or "inplace".
150+
151+
.. confval:: editable.verbose
152+
:type: ``bool``
153+
:default: true
154+
155+
Turn on verbose output for the editable mode rebuilds.
156+
157+
.. confval:: editable.rebuild
158+
:type: ``bool``
159+
:default: false
160+
161+
Rebuild the project when the package is imported. The build-directory must be set.
162+
163+
.. confval:: build.tool-args
164+
:type: ``list[str]``
165+
166+
Extra args to pass directly to the builder in the build step.
167+
168+
.. confval:: build.targets
169+
:type: ``list[str]``
170+
171+
The build targets to use when building the project. Empty builds the default target.
172+
173+
.. confval:: build.verbose
174+
:type: ``bool``
175+
:default: false
176+
177+
Verbose printout when building.
178+
179+
.. confval:: build.requires
180+
:type: ``list[str]``
181+
182+
Additional ``build-system.requires``. Intended to be used in combination with ``overrides``.
183+
184+
.. confval:: install.components
185+
:type: ``list[str]``
186+
187+
The components to install. If empty, all default components are installed.
188+
189+
.. confval:: install.strip
190+
:type: ``bool``
191+
:default: true
192+
193+
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).
194+
195+
.. confval:: generate[].path
196+
:type: ``Path``
197+
198+
The path (relative to platlib) for the file to generate.
199+
200+
.. confval:: generate[].template
201+
:type: ``str``
202+
203+
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.
204+
205+
.. confval:: generate[].template-path
206+
:type: ``Path``
207+
208+
The path to the template file. If empty, a template must be set.
209+
210+
.. confval:: generate[].location
211+
:type: ``"install" | "build" | "source"``
212+
:default: "install"
213+
214+
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.
215+
216+
.. confval:: messages.after-failure
217+
:type: ``str``
218+
219+
A message to print after a build failure.
220+
221+
.. confval:: messages.after-success
222+
:type: ``str``
223+
224+
A message to print after a successful build.
225+
226+
.. confval:: search.site-packages
227+
:type: ``bool``
228+
:default: true
229+
230+
Add the python build environment site_packages folder to the CMake prefix paths.
231+
232+
.. confval:: metadata
233+
:type: ``dict[str,dict[str,Any]]``
234+
235+
List dynamic metadata fields and hook locations in this table.
236+
237+
.. confval:: strict-config
238+
:type: ``bool``
239+
:default: true
240+
241+
Strictly check all config options. If False, warnings will be printed for unknown options. If True, an error will be raised.
242+
243+
.. confval:: experimental
244+
:type: ``bool``
245+
:default: false
246+
247+
Enable early previews of features not finalized yet.
248+
249+
.. confval:: minimum-version
250+
:type: ``Version``
251+
:default: "0.11" # current version
252+
253+
If set, this will provide a method for backward compatibility.
254+
255+
.. confval:: build-dir
256+
:type: ``str``
257+
258+
The build directory. Defaults to a temporary directory, but can be set.
259+
260+
.. confval:: fail
261+
:type: ``bool``
262+
:default: false
263+
264+
Immediately fail the build. This is only useful in overrides.

noxfile.py

Lines changed: 23 additions & 0 deletions
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

Lines changed: 33 additions & 2 deletions
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)