Skip to content

Commit 46fa770

Browse files
committed
Add a format choice
Signed-off-by: Cristian Le <[email protected]>
1 parent b965df7 commit 46fa770

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/scikit_build_core/settings/documentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class DCDoc:
6262

6363
def __str__(self) -> str:
6464
docs = "\n".join(f"# {s}" for s in textwrap.wrap(self.docs, width=78))
65-
return f"{docs}\n{self.name} = {self.default}\n"
65+
return f"{docs}\n{self.name} = {self.default}"
6666

6767

6868
def get_metadata_field(field: dataclasses.Field[U], field_name: str, default: T) -> T:
Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,48 @@
11
from __future__ import annotations
22

3+
import textwrap
4+
from typing import TYPE_CHECKING
5+
36
from .documentation import mk_docs
47
from .skbuild_model import ScikitBuildSettings
58

9+
if TYPE_CHECKING:
10+
from typing import Literal
11+
612
__all__ = ["mk_skbuild_docs"]
713

814

915
def __dir__() -> list[str]:
1016
return __all__
1117

1218

13-
def mk_skbuild_docs() -> str:
19+
FORMATS = {
20+
"readme": textwrap.dedent("""\
21+
{item}
22+
"""),
23+
}
24+
25+
26+
def mk_skbuild_docs(output_format: Literal["readme"] = "readme") -> str:
1427
"""
1528
Makes documentation for the skbuild model.
1629
"""
17-
return "\n".join(
18-
str(item) for item in mk_docs(ScikitBuildSettings) if not item.deprecated
19-
)
30+
items = list(mk_docs(ScikitBuildSettings))
31+
# Filter deprecated fields
32+
if output_format == "readme":
33+
items = [item for item in items if not item.deprecated]
34+
return "\n".join(FORMATS[output_format].format(item=item) for item in items)
2035

2136

2237
if __name__ == "__main__":
23-
print(mk_skbuild_docs()) # noqa: T201
38+
import argparse
39+
40+
parser = argparse.ArgumentParser()
41+
parser.add_argument(
42+
"--format",
43+
default="readme",
44+
choices=["readme"],
45+
help="Output format",
46+
)
47+
args = parser.parse_args()
48+
print(mk_skbuild_docs(args.format)) # noqa: T201

0 commit comments

Comments
 (0)