Skip to content

Commit a5ae9bd

Browse files
committed
Revert 92a7182
Reverts #10113
1 parent d7bf7f1 commit a5ae9bd

File tree

5 files changed

+50
-30
lines changed

5 files changed

+50
-30
lines changed

readthedocs/doc_builder/backends/sphinx.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from readthedocs.projects.utils import safe_write
2727

2828
from ..base import BaseBuilder
29+
from ..constants import PDF_RE
30+
from ..environments import BuildCommand, DockerBuildCommand
2931
from ..exceptions import BuildUserError
3032
from ..signals import finalize_sphinx_context_data
3133

@@ -486,6 +488,30 @@ def _post_build(self):
486488
)
487489

488490

491+
class LatexBuildCommand(BuildCommand):
492+
493+
"""Ignore LaTeX exit code if there was file output."""
494+
495+
def run(self):
496+
super().run()
497+
# Force LaTeX exit code to be a little more optimistic. If LaTeX
498+
# reports an output file, let's just assume we're fine.
499+
if PDF_RE.search(self.output):
500+
self.exit_code = 0
501+
502+
503+
class DockerLatexBuildCommand(DockerBuildCommand):
504+
505+
"""Ignore LaTeX exit code if there was file output."""
506+
507+
def run(self):
508+
super().run()
509+
# Force LaTeX exit code to be a little more optimistic. If LaTeX
510+
# reports an output file, let's just assume we're fine.
511+
if PDF_RE.search(self.output):
512+
self.exit_code = 0
513+
514+
489515
class PdfBuilder(BaseSphinx):
490516

491517
"""Builder to generate PDF documentation."""
@@ -563,6 +589,11 @@ def _build_latexmk(self, cwd):
563589
cwd=self.absolute_host_output_dir,
564590
)
565591

592+
if self.build_env.command_class == DockerBuildCommand:
593+
latex_class = DockerLatexBuildCommand
594+
else:
595+
latex_class = LatexBuildCommand
596+
566597
cmd = [
567598
'latexmk',
568599
'-r',
@@ -579,18 +610,16 @@ def _build_latexmk(self, cwd):
579610
'-interaction=nonstopmode',
580611
]
581612

582-
try:
583-
cmd_ret = self.run(
584-
*cmd,
585-
cwd=self.absolute_host_output_dir,
586-
)
587-
self.pdf_file_name = f"{self.project.slug}.pdf"
588-
return cmd_ret.successful
613+
cmd_ret = self.build_env.run_command_class(
614+
cls=latex_class,
615+
cmd=cmd,
616+
warn_only=True,
617+
cwd=self.absolute_host_output_dir,
618+
)
589619

590-
# Catch the exception and re-raise it with a specific message
591-
except BuildUserError:
592-
raise BuildUserError(BuildUserError.PDF_COMMAND_FAILED)
593-
return False
620+
self.pdf_file_name = f"{self.project.slug}.pdf"
621+
622+
return cmd_ret.successful
594623

595624
def _post_build(self):
596625
"""Internal post build to cleanup PDF output directory and leave only one .pdf file."""

readthedocs/doc_builder/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11

22
"""Doc build constants."""
33

4+
import re
45

56
import structlog
67
from django.conf import settings
78

89
log = structlog.get_logger(__name__)
910

11+
PDF_RE = re.compile("Output written on (.*?)")
12+
1013
# Docker
1114
DOCKER_SOCKET = settings.DOCKER_SOCKET
1215
DOCKER_VERSION = settings.DOCKER_VERSION

readthedocs/doc_builder/exceptions.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ class BuildUserError(BuildBaseException):
5757
"Ensure your project is configured to use the output path "
5858
"'$READTHEDOCS_OUTPUT/html' instead."
5959
)
60-
PDF_COMMAND_FAILED = gettext_noop(
61-
"PDF generation failed. "
62-
"The build log below contains information on what errors caused the failure."
63-
"Our code has recently changed to fail the entire build on PDF errors, "
64-
"where we used to pass the build when a PDF was created."
65-
"Please contact us if you need help understanding this error."
66-
)
6760

6861

6962
class BuildUserSkip(BuildUserError):

readthedocs/projects/tests/mockers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ def _mock_artifact_builders(self):
5858
"project-slug.pdf",
5959
)
6060

61+
self.patches["builder.pdf.LatexBuildCommand.run"] = mock.patch(
62+
"readthedocs.doc_builder.backends.sphinx.LatexBuildCommand.run",
63+
return_value=mock.MagicMock(output="stdout", successful=True),
64+
)
65+
# self.patches['builder.pdf.LatexBuildCommand.output'] = mock.patch(
66+
# 'readthedocs.doc_builder.backends.sphinx.LatexBuildCommand.output',
67+
# )
6168
self.patches['builder.pdf.glob'] = mock.patch(
6269
'readthedocs.doc_builder.backends.sphinx.glob',
6370
return_value=['output.file'],

readthedocs/projects/tests/test_build_tasks.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -723,18 +723,6 @@ def test_build_commands_executed(
723723
bin_path=mock.ANY,
724724
),
725725
mock.call("cat", "latexmkrc", cwd=mock.ANY),
726-
mock.call(
727-
"latexmk",
728-
"-r",
729-
"latexmkrc",
730-
"-pdf",
731-
"-f",
732-
"-dvi-",
733-
"-ps-",
734-
"-jobname=project",
735-
"-interaction=nonstopmode",
736-
cwd=mock.ANY,
737-
),
738726
# NOTE: pdf `mv` commands and others are not here because the
739727
# PDF resulting file is not found in the process (`_post_build`)
740728
mock.call(

0 commit comments

Comments
 (0)