Skip to content

Commit ab65eee

Browse files
committed
Proofreading.
1 parent aa68d68 commit ab65eee

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

build_docs.py

+28-27
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
"""
2424

2525
from argparse import ArgumentParser
26-
from contextlib import suppress
26+
from contextlib import suppress, contextmanager
2727
from dataclasses import dataclass
2828
import filecmp
29-
from itertools import chain, product
3029
import json
3130
import logging
3231
import logging.handlers
@@ -37,10 +36,8 @@
3736
import shutil
3837
import subprocess
3938
import sys
40-
import time
4139
from bisect import bisect_left as bisect
4240
from collections import OrderedDict
43-
from contextlib import contextmanager
4441
from pathlib import Path
4542
from string import Template
4643
from textwrap import indent
@@ -49,11 +46,9 @@
4946
import zc.lockfile
5047
import jinja2
5148
import requests
52-
from tomlkit import parse
49+
import tomlkit
5350

5451

55-
HERE = Path(__file__).resolve().parent
56-
5752
try:
5853
from os import EX_OK, EX_SOFTWARE as EX_FAILURE
5954
except ImportError:
@@ -66,11 +61,7 @@
6661
else:
6762
sentry_sdk.init()
6863

69-
if not hasattr(shlex, "join"):
70-
# Add shlex.join if missing (pre 3.8)
71-
shlex.join = lambda split_command: " ".join(
72-
shlex.quote(arg) for arg in split_command
73-
)
64+
HERE = Path(__file__).resolve().parent
7465

7566

7667
@total_ordering
@@ -98,7 +89,8 @@ def __init__(
9889
status = self.SYNONYMS.get(status, status)
9990
if status not in self.STATUSES:
10091
raise ValueError(
101-
f"Version status expected to be one of: {', '.join(self.STATUSES|set(self.SYNONYMS.keys()))}, got {status!r}."
92+
"Version status expected to be one of: "
93+
f"{', '.join(self.STATUSES|set(self.SYNONYMS.keys()))}, got {status!r}."
10294
)
10395
self.name = name
10496
self.branch_or_tag = branch_or_tag
@@ -167,7 +159,7 @@ def filter(versions, branch=None):
167159
@staticmethod
168160
def current_stable(versions):
169161
"""Find the current stable cPython version."""
170-
return max([v for v in versions if v.status == "stable"], key=Version.as_tuple)
162+
return max((v for v in versions if v.status == "stable"), key=Version.as_tuple)
171163

172164
@staticmethod
173165
def current_dev(versions):
@@ -201,6 +193,7 @@ def setup_indexsidebar(self, versions, dest_path):
201193

202194
@classmethod
203195
def from_json(cls, name, values):
196+
"""Loads a version from devguide's json representation."""
204197
return cls(name, status=values["status"], branch_or_tag=values["branch"])
205198

206199
def __eq__(self, other):
@@ -221,6 +214,7 @@ class Language:
221214

222215
@staticmethod
223216
def filter(languages, language_tags=None):
217+
"""Filter a sequence of languages according to --languages."""
224218
if language_tags:
225219
languages_dict = {language.tag: language for language in languages}
226220
return [languages_dict[tag] for tag in language_tags]
@@ -447,7 +441,7 @@ def build_robots_txt(
447441
robots_file.chmod(0o775)
448442
run(["chgrp", group, robots_file])
449443
if not skip_cache_invalidation:
450-
requests.request("PURGE", "https://docs.python.org/robots.txt")
444+
requests.request("PURGE", "https://docs.python.org/robots.txt", timeout=30)
451445

452446

453447
def build_sitemap(
@@ -703,13 +697,19 @@ def build(self):
703697
if self.language.tag == "ja":
704698
# Since luatex doesn't support \ufffd, replace \ufffd with '?'.
705699
# https://gist.github.com/zr-tex8r/e0931df922f38fbb67634f05dfdaf66b
706-
# Luatex already fixed this issue, so we can remove this once Texlive is updated.
700+
# Luatex already fixed this issue, so we can remove this once Texlive
701+
# is updated.
707702
# (https://github.com/TeX-Live/luatex/commit/eaa95ce0a141eaf7a02)
708-
subprocess.check_output("sed -i s/\N{REPLACEMENT CHARACTER}/?/g "
709-
f"{locale_dirs}/ja/LC_MESSAGES/**/*.po",
710-
shell=True)
711-
subprocess.check_output("sed -i s/\N{REPLACEMENT CHARACTER}/?/g "
712-
f"{self.checkout}/Doc/**/*.rst", shell=True)
703+
subprocess.check_output(
704+
"sed -i s/\N{REPLACEMENT CHARACTER}/?/g "
705+
f"{locale_dirs}/ja/LC_MESSAGES/**/*.po",
706+
shell=True,
707+
)
708+
subprocess.check_output(
709+
"sed -i s/\N{REPLACEMENT CHARACTER}/?/g "
710+
f"{self.checkout}/Doc/**/*.rst",
711+
shell=True,
712+
)
713713

714714
if self.version.status == "EOL":
715715
sphinxopts.append("-D html_context.outdated=1")
@@ -983,7 +983,7 @@ def proofread_canonicals(www_root: Path, skip_cache_invalidation: bool) -> None:
983983
if not skip_cache_invalidation:
984984
url = str(file).replace("/srv/", "https://")
985985
logging.info("Purging %s from CDN", url)
986-
requests.request("PURGE", url)
986+
requests.request("PURGE", url, timeout=30)
987987

988988

989989
def purge_path(www_root: Path, path: Path):
@@ -995,7 +995,9 @@ def purge_path(www_root: Path, path: Path):
995995

996996
def parse_versions_from_devguide():
997997
releases = requests.get(
998-
"https://raw.githubusercontent.com/python/devguide/main/include/release-cycle.json"
998+
"https://raw.githubusercontent.com/"
999+
"python/devguide/main/include/release-cycle.json",
1000+
timeout=30,
9991001
).json()
10001002
return [Version.from_json(name, release) for name, release in releases.items()]
10011003

@@ -1057,14 +1059,13 @@ def main():
10571059
lock = zc.lockfile.LockFile(HERE / "build_docs.lock")
10581060
except zc.lockfile.LockError:
10591061
logging.info("Another builder is running... dying...")
1060-
return False
1062+
return EX_FAILURE
10611063

10621064
try:
1063-
build_docs(args)
1065+
return EX_OK if build_docs(args) else EX_FAILURE
10641066
finally:
10651067
lock.close()
10661068

10671069

10681070
if __name__ == "__main__":
1069-
all_built_successfully = main()
1070-
sys.exit(EX_OK if all_built_successfully else EX_FAILURE)
1071+
sys.exit(main())

0 commit comments

Comments
 (0)