Skip to content

Commit de24eb7

Browse files
committed
Proofreading.
1 parent 6fc683c commit de24eb7

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

README.md

-11
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,3 @@ of Sphinx we're using where:
5454
3.12 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0 4.5.0
5555
3.13 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1 6.2.1
5656
========= ===== ===== ===== ===== ===== ===== ===== ===== ======= ===== ===== ======= =======
57-
58-
## The GitHub hook server
59-
60-
`build_docs_server.py` is a simple HTTP server handling GitHub Webhooks
61-
requests to build the doc when needed. It only needs `push` events.
62-
63-
Its logging can be configured by giving a yaml file path to the
64-
`--logging-config` argument.
65-
66-
By default the loglevel is `DEBUG` on `stderr`, the default config can
67-
be found in the code so one can bootstrap a different config from it.

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

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

10641066
try:
1065-
build_docs(args)
1067+
return EX_OK if build_docs(args) else EX_FAILURE
10661068
finally:
10671069
lock.close()
10681070

10691071

10701072
if __name__ == "__main__":
1071-
all_built_successfully = main()
1072-
sys.exit(EX_OK if all_built_successfully else EX_FAILURE)
1073+
sys.exit(main())

0 commit comments

Comments
 (0)