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

Commit21508d6

Browse files
committed
Use a static docs_by_version file
1 parenta2919ec commit21508d6

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

‎build_docs.py

Lines changed: 20 additions & 22 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.")
@@ -1087,7 +1098,7 @@ def build_docs(args: argparse.Namespace) -> int:
10871098
force_build=args.force
10881099
delargs.force
10891100

1090-
isb_content,eol_isb_content=render_indexsidebar(versions)
1101+
docs_by_version_content=render_docs_by_version(versions).encode()
10911102
switchers_content=render_switchers(versions,languages)
10921103

10931104
build_succeeded=set()
@@ -1108,13 +1119,11 @@ def build_docs(args: argparse.Namespace) -> int:
11081119
scope.set_tag("version",version.name)
11091120
scope.set_tag("language",language.tag)
11101121
cpython_repo.update()
1111-
v_isb_content=isb_contentifversion.status!="EOL"elseeol_isb_content
11121122
builder=DocBuilder(
11131123
version,
1114-
versions,
11151124
language,
11161125
cpython_repo,
1117-
v_isb_content,
1126+
docs_by_version_content,
11181127
switchers_content,
11191128
**vars(args),
11201129
)
@@ -1170,21 +1179,10 @@ def parse_languages_from_config() -> Languages:
11701179
returnLanguages.from_json(config["defaults"],config["languages"])
11711180

11721181

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

11891187

11901188
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