Skip to content

Commit ffde53f

Browse files
authored
Merge pull request #30 from python-project-templates/tkp/upd
Expose more options to end user, expose options via cli, fixes #15
2 parents e27b3e3 + 6f498e7 commit ffde53f

7 files changed

Lines changed: 152 additions & 84 deletions

File tree

.github/workflows/docs.yml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
name: Docs
2-
32
on:
43
push:
5-
branches:
6-
- main
7-
tags:
8-
- v*
9-
paths-ignore:
10-
- LICENSE
11-
- README.md
12-
4+
branches: ["main"]
5+
tags: ["v*"]
6+
paths-ignore: ["LICENSE", "README.md"]
137
permissions:
148
contents: write
15-
169
jobs:
1710
docs:
1811
runs-on: ubuntu-latest
1912
steps:
20-
- uses: actions/checkout@v4
21-
- uses: actions/setup-python@v5
22-
- run: pip install .
23-
- run: make docs
24-
- name: Deploy
25-
uses: peaceiris/actions-gh-pages@v4
26-
with:
27-
publish_branch: gh-pages
28-
github_token: ${{ secrets.GITHUB_TOKEN }}
29-
publish_dir: docs/html
30-
force_orphan: true
13+
- uses: actions-ext/yardang@main

docs/src/configuration.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,30 @@ Whether or not to use [Sphinx AutoAPI](https://sphinx-autoapi.readthedocs.io/en/
113113
use-autoapi = true
114114
```
115115

116-
## [Autodoc Pydantic](https://autodoc-pydantic.readthedocs.io/en/stable/users/examples.html) arguments
116+
## Sphinx Options
117+
118+
```toml
119+
[tool.yardang]
120+
html_theme_options = {}
121+
html_static_path = []
122+
html_css_files = []
123+
html_js_files = []
124+
source_suffix = []
125+
exclude_patterns = []
126+
language = "en"
127+
pygments_style = "sphinx"
128+
```
117129

118-
[Configuration for Autodoc Pydantic](https://autodoc-pydantic.readthedocs.io/en/stable/users/configuration.html).
130+
131+
## [Myst](https://myst-parser.readthedocs.io/en/latest/#)
119132

120133
```toml
121134
[tool.yardang]
122-
autodoc_pydantic_model_show_config_summary = false
123-
autodoc_pydantic_model_show_validator_summary = false
124-
autodoc_pydantic_model_show_validator_members = false
125-
autodoc_pydantic_field_list_validators = false
126-
autodoc_pydantic_field_show_constraints = false
127-
autodoc_pydantic_model_member_order = "bysource"
128-
autodoc_pydantic_model_show_json = true
129-
autodoc_pydantic_settings_show_json = false
130-
autodoc_pydantic_model_show_field_summary = false
135+
myst_enable_extensions = ["colon_fence"]
136+
myst_fence_as_directive = ["mermaid"]
131137
```
132138

133-
## Myst-NB
139+
## [Myst-NB](https://myst-nb.readthedocs.io/en/latest/#)
134140

135141
```toml
136142
[tool.yardang]
@@ -158,6 +164,22 @@ An example follows:
158164
../notebooks/example
159165
```
160166

167+
## [Autodoc Pydantic](https://autodoc-pydantic.readthedocs.io/en/stable/users/examples.html) arguments
168+
169+
[Configuration for Autodoc Pydantic](https://autodoc-pydantic.readthedocs.io/en/stable/users/configuration.html).
170+
171+
```toml
172+
[tool.yardang]
173+
autodoc_pydantic_model_show_config_summary = false
174+
autodoc_pydantic_model_show_validator_summary = false
175+
autodoc_pydantic_model_show_validator_members = false
176+
autodoc_pydantic_field_list_validators = false
177+
autodoc_pydantic_field_show_constraints = false
178+
autodoc_pydantic_model_member_order = "bysource"
179+
autodoc_pydantic_model_show_json = true
180+
autodoc_pydantic_settings_show_json = false
181+
autodoc_pydantic_model_show_field_summary = false
182+
```
161183

162184
## Mermaid
163185

docs/src/overview.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,14 @@ The following yaml should be all it takes to integrate your project with GitHub
3333
name: Docs
3434
on:
3535
push:
36-
branches:
37-
- main
36+
branches: ["main"]
37+
tags: ["v*"]
38+
paths-ignore: ["LICENSE", "README.md"]
3839
permissions:
39-
contents: write
40+
contents: write
4041
jobs:
4142
docs:
4243
runs-on: ubuntu-latest
4344
steps:
44-
- uses: actions/checkout@v4
45-
- uses: actions/setup-python@v5
46-
with:
47-
python-version: 3.11
48-
- run: pip install .
49-
- run: pip install yardang
50-
- run: yardang build
51-
- name: Deploy
52-
uses: peaceiris/actions-gh-pages@v4
53-
with:
54-
publish_branch: gh-pages
55-
github_token: ${{ secrets.GITHUB_TOKEN }}
56-
publish_dir: docs/html
45+
- uses: actions-ext/yardang@main
5746
```

pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,31 @@ pages = [
144144
"docs/src/configuration.md",
145145
]
146146
use-autoapi = true
147+
148+
# Below are defaults, just to ensure working
149+
# sphinx
150+
html_theme_options = {"switcher" = { "json_url" = "https://mysite.org/en/latest/_static/switcher.json"}}
151+
html_static_path = ["test"]
152+
html_css_files = []
153+
html_js_files = []
154+
source_suffix = []
155+
exclude_patterns = []
156+
language = "en"
157+
pygments_style = "sphinx"
158+
159+
# myst/myst-nb
160+
myst_enable_extensions = ["colon_fence"]
161+
myst_fence_as_directive = ["mermaid"]
162+
nb_execution_mode = "off"
163+
nb_execution_excludepatterns = []
164+
165+
# autodoc/autodoc-pydantic
166+
autodoc_pydantic_model_show_config_summary = false
167+
autodoc_pydantic_model_show_validator_summary = false
168+
autodoc_pydantic_model_show_validator_members = false
169+
autodoc_pydantic_field_list_validators = false
170+
autodoc_pydantic_field_show_constraints = false
171+
autodoc_pydantic_model_member_order = "bysource"
172+
autodoc_pydantic_model_show_json = true
173+
autodoc_pydantic_settings_show_json = false
174+
autodoc_pydantic_model_show_field_summary = false

yardang/build.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,33 @@ def generate_docs_configuration(
7272
source_dir = os.path.curdir
7373

7474
configuration_args = {}
75-
for f in (
76-
# autodoc/autodoc-pydantic
77-
"autodoc_pydantic_model_show_config_summary",
78-
"autodoc_pydantic_model_show_validator_summary",
79-
"autodoc_pydantic_model_show_validator_members",
80-
"autodoc_pydantic_field_list_validators",
81-
"autodoc_pydantic_field_show_constraints",
82-
"autodoc_pydantic_model_member_order",
83-
"autodoc_pydantic_model_show_json",
84-
"autodoc_pydantic_settings_show_json",
85-
"autodoc_pydantic_model_show_field_summary",
75+
for config_option, default in {
76+
# sphinx generic
77+
"html_theme_options": {},
78+
"html_static_path": [],
79+
"html_css_files": [],
80+
"html_js_files": [],
81+
"source_suffix": [],
82+
"exclude_patterns": [],
83+
"language": "en",
84+
"pygments_style": "sphinx",
8685
# myst/myst-nb
87-
"nb_execution_mode",
88-
"nb_execution_excludepatterns",
89-
):
90-
default_value = {
91-
# autodoc/autodoc-pydantic
92-
"autodoc_pydantic_model_member_order": '"bysource"',
93-
"autodoc_pydantic_model_show_json": True,
94-
# myst/myst-nb
95-
"nb_execution_excludepatterns": [],
96-
"nb_execution_mode": "off",
97-
}.get(f, False)
98-
config_value = get_config(section=f"{f}")
99-
configuration_args[f] = default_value if config_value is None else config_value
86+
"myst_enable_extensions": ["colon_fence"],
87+
"myst_fence_as_directive": ["mermaid"],
88+
"nb_execution_mode": "off",
89+
"nb_execution_excludepatterns": [],
90+
# autodoc/autodoc-pydantic
91+
"autodoc_pydantic_model_show_config_summary": None,
92+
"autodoc_pydantic_model_show_validator_summary": None,
93+
"autodoc_pydantic_model_show_validator_members": None,
94+
"autodoc_pydantic_field_list_validators": None,
95+
"autodoc_pydantic_field_show_constraints": None,
96+
"autodoc_pydantic_model_member_order": "bysource",
97+
"autodoc_pydantic_model_show_json": True,
98+
"autodoc_pydantic_settings_show_json": None,
99+
"autodoc_pydantic_model_show_field_summary": None,
100+
}.items():
101+
configuration_args[config_option] = get_config(section=config_option) or default
100102
# create a temporary directory to store the conf.py file in
101103
with TemporaryDirectory() as td:
102104
templateEnv = Environment(loader=FileSystemLoader(searchpath=str(Path(__file__).parent.resolve())))

yardang/cli.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
1+
from pathlib import Path
12
from subprocess import Popen
23
from sys import executable, stderr, stdout
34
from time import sleep
5+
from typing import List, Optional
46

57
from typer import Exit, Typer
68

79
from .build import generate_docs_configuration
810

911

10-
def build(quiet: bool = False, debug: bool = False):
11-
with generate_docs_configuration() as file:
12+
def build(
13+
*,
14+
quiet: bool = False,
15+
debug: bool = False,
16+
pdb: bool = False,
17+
project: str = "",
18+
title: str = "",
19+
module: str = "",
20+
description: str = "",
21+
author: str = "",
22+
copyright: str = "",
23+
version: str = "",
24+
theme: str = "furo",
25+
docs_root: str = "",
26+
root: str = "",
27+
cname: str = "",
28+
pages: Optional[List[Path]] = None,
29+
use_autoapi: Optional[bool] = None,
30+
custom_css: Optional[Path] = None,
31+
custom_js: Optional[Path] = None,
32+
):
33+
with generate_docs_configuration(
34+
project=project,
35+
title=title,
36+
module=module,
37+
description=description,
38+
author=author,
39+
copyright=copyright,
40+
version=version,
41+
theme=theme,
42+
docs_root=docs_root,
43+
root=root,
44+
cname=cname,
45+
pages=pages,
46+
use_autoapi=use_autoapi,
47+
custom_css=custom_css,
48+
custom_js=custom_js,
49+
) as file:
1250
build_cmd = [
1351
executable,
1452
"-m",
@@ -28,6 +66,10 @@ def build(quiet: bool = False, debug: bool = False):
2866
while process.poll() is None:
2967
sleep(0.1)
3068
if process.returncode != 0:
69+
if pdb:
70+
import pdb
71+
72+
pdb.set_trace()
3173
raise Exit(process.returncode)
3274

3375

yardang/conf.py.j2

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,27 @@ else:
5555

5656
os.environ["SPHINX_BUILDING"] = "1"
5757
html_theme = "{{theme}}"
58-
html_theme_options = {}
59-
html_static_path = []
58+
html_theme_options = {{html_theme_options}}
59+
html_static_path = {{html_static_path}}
6060
html_css_files = [
6161
"styles/custom.css",
62+
*{{html_css_files}},
6263
]
6364
html_js_files = [
6465
"js/custom.js",
66+
*{{html_js_files}}
6567
]
6668

6769
master_doc = "index"
6870
templates_path = ["_templates"]
69-
source_suffix = [".rst", ".md"]
70-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "node_modules", "_skbuild", ".pytest_cache", "js/*"]
71-
language = "en"
72-
pygments_style = "sphinx"
71+
source_suffix = [".rst", ".md", *{{source_suffix}}]
72+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "node_modules", "_skbuild", ".pytest_cache", "js/*", *{{exclude_patterns}}]
73+
language = "{{language}}"
74+
pygments_style = "{{pygments_style}}"
7375

7476
# myst / myst-nb
75-
myst_enable_extensions = ["colon_fence"]
76-
myst_fence_as_directive = ["mermaid"]
77+
myst_enable_extensions = {{myst_enable_extensions}}
78+
myst_fence_as_directive = {{myst_fence_as_directive}}
7779
nb_execution_mode = "{{nb_execution_mode}}"
7880
nb_execution_excludepatterns = {{nb_execution_excludepatterns}}
7981

@@ -92,7 +94,7 @@ autodoc_pydantic_model_show_validator_summary = {{autodoc_pydantic_model_show_va
9294
autodoc_pydantic_model_show_validator_members = {{autodoc_pydantic_model_show_validator_members}} # noqa: F821
9395
autodoc_pydantic_field_list_validators = {{autodoc_pydantic_field_list_validators}} # noqa: F821
9496
autodoc_pydantic_field_show_constraints = {{autodoc_pydantic_field_show_constraints}} # noqa: F821
95-
autodoc_pydantic_model_member_order = {{autodoc_pydantic_model_member_order}} # noqa: F821
97+
autodoc_pydantic_model_member_order = "{{autodoc_pydantic_model_member_order}}" # noqa: F821
9698
autodoc_pydantic_model_show_json = {{autodoc_pydantic_model_show_json}} # noqa: F821
9799
autodoc_pydantic_settings_show_json = {{autodoc_pydantic_settings_show_json}} # noqa: F821
98100

0 commit comments

Comments
 (0)