Skip to content

Commit 9704924

Browse files
👷 Upgrade build docs configs (#1047)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0678615 commit 9704924

File tree

9 files changed

+146
-35
lines changed

9 files changed

+146
-35
lines changed

.github/workflows/build-docs.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ jobs:
2828
- docs/**
2929
- docs_src/**
3030
- requirements-docs.txt
31+
- requirements-docs-insiders.txt
3132
- pyproject.toml
3233
- mkdocs.yml
3334
- mkdocs.insiders.yml
35+
- mkdocs.maybe-insiders.yml
36+
- mkdocs.no-insiders.yml
3437
- .github/workflows/build-docs.yml
3538
- .github/workflows/deploy-docs.yml
3639
@@ -53,16 +56,15 @@ jobs:
5356
id: cache
5457
with:
5558
path: ${{ env.pythonLocation }}
56-
key: ${{ runner.os }}-python-docs-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-docs.txt') }}-v01
59+
key: ${{ runner.os }}-python-docs-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-docs.txt', 'requirements-docs-insiders.txt', 'requirements-docs-tests.txt') }}-v02
5760
- name: Install docs extras
5861
if: steps.cache.outputs.cache-hit != 'true'
5962
run: pip install -r requirements-docs.txt
6063
- name: Install Material for MkDocs Insiders
6164
if: ( github.event_name != 'pull_request' || github.secret_source == 'Actions' ) && steps.cache.outputs.cache-hit != 'true'
62-
run: |
63-
pip install git+https://${{ secrets.SQLMODEL_MKDOCS_MATERIAL_INSIDERS }}@github.com/squidfunk/mkdocs-material-insiders.git
64-
pip install git+https://${{ secrets.SQLMODEL_MKDOCS_MATERIAL_INSIDERS }}@github.com/pawamoy-insiders/griffe-typing-deprecated.git
65-
pip install git+https://${{ secrets.SQLMODEL_MKDOCS_MATERIAL_INSIDERS }}@github.com/pawamoy-insiders/mkdocstrings-python.git
65+
run: pip install -r requirements-docs-insiders.txt
66+
env:
67+
TOKEN: ${{ secrets.SQLMODEL_MKDOCS_MATERIAL_INSIDERS }}
6668
- uses: actions/cache@v4
6769
with:
6870
key: mkdocs-cards-${{ github.ref }}

docs/js/custom.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,6 @@ async function main() {
110110
setupTermynal()
111111
}
112112

113-
main()
113+
document$.subscribe(() => {
114+
main()
115+
})

docs/tutorial/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Intro, Installation, and First Steps
22

3+
Before we start playing with **SQLModel**, let's prepare everything else we need. A bit of type annotations, setting up the environment to install everything, and installing DB Browser for SQLite. 🤓
4+
35
## Type hints
46

57
If you need a refresher about how to use Python type hints (type annotations), check <a href="https://fastapi.tiangolo.com/python-types/" class="external-link" target="_blank">FastAPI's Python types intro</a>.

mkdocs.insiders.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
plugins:
2-
social:
32
typeset:
3+
markdown_extensions:
4+
material.extensions.preview:
5+
targets:
6+
include:
7+
- ./*

mkdocs.yml

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,43 @@ theme:
2525
icon: material/lightbulb-outline
2626
name: Switch to system preference
2727
features:
28-
- search.suggest
29-
- search.highlight
28+
- content.code.annotate
29+
- content.code.copy
30+
# - content.code.select
31+
- content.footnote.tooltips
3032
- content.tabs.link
31-
- navigation.indexes
3233
- content.tooltips
34+
- navigation.footer
35+
- navigation.indexes
36+
- navigation.instant
37+
- navigation.instant.prefetch
38+
- navigation.instant.preview
39+
- navigation.instant.progress
3340
- navigation.path
34-
- content.code.annotate
35-
- content.code.copy
36-
- content.code.select
3741
# - navigation.tabs
42+
# - navigation.tabs.sticky
43+
- navigation.top
44+
- navigation.tracking
45+
- search.highlight
46+
- search.share
47+
- search.suggest
48+
- toc.follow
49+
3850
icon:
3951
repo: fontawesome/brands/github-alt
4052
logo: img/icon-white.svg
4153
favicon: img/favicon.png
4254
language: en
4355
repo_name: tiangolo/sqlmodel
4456
repo_url: https://github.com/tiangolo/sqlmodel
45-
edit_uri: ''
4657
plugins:
47-
search: null
48-
markdownextradata:
49-
data: ./data
58+
# Material for MkDocs
59+
search:
60+
social:
61+
# Other plugins
62+
macros:
63+
include_yaml:
64+
- sponsors: data/sponsors.yml
5065

5166
nav:
5267
- SQLModel: index.md
@@ -113,33 +128,68 @@ nav:
113128
- release-notes.md
114129

115130
markdown_extensions:
116-
markdown.extensions.attr_list:
117-
markdown.extensions.tables:
118-
markdown.extensions.md_in_html:
131+
# Python Markdown
132+
abbr:
133+
attr_list:
134+
footnotes:
135+
md_in_html:
136+
tables:
119137
toc:
120138
permalink: true
139+
140+
# Python Markdown Extensions
141+
pymdownx.betterem:
142+
smart_enable: all
143+
pymdownx.caret:
144+
pymdownx.highlight:
145+
line_spans: __span
146+
pymdownx.inlinehilite:
147+
pymdownx.keys:
148+
pymdownx.mark:
121149
pymdownx.superfences:
122150
custom_fences:
123151
- name: mermaid
124152
class: mermaid
125-
format: !!python/name:pymdownx.superfences.fence_code_format ''
126-
pymdownx.betterem:
127-
pymdownx.blocks.details:
153+
format: !!python/name:pymdownx.superfences.fence_code_format
154+
pymdownx.tilde:
155+
156+
# pymdownx blocks
128157
pymdownx.blocks.admonition:
129158
types:
130159
- note
131-
- info
160+
- attention
161+
- caution
162+
- danger
163+
- error
132164
- tip
165+
- hint
133166
- warning
134-
- danger
167+
# Custom types
168+
- info
169+
pymdownx.blocks.details:
135170
pymdownx.blocks.tab:
136171
alternate_style: True
172+
173+
# Other extensions
137174
mdx_include:
138175

139176
extra:
140177
analytics:
141178
provider: google
142179
property: G-J8HVTT936W
180+
feedback:
181+
title: Was this page helpful?
182+
ratings:
183+
- icon: material/emoticon-happy-outline
184+
name: This page was helpful
185+
data: 1
186+
note: >-
187+
Thanks for your feedback!
188+
- icon: material/emoticon-sad-outline
189+
name: This page could be improved
190+
data: 0
191+
note: >-
192+
Thanks for your feedback!
143193
social:
144194
- icon: fontawesome/brands/github-alt
145195
link: https://github.com/tiangolo/sqlmodel
@@ -161,3 +211,6 @@ extra_css:
161211
extra_javascript:
162212
- js/termynal.js
163213
- js/custom.js
214+
215+
hooks:
216+
- scripts/mkdocs_hooks.py

requirements-docs-insiders.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
git+https://${TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git@9.5.30-insiders-4.53.11
2+
git+https://${TOKEN}@github.com/pawamoy-insiders/griffe-typing-deprecated.git
3+
git+https://${TOKEN}@github.com/pawamoy-insiders/mkdocstrings-python.git

requirements-docs.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
-e .
22
-r requirements-docs-tests.txt
3-
mkdocs-material==9.4.7
3+
mkdocs-material==9.5.18
44
mdx-include >=1.4.1,<2.0.0
5-
mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0
65
mkdocs-redirects>=1.2.1,<1.3.0
76
pyyaml >=5.3.1,<7.0.0
87
# For Material for MkDocs, Chinese search
9-
jieba==0.42.1
8+
# jieba==0.42.1
109
# For image processing by Material for MkDocs
11-
pillow==10.1.0
10+
pillow==10.3.0
1211
# For image processing by Material for MkDocs
1312
cairosvg==2.7.1
14-
mkdocstrings[python]==0.25.1
13+
# mkdocstrings[python]==0.25.1
1514
# Enable griffe-typingdoc once dropping Python 3.7 and upgrading typing-extensions
1615
# griffe-typingdoc==0.2.5
1716
# For griffe, it formats with black
1817
typer == 0.12.3
18+
mkdocs-macros-plugin==1.0.5

scripts/docs.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from importlib import metadata
88
from pathlib import Path
99

10-
import mkdocs.commands.build
11-
import mkdocs.commands.serve
12-
import mkdocs.config
1310
import mkdocs.utils
1411
import typer
1512
from jinja2 import Template
@@ -68,6 +65,13 @@ def generate_readme_content() -> str:
6865
pre_content = content[frontmatter_end:pre_end]
6966
post_content = content[post_start:]
7067
new_content = pre_content + message + post_content
68+
# Remove content between <!-- only-mkdocs --> and <!-- /only-mkdocs -->
69+
new_content = re.sub(
70+
r"<!-- only-mkdocs -->.*?<!-- /only-mkdocs -->",
71+
"",
72+
new_content,
73+
flags=re.DOTALL,
74+
)
7175
return new_content
7276

7377

@@ -111,8 +115,11 @@ def live() -> None:
111115
en.
112116
"""
113117
# Enable line numbers during local development to make it easier to highlight
114-
os.environ["LINENUMS"] = "true"
115-
mkdocs.commands.serve.serve(dev_addr="127.0.0.1:8008")
118+
subprocess.run(
119+
["mkdocs", "serve", "--dev-addr", "127.0.0.1:8008", "--dirty"],
120+
env={**os.environ, "LINENUMS": "true"},
121+
check=True,
122+
)
116123

117124

118125
@app.command()

scripts/mkdocs_hooks.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Any, List, Union
2+
3+
from mkdocs.config.defaults import MkDocsConfig
4+
from mkdocs.structure.files import Files
5+
from mkdocs.structure.nav import Link, Navigation, Section
6+
from mkdocs.structure.pages import Page
7+
8+
9+
def generate_renamed_section_items(
10+
items: List[Union[Page, Section, Link]], *, config: MkDocsConfig
11+
) -> List[Union[Page, Section, Link]]:
12+
new_items: List[Union[Page, Section, Link]] = []
13+
for item in items:
14+
if isinstance(item, Section):
15+
new_title = item.title
16+
new_children = generate_renamed_section_items(item.children, config=config)
17+
first_child = new_children[0]
18+
if isinstance(first_child, Page):
19+
if first_child.file.src_path.endswith("index.md"):
20+
# Read the source so that the title is parsed and available
21+
first_child.read_source(config=config)
22+
new_title = first_child.title or new_title
23+
# Creating a new section makes it render it collapsed by default
24+
# no idea why, so, let's just modify the existing one
25+
# new_section = Section(title=new_title, children=new_children)
26+
item.title = new_title
27+
item.children = new_children
28+
new_items.append(item)
29+
else:
30+
new_items.append(item)
31+
return new_items
32+
33+
34+
def on_nav(
35+
nav: Navigation, *, config: MkDocsConfig, files: Files, **kwargs: Any
36+
) -> Navigation:
37+
new_items = generate_renamed_section_items(nav.items, config=config)
38+
return Navigation(items=new_items, pages=nav.pages)

0 commit comments

Comments
 (0)