Skip to content

Commit 9a9e61b

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 a3c007d commit 9a9e61b

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
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

src/scikit_build_core/format.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Format variables available in the ``pyproject.toml`` evaluation"""
2+
3+
from __future__ import annotations
4+
5+
import dataclasses
6+
from collections.abc import Mapping
7+
from typing import TYPE_CHECKING, Any
8+
9+
if TYPE_CHECKING:
10+
from collections.abc import Iterator
11+
12+
from scikit_build_core.settings.skbuild_model import ScikitBuildSettings
13+
14+
__all__ = [
15+
"Formatter",
16+
]
17+
18+
19+
@dataclasses.dataclass
20+
class Formatter(Mapping[str, Any]):
21+
"""Formatting helper"""
22+
23+
_dict: dict[str, Any] = dataclasses.field(init=False)
24+
"""Dict storage of the acceptable variable keys and their expanded values."""
25+
settings: ScikitBuildSettings
26+
"""Parsed settings."""
27+
28+
def __getitem__(self, key: str) -> Any:
29+
return self._dict[key]
30+
31+
def __len__(self) -> int:
32+
return len(self._dict)
33+
34+
def __iter__(self) -> Iterator[Any]:
35+
return iter(self._dict)
36+
37+
def __post_init__(self) -> None:
38+
# TODO: Initialize the container with all known values
39+
self._dict = {}

0 commit comments

Comments
 (0)