2
2
3
3
# Runs a build of the Python docs for various branches.
4
4
#
5
- # Usages :
5
+ # Usage :
6
6
#
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]
8
10
#
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.
11
14
#
12
- # dailybuild.py [-q] [-d] <checkout> <target>
15
+ # -q selects "quick build", which means to build only HTML.
13
16
#
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
17
18
# development mode (i.e. version contains a, b or c).
18
19
#
19
20
# This script was originally created and by Georg Brandl in March 2010. Modified
26
27
import sys
27
28
28
29
29
- BUILDROOT = "/srv/docsbuild"
30
- SPHINXBUILD = os .path .join (BUILDROOT , "environment/bin/sphinx-build" )
31
- WWWROOT = "/srv/docs.python.org"
32
-
33
30
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 )
39
36
]
40
- DEVGUIDE_CHECKOUT = BUILDROOT + "/devguide"
41
- DEVGUIDE_TARGET = WWWROOT + "/devguide"
42
37
43
38
44
39
def _file_unchanged (old , new ):
@@ -58,6 +53,7 @@ def _file_unchanged(old, new):
58
53
break
59
54
return True
60
55
56
+
61
57
def shell_out (cmd ):
62
58
logging .debug ("Running command %r" , cmd )
63
59
try :
@@ -66,7 +62,10 @@ def shell_out(cmd):
66
62
logging .error ("command failed with output %r" , e .output .decode ("utf-8" ))
67
63
raise
68
64
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 )
70
69
logging .info ("Doc autobuild started in %s" , checkout )
71
70
os .chdir (checkout )
72
71
@@ -77,7 +76,7 @@ def build_one(checkout, target, isdev, quick):
77
76
logging .info ("Running make %s" , maketarget )
78
77
logname = os .path .basename (checkout ) + ".log"
79
78
shell_out ("cd Doc; make SPHINXBUILD=%s %s >> /var/log/docsbuild/%s 2>&1" %
80
- (SPHINXBUILD , maketarget , logname ))
79
+ (sphinxbuild , maketarget , logname ))
81
80
82
81
logging .info ("Computing changed files" )
83
82
changed = []
@@ -123,19 +122,49 @@ def build_one(checkout, target, isdev, quick):
123
122
124
123
logging .info ("Finished %s" , checkout )
125
124
126
- def build_devguide ():
125
+
126
+ def build_devguide (devguide_checkout , devguide_target , sphinxbuild ):
127
127
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 ,))
131
131
# TODO Do Fastly invalidation.
132
132
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 ()
139
168
140
169
141
170
if __name__ == '__main__' :
@@ -146,27 +175,16 @@ def usage():
146
175
logging .basicConfig (format = "%(levelname)s:%(asctime)s:%(message)s" ,
147
176
filename = "/var/log/docsbuild/docsbuild.log" )
148
177
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" )
162
180
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 )
167
184
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 )
171
189
except Exception :
172
190
logging .exception ("docs build raised exception" )
0 commit comments