Skip to content

Commit 5c4d9d1

Browse files
committed
Add a format module
Have a central location to view and evaluate all format variables used in the evaluation of the `pyproject.toml` Signed-off-by: Cristian Le <[email protected]>
1 parent 76cbc06 commit 5c4d9d1

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

docs/api/scikit_build_core.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ scikit\_build\_core.errors module
4141
:show-inheritance:
4242
:undoc-members:
4343

44+
scikit\_build\_core.format module
45+
---------------------------------
46+
47+
.. automodule:: scikit_build_core.format
48+
:members:
49+
:show-inheritance:
50+
:undoc-members:
51+
4452
scikit\_build\_core.program\_search module
4553
------------------------------------------
4654

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ known-local-folder = ["pathutils"]
290290
"typing.Self".msg = "Use scikit_build_core._compat.typing.Self instead."
291291
"typing_extensions.Self".msg = "Use scikit_build_core._compat.typing.Self instead."
292292
"typing.Final".msg = "Add scikit_build_core._compat.typing.Final instead."
293-
"typing.NotRequired".msg = "Add scikit_build_core._compat.typing.NotRequired instead."
294-
"typing.OrderedDict".msg = "Add scikit_build_core._compat.typing.OrderedDict instead."
295-
"typing.TypedDict".msg = "Add scikit_build_core._compat.typing.TypedDict instead."
296293
"typing.assert_never".msg = "Add scikit_build_core._compat.typing.assert_never instead."
297294
"tomli".msg = "Use scikit_build_core._compat.tomllib instead."
298295
"tomllib".msg = "Use scikit_build_core._compat.tomllib instead."

src/scikit_build_core/format.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Format variables available in the ``pyproject.toml`` evaluation"""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING, TypedDict
6+
7+
if TYPE_CHECKING:
8+
from scikit_build_core.settings.skbuild_model import ScikitBuildSettings
9+
10+
__all__ = [
11+
"pyproject_format",
12+
]
13+
14+
15+
def __dir__() -> list[str]:
16+
return __all__
17+
18+
19+
class PyprojectFormatter(TypedDict, total=False):
20+
"""Format helper for pyproject.toml.
21+
22+
Stores all known variables that can be used for evaluating a formatted string
23+
in the pyproject.toml config file.
24+
"""
25+
26+
27+
def pyproject_format(
28+
*,
29+
settings: ScikitBuildSettings | None = None, # noqa: ARG001
30+
dummy: bool = False,
31+
) -> PyprojectFormatter | dict[str, str]:
32+
if dummy:
33+
# Return a dict with all the known keys but with values replaced with dummy values
34+
return {key: "*" for key in PyprojectFormatter.__annotations__}
35+
return PyprojectFormatter()

0 commit comments

Comments
 (0)