Skip to content

Commit 037a41e

Browse files
committed
Add version information for the version picker.
1 parent 1f5f067 commit 037a41e

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

build_docs.py

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
[--languages [fr [fr ...]]]
1111
1212
13-
Without any arguments builds docs for all branches configured in the
14-
global BRANCHES value and all languages configured in LANGUAGES,
15-
ignoring the -d flag as it's given in the BRANCHES configuration.
13+
Without any arguments builds docs for all active versions configured in the
14+
global VERSIONS list and all languages configured in the LANGUAGES list,
15+
ignoring the -d flag as it's given in the VERSIONS configuration.
1616
1717
-q selects "quick build", which means to build only HTML.
1818
@@ -58,20 +58,24 @@
5858

5959
VERSION = "19.0"
6060

61-
BRANCHES = [
62-
# version, git branch, isdev
63-
("3.6", "3.6", False),
64-
("3.7", "3.7", False),
65-
("3.8", "3.8", False),
66-
("3.9", "3.9", True),
67-
("3.10", "master", True),
68-
]
69-
70-
61+
# status in {"EOL", "security", "stable", "pre-release", "in development"}
62+
Version = namedtuple("Version", ["name", "branch", "status"])
7163
Language = namedtuple(
7264
"Language", ["tag", "iso639_tag", "name", "in_prod", "sphinxopts"]
7365
)
7466

67+
# EOL and security are not automatically built, no need to remove them
68+
# from the list.
69+
VERSIONS = [
70+
Version("2.7", "2.7", "EOL"),
71+
Version("3.5", "3.5", "security"),
72+
Version("3.6", "3.6", "security"),
73+
Version("3.7", "3.7", "stable"),
74+
Version("3.8", "3.8", "stable"),
75+
Version("3.9", "3.9", "pre-release"),
76+
Version("3.10", "master", "in development"),
77+
]
78+
7579
XELATEX_DEFAULT = (
7680
"-D latex_engine=xelatex",
7781
"-D latex_elements.inputenc=",
@@ -299,32 +303,26 @@ def setup_switchers(html_root):
299303

300304

301305
def build_one(
302-
version,
303-
git_branch,
304-
isdev,
305-
quick,
306-
venv,
307-
build_root,
308-
group,
309-
log_directory,
310-
language: Language,
306+
version, quick, venv, build_root, group, log_directory, language: Language,
311307
):
312308
checkout = os.path.join(
313-
build_root, version, "cpython-{lang}".format(lang=language.tag)
309+
build_root, version.name, "cpython-{lang}".format(lang=language.tag)
310+
)
311+
logging.info(
312+
"Build start for version: %s, language: %s", version.name, language.tag
314313
)
315-
logging.info("Build start for version: %s, language: %s", version, language.tag)
316314
sphinxopts = list(language.sphinxopts)
317315
sphinxopts.extend(["-q"])
318316
if language.tag != "en":
319-
locale_dirs = os.path.join(build_root, version, "locale")
317+
locale_dirs = os.path.join(build_root, version.name, "locale")
320318
locale_clone_dir = os.path.join(locale_dirs, language.iso639_tag, "LC_MESSAGES")
321319
locale_repo = "https://github.com/python/python-docs-{}.git".format(
322320
language.tag
323321
)
324322
git_clone(
325323
locale_repo,
326324
locale_clone_dir,
327-
translation_branch(locale_repo, locale_clone_dir, version),
325+
translation_branch(locale_repo, locale_clone_dir, version.name),
328326
)
329327
sphinxopts.extend(
330328
(
@@ -333,12 +331,16 @@ def build_one(
333331
"-D gettext_compact=0",
334332
)
335333
)
336-
git_clone("https://github.com/python/cpython.git", checkout, git_branch)
334+
git_clone("https://github.com/python/cpython.git", checkout, version.branch)
337335
maketarget = (
338-
"autobuild-" + ("dev" if isdev else "stable") + ("-html" if quick else "")
336+
"autobuild-"
337+
+ ("dev" if version.status == "in development" else "stable")
338+
+ ("-html" if quick else "")
339339
)
340340
logging.info("Running make %s", maketarget)
341-
logname = "cpython-{lang}-{version}.log".format(lang=language.tag, version=version)
341+
logname = "cpython-{lang}-{version}.log".format(
342+
lang=language.tag, version=version.name
343+
)
342344
python = os.path.join(venv, "bin/python")
343345
sphinxbuild = os.path.join(venv, "bin/sphinx-build")
344346
blurb = os.path.join(venv, "bin/blurb")
@@ -368,7 +370,7 @@ def build_one(
368370
)
369371
shell_out(["chgrp", "-R", group, log_directory])
370372
setup_switchers(os.path.join(checkout, "Doc", "build", "html"))
371-
logging.info("Build done for version: %s, language: %s", version, language.tag)
373+
logging.info("Build done for version: %s, language: %s", version.name, language.tag)
372374

373375

374376
def copy_build_to_webroot(
@@ -603,13 +605,17 @@ def main():
603605
setup_logging(args.log_directory)
604606
venv = os.path.join(args.build_root, "venv")
605607
if args.branch:
606-
branches_to_do = [
607-
branch
608-
for branch in BRANCHES
609-
if str(branch[0]) == args.branch or branch[1] == args.branch
608+
versions_to_build = [
609+
version
610+
for version in VERSIONS
611+
if version.name == args.branch or version.branch == args.branch
610612
]
611613
else:
612-
branches_to_do = BRANCHES
614+
versions_to_build = [
615+
version
616+
for version in VERSIONS
617+
if version.status != "EOL" and version.status != "security"
618+
]
613619
if args.languages:
614620
languages = [languages_dict[tag] for tag in args.languages]
615621
else:
@@ -619,17 +625,15 @@ def main():
619625
languages = [
620626
language for language in LANGUAGES if language.tag in DEFAULT_LANGUAGES_SET
621627
]
622-
for version, git_branch, devel in branches_to_do:
628+
for version in versions_to_build:
623629
for language in languages:
624630
if sentry_sdk:
625631
with sentry_sdk.configure_scope() as scope:
626-
scope.set_tag("version", version)
632+
scope.set_tag("version", version.name)
627633
scope.set_tag("language", language.tag)
628634
try:
629635
build_one(
630636
version,
631-
git_branch,
632-
devel,
633637
args.quick,
634638
venv,
635639
args.build_root,
@@ -650,7 +654,7 @@ def main():
650654
logging.error(
651655
"Exception while building %s version %s: %s",
652656
language.tag,
653-
version,
657+
version.name,
654658
err,
655659
)
656660
if sentry_sdk:

0 commit comments

Comments
 (0)