|
48 | 48 | import sys
|
49 | 49 | from datetime import datetime
|
50 | 50 |
|
| 51 | +HERE = Path(__file__).resolve().parent |
51 | 52 |
|
52 | 53 | try:
|
53 | 54 | import sentry_sdk
|
|
58 | 59 |
|
59 | 60 | VERSION = "19.0"
|
60 | 61 |
|
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 | + |
63 | 84 | Language = namedtuple(
|
64 | 85 | "Language", ["tag", "iso639_tag", "name", "in_prod", "sphinxopts"]
|
65 | 86 | )
|
66 | 87 |
|
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 |
68 | 89 | # from the list.
|
69 | 90 | VERSIONS = [
|
70 | 91 | 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"), |
73 | 94 | Version("3.7", "3.7", "stable"),
|
74 | 95 | Version("3.8", "3.8", "stable"),
|
75 | 96 | Version("3.9", "3.9", "pre-release"),
|
@@ -277,12 +298,29 @@ def picker_label(version):
|
277 | 298 | return version.name
|
278 | 299 |
|
279 | 300 |
|
| 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 | + |
280 | 318 | def setup_switchers(html_root):
|
281 | 319 | """Setup cross-links between cpython versions:
|
282 | 320 | - Cross-link various languages in a language switcher
|
283 | 321 | - Cross-link various versions in a version switcher
|
284 | 322 | """
|
285 |
| - with open("switchers.js") as switchers_template_file: |
| 323 | + with open(HERE / "templates" / "switchers.js") as switchers_template_file: |
286 | 324 | with open(
|
287 | 325 | os.path.join(html_root, "_static", "switchers.js"), "w"
|
288 | 326 | ) as switchers_file:
|
@@ -381,6 +419,9 @@ def build_one(
|
381 | 419 | os.path.join(checkout, "Doc", "Makefile"),
|
382 | 420 | ]
|
383 | 421 | )
|
| 422 | + setup_indexsidebar( |
| 423 | + os.path.join(checkout, "Doc", "tools", "templates", "indexsidebar.html") |
| 424 | + ) |
384 | 425 | shell_out(
|
385 | 426 | [
|
386 | 427 | "make",
|
@@ -648,7 +689,7 @@ def main():
|
648 | 689 | versions_to_build = [
|
649 | 690 | version
|
650 | 691 | for version in VERSIONS
|
651 |
| - if version.status != "EOL" and version.status != "security" |
| 692 | + if version.status != "EOL" and version.status != "security-fixes" |
652 | 693 | ]
|
653 | 694 | if args.languages:
|
654 | 695 | languages = [languages_dict[tag] for tag in args.languages]
|
@@ -685,11 +726,10 @@ def main():
|
685 | 726 | args.www_root,
|
686 | 727 | )
|
687 | 728 | 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", |
690 | 731 | language.tag,
|
691 | 732 | version.name,
|
692 |
| - err, |
693 | 733 | )
|
694 | 734 | if sentry_sdk:
|
695 | 735 | sentry_sdk.capture_exception(err)
|
|
0 commit comments