Skip to content

Commit 8dc5d31

Browse files
committed
Merge branch 'build-pdf-ret-val'
2 parents 3906826 + e4824a0 commit 8dc5d31

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

readthedocs/doc_builder/backends/sphinx.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from ..base import BaseBuilder, restoring_chdir
1919
from ..exceptions import BuildEnvironmentError
20+
from ..environments import BuildCommand
2021

2122

2223
log = logging.getLogger(__name__)
@@ -225,6 +226,17 @@ def move(self, **kwargs):
225226
self.run('mv', '-f', from_file, to_file)
226227

227228

229+
class LatexBuildCommand(BuildCommand):
230+
'''Ignore LaTeX exit code if there was file output'''
231+
232+
def run(self):
233+
super(LatexBuildCommand, self).run()
234+
# Force LaTeX exit code to be a little more optimistic. If LaTeX
235+
# reports an output file, let's just assume we're fine.
236+
if PDF_RE.search(self.output):
237+
self.exit_code = 0
238+
239+
228240
class PdfBuilder(BaseSphinx):
229241
type = 'sphinx_pdf'
230242
sphinx_build_dir = '_build/latex'
@@ -268,20 +280,18 @@ def build(self, **kwargs):
268280

269281
pdf_commands = []
270282
for cmd in pdflatex_cmds:
271-
cmd_ret = self.run(*cmd, cwd=latex_cwd, warn_only=True)
272-
# Force LaTeX exit code to be a little more optimistic. If LaTeX
273-
# reports an output file, let's just assume we're fine.
274-
if PDF_RE.search(cmd_ret.output):
275-
cmd_ret.exit_code = 0
283+
cmd_ret = self.build_env.run_command_class(
284+
cls=LatexBuildCommand, cmd=cmd, cwd=latex_cwd, warn_only=True)
276285
pdf_commands.append(cmd_ret)
277286
for cmd in makeindex_cmds:
278-
cmd_ret = self.run(*cmd, cwd=latex_cwd, warn_only=True)
287+
cmd_ret = self.build_env.run_command_class(
288+
cls=LatexBuildCommand, cmd=cmd, cwd=latex_cwd, warn_only=True)
279289
pdf_commands.append(cmd_ret)
280290
for cmd in pdflatex_cmds:
281-
cmd_ret = self.run(*cmd, cwd=latex_cwd, warn_only=True)
291+
cmd_ret = self.build_env.run_command_class(
292+
cls=LatexBuildCommand, cmd=cmd, cwd=latex_cwd, warn_only=True)
282293
pdf_match = PDF_RE.search(cmd_ret.output)
283294
if pdf_match:
284-
cmd_ret.exit_code = 0
285295
self.pdf_file_name = pdf_match.group(1).strip()
286296
pdf_commands.append(cmd_ret)
287297
return all(cmd.successful for cmd in pdf_commands)

readthedocs/doc_builder/environments.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,31 @@ def handle_exception(self, exc_type, exc_value, _):
300300
return False
301301

302302
def run(self, *cmd, **kwargs):
303-
'''Run command from environment
303+
'''Shortcut to run command from environment'''
304+
return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
305+
306+
def run_command_class(self, cls, cmd, **kwargs):
307+
'''Run command from this environment
308+
309+
Use ``cls`` to instantiate a command
304310
305311
:param warn_only: Don't raise an exception on command failure
306312
'''
307313
warn_only = kwargs.pop('warn_only', False)
308314
kwargs['build_env'] = self
309-
cmd = self.command_class(cmd, **kwargs)
310-
self.commands.append(cmd)
311-
cmd.run()
315+
build_cmd = cls(cmd, **kwargs)
316+
self.commands.append(build_cmd)
317+
build_cmd.run()
312318

313319
# Save to database
314320
if self.record:
315-
cmd.save()
321+
build_cmd.save()
316322

317-
if cmd.failed:
318-
msg = u'Command {cmd} failed'.format(cmd=cmd.get_command())
323+
if build_cmd.failed:
324+
msg = u'Command {cmd} failed'.format(cmd=build_cmd.get_command())
319325

320-
if cmd.output:
321-
msg += u':\n{out}'.format(out=cmd.output)
326+
if build_cmd.output:
327+
msg += u':\n{out}'.format(out=build_cmd.output)
322328

323329
if warn_only:
324330
log.warn(LOG_TEMPLATE
@@ -327,7 +333,7 @@ def run(self, *cmd, **kwargs):
327333
msg=msg))
328334
else:
329335
raise BuildEnvironmentWarning(msg)
330-
return cmd
336+
return build_cmd
331337

332338
@property
333339
def successful(self):

0 commit comments

Comments
 (0)