@@ -89,9 +89,18 @@ def setup_vcs(self):
89
89
version_type = self .data .version .type ,
90
90
)
91
91
92
- self .pre_checkout ()
92
+ # We can't do too much on ``pre_checkout`` because we haven't
93
+ # cloned the repository yet and we don't know what the user wrote
94
+ # in the `.readthedocs.yaml` yet.
95
+ #
96
+ # We could implement something different in the future if we download
97
+ # the `.readthedocs.yaml` file without cloning.
98
+ # See https://github.com/readthedocs/readthedocs.org/issues/8935
99
+ #
100
+ # self.run_build_job('pre_checkout')
101
+
93
102
self .checkout ()
94
- self .post_checkout ( )
103
+ self .run_build_job ( "post_checkout" )
95
104
96
105
commit = self .data .build_commit or self .vcs_repository .commit
97
106
if commit :
@@ -139,21 +148,21 @@ def setup_environment(self):
139
148
environment = self .build_environment ,
140
149
)
141
150
142
- self .pre_system_dependencies ( )
151
+ self .run_build_job ( "pre_system_dependencies" )
143
152
self .system_dependencies ()
144
- self .post_system_dependencies ( )
153
+ self .run_build_job ( "post_system_dependencies" )
145
154
146
155
# Install all ``build.tools`` specified by the user
147
156
if self .data .config .using_build_tools :
148
157
self .language_environment .install_build_tools ()
149
158
150
- self .pre_create_environment ( )
159
+ self .run_build_job ( "pre_create_environment" )
151
160
self .create_environment ()
152
- self .post_create_environment ( )
161
+ self .run_build_job ( "post_create_environment" )
153
162
154
- self .pre_install ( )
163
+ self .run_build_job ( "pre_install" )
155
164
self .install ()
156
- self .post_install ( )
165
+ self .run_build_job ( "post_install" )
157
166
158
167
# TODO: remove this and document how to do it on `build.jobs.post_install`
159
168
if self .data .project .has_feature (Feature .LIST_PACKAGES_INSTALLED_ENV ):
@@ -169,7 +178,7 @@ def build(self):
169
178
4. build ePub
170
179
"""
171
180
172
- self .pre_build ( )
181
+ self .run_build_job ( "pre_build" )
173
182
174
183
self .data .outcomes = defaultdict (lambda : False )
175
184
self .data .outcomes ["html" ] = self .build_html ()
@@ -178,23 +187,13 @@ def build(self):
178
187
self .data .outcomes ["pdf" ] = self .build_pdf ()
179
188
self .data .outcomes ["epub" ] = self .build_epub ()
180
189
181
- self .post_build ( )
190
+ self .run_build_job ( "post_build" )
182
191
183
192
after_build .send (
184
193
sender = self .data .version ,
185
194
)
186
195
187
196
# VCS checkout
188
- def pre_checkout (self ):
189
- # We can't do too much here because we haven't cloned the repository
190
- # yet and we don't know what the user wrote in the `.readthedocs.yaml`
191
- # yet.
192
- #
193
- # We could implement something different in the future if we download
194
- # the `.readthedocs.yaml` file without cloning.
195
- # See https://github.com/readthedocs/readthedocs.org/issues/8935
196
- pass
197
-
198
197
def checkout (self ):
199
198
log .info (
200
199
"Clonning repository." ,
@@ -211,17 +210,7 @@ def checkout(self):
211
210
if self .vcs_repository .supports_submodules :
212
211
self .vcs_repository .update_submodules (self .data .config )
213
212
214
- def post_checkout (self ):
215
- commands = self .data .config .build .jobs .post_checkout
216
- for command in commands :
217
- self .run_user_cmd (command )
218
-
219
213
# System dependencies (``build.apt_packages``)
220
- def pre_system_dependencies (self ):
221
- commands = self .data .config .build .jobs .pre_system_dependencies
222
- for command in commands :
223
- self .run_user_cmd (command )
224
-
225
214
# NOTE: `system_dependencies` should not be possible to override by the
226
215
# user because it's executed as ``RTD_DOCKER_USER`` (e.g. ``root``) user.
227
216
def system_dependencies (self ):
@@ -257,75 +246,23 @@ def system_dependencies(self):
257
246
user = settings .RTD_DOCKER_SUPER_USER ,
258
247
)
259
248
260
- def post_system_dependencies (self ):
261
- commands = self .data .config .build .jobs .post_system_dependencies
262
- for command in commands :
263
- self .run_user_cmd (command )
264
-
265
249
# Language environment
266
- def pre_create_environment (self ):
267
- commands = self .data .config .build .jobs .pre_create_environment
268
- for command in commands :
269
- self .run_user_cmd (command )
270
-
271
250
def create_environment (self ):
272
- commands = [] # self.data.config.build.jobs.create_environment
273
- for command in commands :
274
- self .run_user_cmd (command )
275
-
276
- if not commands :
277
- self .language_environment .setup_base ()
278
-
279
- def post_create_environment (self ):
280
- commands = self .data .config .build .jobs .post_create_environment
281
- for command in commands :
282
- self .run_user_cmd (command )
251
+ self .language_environment .setup_base ()
283
252
284
253
# Install
285
- def pre_install (self ):
286
- commands = self .data .config .build .jobs .pre_install
287
- for command in commands :
288
- self .run_user_cmd (command )
289
-
290
254
def install (self ):
291
- commands = [] # self.data.config.build.jobs.install
292
- for command in commands :
293
- self .run_user_cmd (command )
294
-
295
- if not commands :
296
- self .language_environment .install_core_requirements ()
297
- self .language_environment .install_requirements ()
298
-
299
- def post_install (self ):
300
- commands = self .data .config .build .jobs .post_install
301
- for command in commands :
302
- self .run_user_cmd (command )
255
+ self .language_environment .install_core_requirements ()
256
+ self .language_environment .install_requirements ()
303
257
304
258
# Build
305
- def pre_build (self ):
306
- commands = self .data .config .build .jobs .pre_build
307
- for command in commands :
308
- self .run_user_cmd (command )
309
-
310
259
def build_html (self ):
311
- commands = [] # self.data.config.build.jobs.build.html
312
- if commands :
313
- for command in commands :
314
- self .run_user_cmd (command )
315
- return True
316
-
317
260
return self .build_docs_class (self .data .config .doctype )
318
261
319
262
def build_pdf (self ):
320
263
if "pdf" not in self .data .config .formats or self .data .version .type == EXTERNAL :
321
264
return False
322
265
323
- commands = [] # self.data.config.build.jobs.build.pdf
324
- if commands :
325
- for command in commands :
326
- self .run_user_cmd (command )
327
- return True
328
-
329
266
# Mkdocs has no pdf generation currently.
330
267
if self .is_type_sphinx ():
331
268
return self .build_docs_class ("sphinx_pdf" )
@@ -339,12 +276,6 @@ def build_htmlzip(self):
339
276
):
340
277
return False
341
278
342
- commands = [] # self.data.config.build.jobs.build.htmlzip
343
- if commands :
344
- for command in commands :
345
- self .run_user_cmd (command )
346
- return True
347
-
348
279
# We don't generate a zip for mkdocs currently.
349
280
if self .is_type_sphinx ():
350
281
return self .build_docs_class ("sphinx_singlehtmllocalmedia" )
@@ -354,30 +285,30 @@ def build_epub(self):
354
285
if "epub" not in self .data .config .formats or self .data .version .type == EXTERNAL :
355
286
return False
356
287
357
- commands = [] # self.data.config.build.jobs.build.epub
358
- if commands :
359
- for command in commands :
360
- self .run_user_cmd (command )
361
- return True
362
-
363
288
# Mkdocs has no epub generation currently.
364
289
if self .is_type_sphinx ():
365
290
return self .build_docs_class ("sphinx_epub" )
366
291
return False
367
292
368
- def post_build (self ):
369
- commands = self .data .config .build .jobs .post_build
293
+ def run_build_job (self , job ):
294
+ if (
295
+ getattr (self .data .config .build , "jobs" , None ) is None
296
+ or getattr (self .data .config .build .jobs , job , None ) is None
297
+ ):
298
+ return
299
+
300
+ cwd = self .data .project .checkout_path (self .data .version .slug )
301
+ commands = getattr (self .data .config .build .jobs , job , [])
370
302
for command in commands :
371
- self .run_user_cmd (command )
303
+ environment = self .vcs_environment
304
+ if job not in ("pre_checkout" , "post_checkout" ):
305
+ environment = self .build_environment
306
+ environment .run (* command .split (), escape_command = False , cwd = cwd )
372
307
373
308
# Helpers
374
309
#
375
310
# TODO: move somewhere or change names to make them private or something to
376
311
# easily differentiate them from the normal flow.
377
- def run_user_cmd (self , cmd ):
378
- cwd = self .data .project .checkout_path (self .data .version .slug )
379
- self .build_environment .run (cmd .split (), escape_command = False , cwd = cwd )
380
-
381
312
def build_docs_class (self , builder_class ):
382
313
"""
383
314
Build docs with additional doc backends.
0 commit comments