Skip to content

Commit f97e6d1

Browse files
committed
Template the indexsidebar too.
1 parent 3ead1ba commit f97e6d1

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

build_docs.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import sys
4949
from datetime import datetime
5050

51+
HERE = Path(__file__).resolve().parent
5152

5253
try:
5354
import sentry_sdk
@@ -58,18 +59,38 @@
5859

5960
VERSION = "19.0"
6061

61-
# status in {"EOL", "security", "stable", "pre-release", "in development"}
62-
Version = namedtuple("Version", ["name", "branch", "status"])
62+
63+
class Version:
64+
STATUSES = {"EOL", "security-fixes", "stable", "pre-release", "in development"}
65+
66+
def __init__(self, name, branch, status):
67+
if status not in self.STATUSES:
68+
raise ValueError(
69+
"Version status expected to be in {}".format(", ".join(self.STATUSES))
70+
)
71+
self.name = name
72+
self.branch = branch
73+
self.status = status
74+
75+
@property
76+
def url(self):
77+
return "https://docs.python.org/{}/".format(self.name)
78+
79+
@property
80+
def title(self):
81+
return "Python {} ({})".format(self.name, self.status)
82+
83+
6384
Language = namedtuple(
6485
"Language", ["tag", "iso639_tag", "name", "in_prod", "sphinxopts"]
6586
)
6687

67-
# EOL and security are not automatically built, no need to remove them
88+
# EOL and security-fixes are not automatically built, no need to remove them
6889
# from the list.
6990
VERSIONS = [
7091
Version("2.7", "2.7", "EOL"),
71-
Version("3.5", "3.5", "security"),
72-
Version("3.6", "3.6", "security"),
92+
Version("3.5", "3.5", "security-fixes"),
93+
Version("3.6", "3.6", "security-fixes"),
7394
Version("3.7", "3.7", "stable"),
7495
Version("3.8", "3.8", "stable"),
7596
Version("3.9", "3.9", "pre-release"),
@@ -277,12 +298,29 @@ def picker_label(version):
277298
return version.name
278299

279300

301+
def setup_indexsidebar(dest_path):
302+
versions_li = []
303+
for version in sorted(
304+
VERSIONS, key=lambda v: version_to_tuple(v.name), reverse=True,
305+
):
306+
versions_li.append(
307+
'<li><a href="{}">{}</a></li>'.format(version.url, version.title)
308+
)
309+
310+
with open(HERE / "templates" / "indexsidebar.html") as sidebar_template_file:
311+
with open(dest_path, "w") as sidebar_file:
312+
template = Template(sidebar_template_file.read())
313+
sidebar_file.write(
314+
template.safe_substitute({"VERSIONS": "\n".join(versions_li)})
315+
)
316+
317+
280318
def setup_switchers(html_root):
281319
"""Setup cross-links between cpython versions:
282320
- Cross-link various languages in a language switcher
283321
- Cross-link various versions in a version switcher
284322
"""
285-
with open("switchers.js") as switchers_template_file:
323+
with open(HERE / "templates" / "switchers.js") as switchers_template_file:
286324
with open(
287325
os.path.join(html_root, "_static", "switchers.js"), "w"
288326
) as switchers_file:
@@ -381,6 +419,9 @@ def build_one(
381419
os.path.join(checkout, "Doc", "Makefile"),
382420
]
383421
)
422+
setup_indexsidebar(
423+
os.path.join(checkout, "Doc", "tools", "templates", "indexsidebar.html")
424+
)
384425
shell_out(
385426
[
386427
"make",
@@ -648,7 +689,7 @@ def main():
648689
versions_to_build = [
649690
version
650691
for version in VERSIONS
651-
if version.status != "EOL" and version.status != "security"
692+
if version.status != "EOL" and version.status != "security-fixes"
652693
]
653694
if args.languages:
654695
languages = [languages_dict[tag] for tag in args.languages]
@@ -685,11 +726,10 @@ def main():
685726
args.www_root,
686727
)
687728
except Exception as err:
688-
logging.error(
689-
"Exception while building %s version %s: %s",
729+
logging.exception(
730+
"Exception while building %s version %s",
690731
language.tag,
691732
version.name,
692-
err,
693733
)
694734
if sentry_sdk:
695735
sentry_sdk.capture_exception(err)

indexsidebar.html renamed to templates/indexsidebar.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ <h3>{% trans %}Download{% endtrans %}</h3>
22
<p><a href="{{ pathto('download') }}">{% trans %}Download these documents{% endtrans %}</a></p>
33
<h3>{% trans %}Docs by version{% endtrans %}</h3>
44
<ul>
5-
<li><a href="https://docs.python.org/3.10/">{% trans %}Python 3.10 (in development){% endtrans %}</a></li>
6-
<li><a href="https://docs.python.org/3.9/">{% trans %}Python 3.9 (pre-release){% endtrans %}</a></li>
7-
<li><a href="https://docs.python.org/3.8/">{% trans %}Python 3.8 (stable){% endtrans %}</a></li>
8-
<li><a href="https://docs.python.org/3.7/">{% trans %}Python 3.7 (stable){% endtrans %}</a></li>
9-
<li><a href="https://docs.python.org/3.6/">{% trans %}Python 3.6 (security-fixes){% endtrans %}</a></li>
10-
<li><a href="https://docs.python.org/3.5/">{% trans %}Python 3.5 (security-fixes){% endtrans %}</a></li>
11-
<li><a href="https://docs.python.org/2.7/">{% trans %}Python 2.7 (EOL){% endtrans %}</a></li>
5+
$VERSIONS
126
<li><a href="https://www.python.org/doc/versions/">{% trans %}All versions{% endtrans %}</a></li>
137
</ul>
148

File renamed without changes.

0 commit comments

Comments
 (0)