Skip to content

Commit f4cbcb7

Browse files
committed
Refine Sphinx documentation generation
Signed-off-by: Tobias Wolf <wolf@b1-systems.de> On-behalf-of: SAP <tobias.wolf@sap.com>
1 parent ed0a9a1 commit f4cbcb7

File tree

11 files changed

+92
-73
lines changed

11 files changed

+92
-73
lines changed

.github/workflows/docs.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,29 @@ env:
88
GIT_CLIFF_VERSION: 2.12.0
99

1010
jobs:
11+
docs:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
15+
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@main
16+
- run: make docs
17+
- if: ${{ github.ref_name != 'main' }}
18+
name: Upload as artifact
19+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # pin@v6.0.0
20+
with:
21+
name: docs
22+
path: _build/
23+
- if: ${{ github.ref_name == 'main' }}
24+
name: Deploy to GitHub Pages
25+
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
26+
with:
27+
publish_branch: gh-pages
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
publish_dir: _build
30+
force_orphan: true
31+
1132
create-pre-release:
33+
if: ${{ github.ref_name == 'main' }}
1234
runs-on: ubuntu-latest
1335
permissions:
1436
contents: write

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
API Reference
2-
============
2+
=============
33

44
This section provides detailed documentation for all Python modules and classes in python-gardenlinux-lib.
55

docs/cli.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ gl-cname
1111

1212
Generate a canonical name (cname) from feature sets.
1313

14-
.. autoprogram:: gardenlinux.features.cname_main:parser
14+
.. autoprogram:: gardenlinux.features.cname_main:get_parser()
1515

1616
gl-features-parse
1717
~~~~~~~~~~~~~~~~~
1818

1919
Parse and extract information from GardenLinux features.
2020

21-
.. autoprogram:: gardenlinux.features.__main__:parser
21+
.. autoprogram:: gardenlinux.features.__main__:get_parser()
2222

2323
Flavors Commands
2424
----------------
@@ -28,7 +28,7 @@ gl-flavors-parse
2828

2929
Parse flavors.yaml and generate combinations.
3030

31-
.. autoprogram:: gardenlinux.flavors.__main__:parser
31+
.. autoprogram:: gardenlinux.flavors.__main__:get_parser()
3232

3333
OCI Commands
3434
------------
@@ -50,7 +50,7 @@ gl-s3
5050

5151
Upload and download artifacts from S3 buckets.
5252

53-
.. autoprogram:: gardenlinux.s3.__main__:parser
53+
.. autoprogram:: gardenlinux.s3.__main__:get_parser()
5454

5555
GitHub Commands
5656
---------------
@@ -60,4 +60,4 @@ gl-gh-release
6060

6161
Create and manage GitHub releases.
6262

63-
.. autoprogram:: gardenlinux.github.release.__main__:parser
63+
.. autoprogram:: gardenlinux.github.release.__main__:get_parser()

docs/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
33

4-
sys.path.insert(0, os.path.abspath("../src"))
4+
from sphinx.application import Sphinx
55

66

77
# Configuration file for the Sphinx documentation builder.
@@ -41,9 +41,9 @@
4141

4242
# Logo configuration
4343
html_logo = "_static/gardenlinux-logo.svg"
44+
4445
html_theme_options = {
4546
"logo_only": False,
46-
"display_version": True,
4747
"prev_next_buttons_location": "bottom",
4848
"style_external_links": True,
4949
"vcs_pageview_mode": "",
@@ -57,5 +57,5 @@
5757

5858

5959
# Add custom CSS
60-
def setup(app):
60+
def setup(app: Sphinx) -> None:
6161
app.add_css_file("custom.css")

src/gardenlinux/features/__main__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,46 +47,55 @@ def get_parser() -> argparse.ArgumentParser:
4747
:return: ArgumentParser instance
4848
:since: 0.10.9
4949
"""
50+
5051
parser = argparse.ArgumentParser(
51-
description="Parse and extract information from GardenLinux features."
52+
prog="gl-features-parse",
53+
description="Parse and extract information from GardenLinux features.",
5254
)
5355

5456
parser.add_argument(
5557
"--arch",
5658
dest="arch",
5759
help="Target architecture (e.g., amd64, arm64). Overrides architecture from cname.",
5860
)
61+
5962
parser.add_argument(
6063
"--cname",
6164
dest="cname",
6265
required=True,
6366
help="Canonical name (cname) to parse. Must be a valid GardenLinux canonical name.",
6467
)
68+
6569
parser.add_argument(
6670
"--commit",
6771
dest="commit",
6872
help="Git commit hash. If not specified, will be read from COMMIT file or release file.",
6973
)
74+
7075
parser.add_argument(
7176
"--feature-dir",
7277
default="features",
7378
help="Path to the features directory (default: 'features'). Either --feature-dir or --release-file must be provided.",
7479
)
80+
7581
parser.add_argument(
7682
"--release-file",
7783
dest="release_file",
7884
help="Path to a release file containing cname metadata. Either --feature-dir or --release-file must be provided.",
7985
)
86+
8087
parser.add_argument(
8188
"--default-arch",
8289
dest="default_arch",
8390
help="Default architecture to use if architecture cannot be determined from cname or other sources.",
8491
)
92+
8593
parser.add_argument(
8694
"--default-version",
8795
dest="default_version",
8896
help="Default version to use if version cannot be determined from files or other sources.",
8997
)
98+
9099
parser.add_argument(
91100
"--version",
92101
dest="version",
@@ -110,12 +119,8 @@ def get_parser() -> argparse.ArgumentParser:
110119
", ".join(_ARGS_TYPE_ALLOWED)
111120
),
112121
)
113-
return parser
114122

115-
116-
# Parser object for documentation generation
117-
parser = get_parser()
118-
parser.prog = "gl-features-parse"
123+
return parser
119124

120125

121126
def main() -> None:

src/gardenlinux/features/cname_main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,42 @@ def get_parser() -> argparse.ArgumentParser:
2626
:return: ArgumentParser instance
2727
:since: 1.0.0
2828
"""
29+
2930
parser = argparse.ArgumentParser(
30-
description="Generate a canonical name (cname) from feature sets."
31+
prog="gl-cname",
32+
description="Generate a canonical name (cname) from feature sets.",
3133
)
34+
3235
parser.add_argument(
3336
"--arch",
3437
dest="arch",
3538
help="Target architecture (e.g., amd64, arm64). If not specified, will be determined from the cname or feature set.",
3639
)
40+
3741
parser.add_argument(
3842
"--commit",
3943
dest="commit",
4044
help="Git commit hash. If not specified, will be read from COMMIT file in the GardenLinux root directory.",
4145
)
46+
4247
parser.add_argument(
4348
"--feature-dir",
4449
default="features",
4550
help="Path to the features directory (default: 'features').",
4651
)
52+
4753
parser.add_argument(
4854
"--version",
4955
dest="version",
5056
help="Version string. If not specified, will be read from VERSION file in the GardenLinux root directory.",
5157
)
58+
5259
parser.add_argument(
5360
"cname",
5461
help="Canonical name (cname) to process. Must be a valid GardenLinux canonical name format.",
5562
)
56-
return parser
5763

58-
59-
# Parser object for documentation generation
60-
parser = get_parser()
61-
parser.prog = "gl-cname"
64+
return parser
6265

6366

6467
def main() -> None:

src/gardenlinux/flavors/__main__.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import json
9-
from argparse import ArgumentParser, Namespace
9+
from argparse import ArgumentParser
1010
from pathlib import Path
1111
from tempfile import TemporaryDirectory
1212
from typing import Any, List, Tuple
@@ -55,67 +55,79 @@ def get_parser() -> ArgumentParser:
5555
:return: ArgumentParser instance
5656
:since: 1.0.0
5757
"""
58+
5859
parser = ArgumentParser(description="Parse flavors.yaml and generate combinations.")
5960

6061
parser.add_argument(
6162
"--commit",
6263
default=None,
6364
help="Commit hash to fetch flavors.yaml from GitHub. An existing 'flavors.yaml' file will be preferred.",
6465
)
66+
6567
parser.add_argument(
6668
"--no-arch",
6769
action="store_true",
6870
help="Exclude architecture from the flavor output.",
6971
)
72+
7073
parser.add_argument(
7174
"--include-only",
7275
action="append",
7376
default=[],
7477
help="Restrict combinations to those matching wildcard patterns (can be specified multiple times).",
7578
)
79+
7680
parser.add_argument(
7781
"--exclude",
7882
action="append",
7983
default=[],
8084
help="Exclude combinations based on wildcard patterns (can be specified multiple times).",
8185
)
86+
8287
parser.add_argument(
8388
"--build",
8489
action="store_true",
8590
help="Filter combinations to include only those with build enabled.",
8691
)
92+
8793
parser.add_argument(
8894
"--publish",
8995
action="store_true",
9096
help="Filter combinations to include only those with publish enabled.",
9197
)
98+
9299
parser.add_argument(
93100
"--test",
94101
action="store_true",
95102
help="Filter combinations to include only those with test enabled.",
96103
)
104+
97105
parser.add_argument(
98106
"--test-platform",
99107
action="store_true",
100108
help="Filter combinations to include only platforms with test-platform: true.",
101109
)
110+
102111
parser.add_argument(
103112
"--category",
104113
action="append",
105114
default=[],
106115
help="Filter combinations to include only platforms belonging to the specified categories (can be specified multiple times).",
107116
)
117+
108118
parser.add_argument(
109119
"--exclude-category",
110120
action="append",
111121
default=[],
112122
help="Exclude platforms belonging to the specified categories (can be specified multiple times).",
113123
)
124+
114125
parser.add_argument(
115126
"--json-by-arch",
116127
action="store_true",
117128
help="Output a JSON dictionary where keys are architectures and values are lists of flavors.",
118129
)
130+
119131
parser.add_argument(
120132
"--markdown-table-by-platform",
121133
action="store_true",
@@ -125,29 +137,15 @@ def get_parser() -> ArgumentParser:
125137
return parser
126138

127139

128-
# Parser object for documentation generation
129-
parser = get_parser()
130-
parser.prog = "gl-flavors-parse"
131-
132-
133-
def parse_args() -> Namespace:
134-
"""
135-
Parses arguments used for main()
136-
137-
:return: (object) Parsed argparse.ArgumentParser namespace
138-
:since: 0.7.0
139-
"""
140-
return get_parser().parse_args()
141-
142-
143140
def main() -> None:
144141
"""
145142
gl-flavors-parse main()
146143
147144
:since: 0.7.0
148145
"""
149146

150-
args = parse_args()
147+
parser = get_parser()
148+
args = parser.parse_args()
151149

152150
try:
153151
flavors_data = _get_flavors_file_data(Path(Repository().root, "flavors.yaml"))

0 commit comments

Comments
 (0)