Skip to content

Revert 92a7182af42e26cab01265d2cc06fc7832832689 #10158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from readthedocs.projects.utils import safe_write

from ..base import BaseBuilder
from ..constants import PDF_RE
from ..environments import BuildCommand, DockerBuildCommand
from ..exceptions import BuildUserError
from ..signals import finalize_sphinx_context_data

Expand Down Expand Up @@ -486,6 +488,30 @@ def _post_build(self):
)


class LatexBuildCommand(BuildCommand):

"""Ignore LaTeX exit code if there was file output."""

def run(self):
super().run()
# Force LaTeX exit code to be a little more optimistic. If LaTeX
# reports an output file, let's just assume we're fine.
if PDF_RE.search(self.output):
self.exit_code = 0


class DockerLatexBuildCommand(DockerBuildCommand):

"""Ignore LaTeX exit code if there was file output."""

def run(self):
super().run()
# Force LaTeX exit code to be a little more optimistic. If LaTeX
# reports an output file, let's just assume we're fine.
if PDF_RE.search(self.output):
self.exit_code = 0


class PdfBuilder(BaseSphinx):

"""Builder to generate PDF documentation."""
Expand Down Expand Up @@ -563,6 +589,11 @@ def _build_latexmk(self, cwd):
cwd=self.absolute_host_output_dir,
)

if self.build_env.command_class == DockerBuildCommand:
latex_class = DockerLatexBuildCommand
else:
latex_class = LatexBuildCommand

cmd = [
'latexmk',
'-r',
Expand All @@ -579,18 +610,16 @@ def _build_latexmk(self, cwd):
'-interaction=nonstopmode',
]

try:
cmd_ret = self.run(
*cmd,
cwd=self.absolute_host_output_dir,
)
self.pdf_file_name = f"{self.project.slug}.pdf"
return cmd_ret.successful
cmd_ret = self.build_env.run_command_class(
cls=latex_class,
cmd=cmd,
warn_only=True,
cwd=self.absolute_host_output_dir,
)

# Catch the exception and re-raise it with a specific message
except BuildUserError:
raise BuildUserError(BuildUserError.PDF_COMMAND_FAILED)
return False
self.pdf_file_name = f"{self.project.slug}.pdf"

return cmd_ret.successful

def _post_build(self):
"""Internal post build to cleanup PDF output directory and leave only one .pdf file."""
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/doc_builder/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@

"""Doc build constants."""

import re

import structlog
from django.conf import settings

log = structlog.get_logger(__name__)

PDF_RE = re.compile("Output written on (.*?)")

# Docker
DOCKER_SOCKET = settings.DOCKER_SOCKET
DOCKER_VERSION = settings.DOCKER_VERSION
Expand Down
7 changes: 0 additions & 7 deletions readthedocs/doc_builder/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ class BuildUserError(BuildBaseException):
"Ensure your project is configured to use the output path "
"'$READTHEDOCS_OUTPUT/html' instead."
)
PDF_COMMAND_FAILED = gettext_noop(
"PDF generation failed. "
"The build log below contains information on what errors caused the failure. "
"Our code has recently changed to fail the entire build on PDF errors, "
"where we used to pass the build when a PDF was created. "
"Please contact us if you need help understanding this error."
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Once we re-revert, this would be a great place to add helpful tips on how to get it working again.



class BuildUserSkip(BuildUserError):
Expand Down
7 changes: 7 additions & 0 deletions readthedocs/projects/tests/mockers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def _mock_artifact_builders(self):
"project-slug.pdf",
)

self.patches["builder.pdf.LatexBuildCommand.run"] = mock.patch(
"readthedocs.doc_builder.backends.sphinx.LatexBuildCommand.run",
return_value=mock.MagicMock(output="stdout", successful=True),
)
# self.patches['builder.pdf.LatexBuildCommand.output'] = mock.patch(
# 'readthedocs.doc_builder.backends.sphinx.LatexBuildCommand.output',
# )
self.patches['builder.pdf.glob'] = mock.patch(
'readthedocs.doc_builder.backends.sphinx.glob',
return_value=['output.file'],
Expand Down
12 changes: 0 additions & 12 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,6 @@ def test_build_commands_executed(
bin_path=mock.ANY,
),
mock.call("cat", "latexmkrc", cwd=mock.ANY),
mock.call(
"latexmk",
"-r",
"latexmkrc",
"-pdf",
"-f",
"-dvi-",
"-ps-",
"-jobname=project",
"-interaction=nonstopmode",
cwd=mock.ANY,
),
# NOTE: pdf `mv` commands and others are not here because the
# PDF resulting file is not found in the process (`_post_build`)
mock.call(
Expand Down