Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf76e95

Browse files
committed
Use a static docs_by_version file
1 parent5ea7ed5 commitaf76e95

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

‎build_docs.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class DocBuilder:
521521
version:Version
522522
language:Language
523523
cpython_repo:Repository
524-
indexsidebar_content:bytes
524+
docs_by_version_content:bytes
525525
switchers_content:bytes
526526
build_root:Path
527527
www_root:Path
@@ -657,8 +657,7 @@ def build(self) -> None:
657657
text=text.replace(" -A switchers=1","")
658658
(self.checkout/"Doc"/"Makefile").write_text(text,encoding="utf-8")
659659

660-
indexsidebar_path=self.checkout/"Doc/tools/templates/indexsidebar.html"
661-
indexsidebar_path.write_bytes(self.indexsidebar_content)
660+
self.setup_indexsidebar()
662661
run_with_logging([
663662
"make",
664663
"-C",
@@ -701,6 +700,18 @@ def build_venv(self) -> None:
701700
run([venv_path/"bin"/"python","-m","pip","freeze","--all"])
702701
self.venv=venv_path
703702

703+
defsetup_indexsidebar(self)->None:
704+
"""Copy indexsidebar.html for Sphinx."""
705+
tmpl_src=HERE/"templates"
706+
tmpl_dst=self.checkout/"Doc"/"tools"/"templates"
707+
dbv_path=tmpl_dst/"_docs_by_version.html"
708+
709+
shutil.copy(tmpl_src/"indexsidebar.html",tmpl_dst/"indexsidebar.html")
710+
ifself.version.status!="EOL":
711+
dbv_path.write_bytes(self.docs_by_version_content)
712+
else:
713+
shutil.copy(tmpl_src/"_docs_by_version.html",dbv_path)
714+
704715
defcopy_build_to_webroot(self,http:urllib3.PoolManager)->None:
705716
"""Copy a given build to the appropriate webroot with appropriate rights."""
706717
logging.info("Publishing start.")
@@ -1086,7 +1097,7 @@ def build_docs(args: argparse.Namespace) -> bool:
10861097
force_build=args.force
10871098
delargs.force
10881099

1089-
isb_content,eol_isb_content=render_indexsidebar(versions)
1100+
docs_by_version_content=render_docs_by_version(versions).encode()
10901101
switchers_content=render_switchers(versions,languages)
10911102

10921103
build_succeeded=set()
@@ -1107,13 +1118,12 @@ def build_docs(args: argparse.Namespace) -> bool:
11071118
scope.set_tag("version",version.name)
11081119
scope.set_tag("language",language.tag)
11091120
cpython_repo.update()
1110-
v_isb_content=isb_contentifversion.status!="EOL"elseeol_isb_content
11111121
builder=DocBuilder(
11121122
version,
11131123
versions,
11141124
language,
11151125
cpython_repo,
1116-
v_isb_content,
1126+
docs_by_version_content,
11171127
switchers_content,
11181128
**vars(args),
11191129
)
@@ -1169,21 +1179,10 @@ def parse_languages_from_config() -> Languages:
11691179
returnLanguages.from_json(config["defaults"],config["languages"])
11701180

11711181

1172-
defrender_indexsidebar(versions:Versions)->tuple[bytes,bytes]:
1173-
"""Pre-render indexsidebar.html for Sphinx."""
1174-
docs_by_version=f"""\
1175-
<h3>{{% trans %}}Docs by version{{% endtrans %}}</h3>
1176-
<ul>
1177-
{"\n".join([f' <li><a href="{v.url}">{v.title}</a></li>'forvinreversed(versions)])}
1178-
<li><a href="https://www.python.org/doc/versions/">{{% trans %}}All versions{{% endtrans %}}</a></li>
1179-
</ul>
1180-
"""
1181-
1182-
template_path=HERE/"templates"/"indexsidebar.html"
1183-
template=Template(template_path.read_text(encoding="UTF-8"))
1184-
rendered_template=template.substitute(DOCS_BY_VERSION=docs_by_version).encode()
1185-
eol_template=template.substitute(DOCS_BY_VERSION="").encode()
1186-
returnrendered_template,eol_template
1182+
defrender_docs_by_version(versions:Versions)->str:
1183+
"""Generate content for _docs_by_version.html."""
1184+
links= [f'<li><a href="{v.url}">{v.title}</a></li>'forvinreversed(versions)]
1185+
return"\n".join(links)
11871186

11881187

11891188
defrender_switchers(versions:Versions,languages:Languages)->bytes:

‎templates/_docs_by_version.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{#
2+
This file is only used in indexsidebar.html, where it is included in the docs
3+
by version list. For non-end-of-life branches, build_docs.py overwrites this
4+
list with the full list of versions.
5+
6+
Keep the following two files synchronised:
7+
* cpython/Doc/tools/templates/_docs_by_version.html
8+
* docsbuild-scripts/templates/_docs_by_version.html
9+
#}
10+
<li><ahref="https://docs.python.org/3/">{% trans %}Stable{% endtrans %}</a></li>
11+
<li><ahref="https://docs.python.org/dev/">{% trans %}In development{% endtrans %}</a></li>

‎templates/indexsidebar.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
{#
2-
Beware, this file is rendered twice:
3-
- First by build_docs.py using string.Template, given '$DOCS_BY_VERSION'.
4-
- Second time by Sphinx, using Jinja.
5-
#}
6-
71
<h3>{% trans %}Download{% endtrans %}</h3>
82
<p><ahref="{{ pathto('download') }}">{% trans %}Download these documents{% endtrans %}</a></p>
9-
$DOCS_BY_VERSION
3+
<h3>{% trans %}Docs by version{% endtrans %}</h3>
4+
<ul>
5+
{# _docs_by_version.html is overwritten by build_docs.py for non-EOL versions #}
6+
{% include "_docs_by_version.html" without context %}
7+
<li><ahref="https://www.python.org/doc/versions/">{% trans %}All versions{% endtrans %}</a></li>
8+
</ul>
109
<h3>{% trans %}Other resources{% endtrans %}</h3>
1110
<ul>
1211
{# XXX: many of these should probably be merged in the main docs #}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp