Skip to content

Commit 50980c7

Browse files
committed
Build director: run pre/post user commands
1 parent 00f9279 commit 50980c7

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

readthedocs/doc_builder/director.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import shlex
32
from collections import defaultdict
43

54
import structlog
@@ -215,15 +214,13 @@ def checkout(self):
215214
def post_checkout(self):
216215
commands = self.data.config.build.jobs.post_checkout
217216
for command in commands:
218-
# TODO: we could make a helper `self.run(environment, command)`
219-
# that handles split and escape command
220-
self.vcs_environment.run(*shlex.split(command), escape_command=False)
217+
self.run_user_cmd(command)
221218

222219
# System dependencies (``build.apt_packages``)
223220
def pre_system_dependencies(self):
224221
commands = self.data.config.build.jobs.pre_system_dependencies
225222
for command in commands:
226-
self.build_environment.run(*shlex.split(command), escape_command=False)
223+
self.run_user_cmd(command)
227224

228225
# NOTE: `system_dependencies` should not be possible to override by the
229226
# user because it's executed as ``RTD_DOCKER_USER`` (e.g. ``root``) user.
@@ -263,37 +260,37 @@ def system_dependencies(self):
263260
def post_system_dependencies(self):
264261
commands = self.data.config.build.jobs.post_system_dependencies
265262
for command in commands:
266-
self.build_environment.run(*shlex.split(command), escape_command=False)
263+
self.run_user_cmd(command)
267264

268265
# Language environment
269266
def pre_create_environment(self):
270267
commands = self.data.config.build.jobs.pre_create_environment
271268
for command in commands:
272-
self.build_environment.run(*shlex.split(command), escape_command=False)
269+
self.run_user_cmd(command)
273270

274271
def create_environment(self):
275272
commands = [] # self.data.config.build.jobs.create_environment
276273
for command in commands:
277-
self.build_environment.run(*shlex.split(command), escape_command=False)
274+
self.run_user_cmd(command)
278275

279276
if not commands:
280277
self.language_environment.setup_base()
281278

282279
def post_create_environment(self):
283280
commands = self.data.config.build.jobs.post_create_environment
284281
for command in commands:
285-
self.build_environment.run(*shlex.split(command), escape_command=False)
282+
self.run_user_cmd(command)
286283

287284
# Install
288285
def pre_install(self):
289286
commands = self.data.config.build.jobs.pre_install
290287
for command in commands:
291-
self.build_environment.run(*shlex.split(command), escape_command=False)
288+
self.run_user_cmd(command)
292289

293290
def install(self):
294291
commands = [] # self.data.config.build.jobs.install
295292
for command in commands:
296-
self.build_environment.run(*shlex.split(command), escape_command=False)
293+
self.run_user_cmd(command)
297294

298295
if not commands:
299296
self.language_environment.install_core_requirements()
@@ -302,19 +299,19 @@ def install(self):
302299
def post_install(self):
303300
commands = self.data.config.build.jobs.post_install
304301
for command in commands:
305-
self.build_environment.run(*shlex.split(command), escape_command=False)
302+
self.run_user_cmd(command)
306303

307304
# Build
308305
def pre_build(self):
309306
commands = self.data.config.build.jobs.pre_build
310307
for command in commands:
311-
self.build_environment.run(*shlex.split(command), escape_command=False)
308+
self.run_user_cmd(command)
312309

313310
def build_html(self):
314311
commands = [] # self.data.config.build.jobs.build.html
315312
if commands:
316313
for command in commands:
317-
self.build_environment.run(*shlex.split(command), escape_command=False)
314+
self.run_user_cmd(command)
318315
return True
319316

320317
return self.build_docs_class(self.data.config.doctype)
@@ -326,7 +323,7 @@ def build_pdf(self):
326323
commands = [] # self.data.config.build.jobs.build.pdf
327324
if commands:
328325
for command in commands:
329-
self.build_environment.run(*shlex.split(command), escape_command=False)
326+
self.run_user_cmd(command)
330327
return True
331328

332329
# Mkdocs has no pdf generation currently.
@@ -345,7 +342,7 @@ def build_htmlzip(self):
345342
commands = [] # self.data.config.build.jobs.build.htmlzip
346343
if commands:
347344
for command in commands:
348-
self.build_environment.run(*shlex.split(command), escape_command=False)
345+
self.run_user_cmd(command)
349346
return True
350347

351348
# We don't generate a zip for mkdocs currently.
@@ -360,7 +357,7 @@ def build_epub(self):
360357
commands = [] # self.data.config.build.jobs.build.epub
361358
if commands:
362359
for command in commands:
363-
self.build_environment.run(*shlex.split(command), escape_command=False)
360+
self.run_user_cmd(command)
364361
return True
365362

366363
# Mkdocs has no epub generation currently.
@@ -371,12 +368,16 @@ def build_epub(self):
371368
def post_build(self):
372369
commands = self.data.config.build.jobs.post_build
373370
for command in commands:
374-
self.build_environment.run(*shlex.split(command), escape_command=False)
371+
self.run_user_cmd(command)
375372

376373
# Helpers
377374
#
378375
# TODO: move somewhere or change names to make them private or something to
379376
# 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+
380381
def build_docs_class(self, builder_class):
381382
"""
382383
Build docs with additional doc backends.

0 commit comments

Comments
 (0)