1- from __future__ import annotations
1+ # No `from __future__ import annotations` here: `to_json_schema` reads real
2+ # runtime types from the dataclass fields, like `skbuild_model.py`.
23
34__lazy_modules__ = {
45 f"{ (__spec__ .parent or '' ).rsplit ('.' , 1 )[0 ]} ._logging" ,
910
1011import dataclasses
1112import re
12- from typing import Any , Literal
13+ from typing import Any , Dict , List , Literal , Optional , Union
1314
1415from .._logging import rich_error
1516from .skbuild_model import ScikitBuildSettings
2728]
2829
2930
30- def __dir__ () -> list [str ]:
31+ def __dir__ () -> List [str ]:
3132 return __all__
3233
3334
@@ -36,10 +37,7 @@ def __dir__() -> list[str]:
3637_NAME_REGEX = re .compile (r"^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)+$" )
3738
3839# A "choices" key (allowed values, str type only) was cut from the initial
39- # release to keep the surface minimal. To re-add: a `choices: list[str] | None`
40- # field here, load-time validation (list of strings, not with type = 'bool',
41- # default must be a member), a resolved-value check in resolve_config_settings,
42- # and the entry-schema property in skbuild_schema.py.
40+ # release to keep the surface minimal; see git history to re-add.
4341_DECLARATION_KEYS = frozenset ({"help" , "type" , "default" , "env" })
4442
4543
@@ -54,28 +52,45 @@ class ConfigSettingDeclaration:
5452 """
5553
5654 help : str = ""
55+ """
56+ A description of the setting.
57+ """
58+
5759 type : Literal ["str" , "bool" ] = "str"
58- default : str | bool | None = None
59- env : str | None = None
60+ """
61+ The type of the setting.
62+ """
63+
64+ default : Optional [Union [str , bool ]] = None
65+ """
66+ The value used when the setting is not passed; must match the type.
67+ """
68+
69+ env : Optional [str ] = None
70+ """
71+ An environment variable also read for this setting; it takes precedence over `-C`.
72+ """
6073
6174
6275def _error_context (name : str ) -> str :
6376 return f"tool.scikit-build.config-setting.{ name !r} "
6477
6578
66- def load_declarations (raw : Any ) -> dict [str , ConfigSettingDeclaration ]:
79+ def load_declarations (raw : Any ) -> Dict [str , ConfigSettingDeclaration ]:
6780 """
6881 Validate and load the raw ``tool.scikit-build.config-setting`` table.
6982 """
7083 if not isinstance (raw , dict ):
7184 rich_error ("tool.scikit-build.config-setting must be a table" )
85+ if not raw :
86+ return {}
7287
7388 reserved = {
7489 field .name .replace ("_" , "-" )
7590 for field in dataclasses .fields (ScikitBuildSettings )
7691 } | {"overrides" , "config-setting" , "skbuild" }
7792
78- decls : dict [str , ConfigSettingDeclaration ] = {}
93+ decls : Dict [str , ConfigSettingDeclaration ] = {}
7994 for name , entry in raw .items ():
8095 if not _NAME_REGEX .match (name ):
8196 rich_error (
@@ -130,17 +145,17 @@ def load_declarations(raw: Any) -> dict[str, ConfigSettingDeclaration]:
130145
131146
132147def resolve_config_settings (
133- decls : Mapping [str , ConfigSettingDeclaration ],
134- config_settings : Mapping [str , str | list [str ] | bool ],
135- env : Mapping [str , str ],
136- ) -> dict [str , str | bool | None ]:
148+ decls : " Mapping[str, ConfigSettingDeclaration]" ,
149+ config_settings : " Mapping[str, Union[ str, List [str], bool]]" ,
150+ env : " Mapping[str, str]" ,
151+ ) -> Dict [str , Optional [ Union [ str , bool ]] ]:
137152 """
138153 Resolve declared config-settings; precedence env var > config-setting >
139154 default, with ``None`` meaning "unset".
140155 """
141- values : dict [str , str | bool | None ] = {}
156+ values : Dict [str , Optional [ Union [ str , bool ]] ] = {}
142157 for name , decl in decls .items ():
143- raw : str | bool | None
158+ raw : Optional [ Union [ str , bool ]]
144159 if decl .env is not None and decl .env in env :
145160 raw = env [decl .env ]
146161 elif name in config_settings :
@@ -165,7 +180,7 @@ def resolve_config_settings(
165180
166181
167182def resolve_define_references (
168- tool_skb : dict [str , Any ], values : Mapping [str , str | bool | None ]
183+ tool_skb : Dict [str , Any ], values : " Mapping[str, Optional[Union[ str, bool]]]"
169184) -> None :
170185 """
171186 Replace ``{config-setting = "..."}`` values in the raw ``cmake.define``
0 commit comments