Skip to content

Commit cc85b06

Browse files
authored
Merge pull request #6 from JulienPalard/python_doc_fr
Slowly prepare for french translations.
2 parents fc0b07a + 1993f00 commit cc85b06

File tree

1 file changed

+69
-51
lines changed

1 file changed

+69
-51
lines changed

build_docs.py

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
# Runs a build of the Python docs for various branches.
44
#
5-
# Usages:
5+
# Usage:
66
#
7-
# dailybuild.py [-q]
7+
# build_docs.py [-h] [-d] [-q] [-b 3.6] [-r BUILD_ROOT] [-w WWW_ROOT]
8+
# [--devguide-checkout DEVGUIDE_CHECKOUT]
9+
# [--devguide-target DEVGUIDE_TARGET]
810
#
9-
# without any arguments builds docs for all branches configured in the global
10-
# BRANCHES value. -q selects "quick build", which means to build only HTML.
11+
# Without any arguments builds docs for all branches configured in the
12+
# global BRANCHES value, ignoring the -d flag as it's given in the
13+
# BRANCHES configuration.
1114
#
12-
# dailybuild.py [-q] [-d] <checkout> <target>
15+
# -q selects "quick build", which means to build only HTML.
1316
#
14-
# builds one version, where <checkout> is a HG checkout directory of the Python
15-
# branch to build docs for, and <target> is the directory where the result
16-
# should be placed. If -d is given, the docs are built even if the branch is in
17+
# -d allow the docs to be built even if the branch is in
1718
# development mode (i.e. version contains a, b or c).
1819
#
1920
# This script was originally created and by Georg Brandl in March 2010. Modified
@@ -26,19 +27,13 @@
2627
import sys
2728

2829

29-
BUILDROOT = "/srv/docsbuild"
30-
SPHINXBUILD = os.path.join(BUILDROOT, "environment/bin/sphinx-build")
31-
WWWROOT = "/srv/docs.python.org"
32-
3330
BRANCHES = [
34-
# checkout, target, isdev
35-
(BUILDROOT + "/python35", WWWROOT + "/3.5", False),
36-
(BUILDROOT + "/python36", WWWROOT + "/3.6", True),
37-
(BUILDROOT + "/python37", WWWROOT + "/3.7", True),
38-
(BUILDROOT + "/python27", WWWROOT + "/2.7", False),
31+
# version, isdev
32+
(3.5, False),
33+
(3.6, True),
34+
(3.7, True),
35+
(2.7, False)
3936
]
40-
DEVGUIDE_CHECKOUT = BUILDROOT + "/devguide"
41-
DEVGUIDE_TARGET = WWWROOT + "/devguide"
4237

4338

4439
def _file_unchanged(old, new):
@@ -58,6 +53,7 @@ def _file_unchanged(old, new):
5853
break
5954
return True
6055

56+
6157
def shell_out(cmd):
6258
logging.debug("Running command %r", cmd)
6359
try:
@@ -66,7 +62,10 @@ def shell_out(cmd):
6662
logging.error("command failed with output %r", e.output.decode("utf-8"))
6763
raise
6864

69-
def build_one(checkout, target, isdev, quick):
65+
66+
def build_one(version, isdev, quick, sphinxbuild, build_root, www_root):
67+
checkout = build_root + "/python" + str(version).replace('.', '')
68+
target = www_root + "/" + str(version)
7069
logging.info("Doc autobuild started in %s", checkout)
7170
os.chdir(checkout)
7271

@@ -77,7 +76,7 @@ def build_one(checkout, target, isdev, quick):
7776
logging.info("Running make %s", maketarget)
7877
logname = os.path.basename(checkout) + ".log"
7978
shell_out("cd Doc; make SPHINXBUILD=%s %s >> /var/log/docsbuild/%s 2>&1" %
80-
(SPHINXBUILD, maketarget, logname))
79+
(sphinxbuild, maketarget, logname))
8180

8281
logging.info("Computing changed files")
8382
changed = []
@@ -123,19 +122,49 @@ def build_one(checkout, target, isdev, quick):
123122

124123
logging.info("Finished %s", checkout)
125124

126-
def build_devguide():
125+
126+
def build_devguide(devguide_checkout, devguide_target, sphinxbuild):
127127
logging.info("Building devguide")
128-
shell_out("git -C %s pull" % (DEVGUIDE_CHECKOUT,))
129-
shell_out("%s %s %s" % (SPHINXBUILD, DEVGUIDE_CHECKOUT, DEVGUIDE_TARGET))
130-
shell_out("chmod -R o+r %s" % (DEVGUIDE_TARGET,))
128+
shell_out("git -C %s pull" % (devguide_checkout,))
129+
shell_out("%s %s %s" % (sphinxbuild, devguide_checkout, devguide_target))
130+
shell_out("chmod -R o+r %s" % (devguide_target,))
131131
# TODO Do Fastly invalidation.
132132

133-
def usage():
134-
print("Usage:")
135-
print(" {} (to build all branches)".format(sys.argv[0]))
136-
print("or")
137-
print(" {} [-d] <checkout> <target>".format(sys.argv[0]))
138-
sys.exit(2)
133+
134+
def parse_args():
135+
from argparse import ArgumentParser
136+
parser = ArgumentParser(
137+
description="Runs a build of the Python docs for various branches.")
138+
parser.add_argument(
139+
"-d", "--devel",
140+
action="store_true",
141+
help="Use make autobuild-dev instead of autobuild-stable")
142+
parser.add_argument(
143+
"-q", "--quick",
144+
action="store_true",
145+
help="Make HTML files only (Makefile rules suffixed with -html).")
146+
parser.add_argument(
147+
"-b", "--branch",
148+
metavar=3.6,
149+
type=float,
150+
help="Version to build (defaults to all maintained branches).")
151+
parser.add_argument(
152+
"-r", "--build-root",
153+
help="Path to a directory containing a checkout per branch.",
154+
default="/srv/docsbuild")
155+
parser.add_argument(
156+
"-w", "--www-root",
157+
help="Path where generated files will be copied.",
158+
default="/srv/docs.python.org")
159+
parser.add_argument(
160+
"--devguide-checkout",
161+
help="Path to a devguide checkout.",
162+
default="/srv/docsbuild/devguide")
163+
parser.add_argument(
164+
"--devguide-target",
165+
help="Path where the generated devguide should be copied.",
166+
default="/srv/docs.python.org/devguide")
167+
return parser.parse_args()
139168

140169

141170
if __name__ == '__main__':
@@ -146,27 +175,16 @@ def usage():
146175
logging.basicConfig(format="%(levelname)s:%(asctime)s:%(message)s",
147176
filename="/var/log/docsbuild/docsbuild.log")
148177
logging.root.setLevel(logging.DEBUG)
149-
150-
try:
151-
opts, args = getopt.getopt(sys.argv[1:], "dq")
152-
except getopt.error:
153-
usage()
154-
quick = devel = False
155-
for opt, _ in opts:
156-
if opt == "-q":
157-
quick = True
158-
if opt == "-d":
159-
devel = True
160-
if devel and not args:
161-
usage()
178+
args = parse_args()
179+
sphinxbuild = os.path.join(args.build_root, "environment/bin/sphinx-build")
162180
try:
163-
if args:
164-
if len(args) != 2:
165-
usage()
166-
build_one(os.path.abspath(args[0]), os.path.abspath(args[1]), devel, quick)
181+
if args.branch:
182+
build_one(args.branch, args.devel, args.quick, sphinxbuild,
183+
args.build_root, args.www_root)
167184
else:
168-
for checkout, dest, devel in BRANCHES:
169-
build_one(checkout, dest, devel, quick)
170-
build_devguide()
185+
for version, devel in BRANCHES:
186+
build_one(version, devel, args.quick, sphinxbuild,
187+
args.build_root, args.www_root)
188+
build_devguide(devguide_checkout, devguide_target, sphinxbuild)
171189
except Exception:
172190
logging.exception("docs build raised exception")

0 commit comments

Comments
 (0)