Skip to content

Commit

Permalink
Merge branch 'master' into issue-12045/partial-search-ngrams
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison authored Jul 16, 2024
2 parents 1271159 + 8b4709d commit ce424ea
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 14 deletions.
15 changes: 15 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
Release 7.4.5 (released Jul 16, 2024)
=====================================

Bugs fixed
----------

* #12593, #12600: Revert coercing the type of selected :confval:`html_sidebars`
values to a list.
Log an error message when string values are detected.
Patch by Adam Turner.
* #12594: LaTeX: since 7.4.0, :rst:dir:`seealso` and other "light" admonitions
now break PDF builds if they contain a :dudir:`figure` directive; and also
if they are contained in a table cell (rendered by ``tabulary``).
Patch by Jean-François B.

Release 7.4.4 (released Jul 15, 2024)
=====================================

Expand Down
4 changes: 2 additions & 2 deletions sphinx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""The Sphinx documentation toolchain."""

__version__ = '7.4.4'
__version__ = '7.4.5'
__display_version__ = __version__ # used for command line version

# Keep this file executable as-is in Python 3!
Expand All @@ -27,7 +27,7 @@
#:
#: .. versionadded:: 1.2
#: Before version 1.2, check the string ``sphinx.__version__``.
version_info = (7, 4, 4, 'final', 0)
version_info = (7, 4, 5, 'final', 0)

package_dir = os.path.abspath(os.path.dirname(__file__))

Expand Down
29 changes: 24 additions & 5 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,11 +982,10 @@ def has_wildcard(pattern: str) -> bool:
matched = pattern
sidebars = pat_sidebars

if len(sidebars) == 0:
# keep defaults
pass

ctx['sidebars'] = list(sidebars)
# See error_on_html_sidebars_string_values.
# Replace with simple list coercion in Sphinx 8.0
# xref: RemovedInSphinx80Warning
ctx['sidebars'] = sidebars

# --------- these are overwritten by the serialization builder

Expand Down Expand Up @@ -1287,6 +1286,25 @@ def validate_html_favicon(app: Sphinx, config: Config) -> None:
config.html_favicon = None


def error_on_html_sidebars_string_values(app: Sphinx, config: Config) -> None:
"""Support removed in Sphinx 2."""
errors = {}
for pattern, pat_sidebars in config.html_sidebars.items():
if isinstance(pat_sidebars, str):
errors[pattern] = [pat_sidebars]
if not errors:
return
msg = __("Values in 'html_sidebars' must be a list of strings. "
"At least one pattern has a string value: %s. "
"Change to `html_sidebars = %r`.")
bad_patterns = ', '.join(map(repr, errors))
fixed = config.html_sidebars | errors
logger.error(msg, bad_patterns, fixed)
# Enable hard error in next major version.
# xref: RemovedInSphinx80Warning
# raise ConfigError(msg % (bad_patterns, fixed))


def error_on_html_4(_app: Sphinx, config: Config) -> None:
"""Error on HTML 4."""
if config.html4_writer:
Expand Down Expand Up @@ -1357,6 +1375,7 @@ def setup(app: Sphinx) -> ExtensionMetadata:
app.connect('config-inited', validate_html_static_path, priority=800)
app.connect('config-inited', validate_html_logo, priority=800)
app.connect('config-inited', validate_html_favicon, priority=800)
app.connect('config-inited', error_on_html_sidebars_string_values, priority=800)
app.connect('config-inited', error_on_html_4, priority=800)
app.connect('builder-inited', validate_math_renderer)
app.connect('html-page-context', setup_resource_paths)
Expand Down
4 changes: 4 additions & 0 deletions sphinx/ext/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,17 @@ def latex_visit_todo_node(self: LaTeXTranslator, node: todo_node) -> None:
title_node = cast(nodes.title, node[0])
title = texescape.escape(title_node.astext(), self.config.latex_engine)
self.body.append('%s:}' % title)
self.no_latex_floats += 1
if self.table:
self.table.has_problematic = True
node.pop(0)
else:
raise nodes.SkipNode


def latex_depart_todo_node(self: LaTeXTranslator, node: todo_node) -> None:
self.body.append('\\end{sphinxtodo}\n')
self.no_latex_floats -= 1


def setup(app: Sphinx) -> ExtensionMetadata:
Expand Down
5 changes: 4 additions & 1 deletion sphinx/texinputs/sphinxlatextables.sty
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
\vbox{}% get correct baseline from above
\LTpre\z@skip\LTpost\z@skip % set to zero longtable's own skips
\edef\sphinxbaselineskip{\dimexpr\the\dimexpr\baselineskip\relax\relax}%
\spx@inframedtrue % message to sphinxheavybox
}%
% Compatibility with caption package
\def\sphinxthelongtablecaptionisattop{%
Expand All @@ -121,7 +122,9 @@
\def\sphinxatlongtableend{\@nobreakfalse % latex3/latex2e#173
\prevdepth\z@\vskip\sphinxtablepost\relax}%
% B. Table with tabular or tabulary
\def\sphinxattablestart{\par\vskip\dimexpr\sphinxtablepre\relax}%
\def\sphinxattablestart{\par\vskip\dimexpr\sphinxtablepre\relax
\spx@inframedtrue % message to sphinxheavybox
}%
\let\sphinxattableend\sphinxatlongtableend
% This is used by tabular and tabulary templates
\newcommand*\sphinxcapstartof[1]{%
Expand Down
11 changes: 11 additions & 0 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ def __init__(self, document: nodes.document, builder: LaTeXBuilder,
self.in_term = 0
self.needs_linetrimming = 0
self.in_minipage = 0
# only used by figure inside an admonition
self.no_latex_floats = 0
self.first_document = 1
self.this_is_the_title = 1
Expand Down Expand Up @@ -966,11 +967,15 @@ def depart_desc_annotation(self, node: Element) -> None:
def visit_seealso(self, node: Element) -> None:
self.body.append(BLANKLINE)
self.body.append(r'\begin{sphinxseealso}{%s:}' % admonitionlabels['seealso'] + CR)
self.no_latex_floats += 1
if self.table:
self.table.has_problematic = True

def depart_seealso(self, node: Element) -> None:
self.body.append(BLANKLINE)
self.body.append(r'\end{sphinxseealso}')
self.body.append(BLANKLINE)
self.no_latex_floats -= 1

def visit_rubric(self, node: nodes.rubric) -> None:
if len(node) == 1 and node.astext() in ('Footnotes', _('Footnotes')):
Expand Down Expand Up @@ -1512,6 +1517,8 @@ def visit_figure(self, node: Element) -> None:
if self.no_latex_floats:
align = "H"
if self.table:
# Blank line is needed if text precedes
self.body.append(BLANKLINE)
# TODO: support align option
if 'width' in node:
length = self.latex_image_length(node['width'])
Expand Down Expand Up @@ -1580,6 +1587,8 @@ def depart_legend(self, node: Element) -> None:
def visit_admonition(self, node: Element) -> None:
self.body.append(CR + r'\begin{sphinxadmonition}{note}')
self.no_latex_floats += 1
if self.table:
self.table.has_problematic = True

def depart_admonition(self, node: Element) -> None:
self.body.append(r'\end{sphinxadmonition}' + CR)
Expand All @@ -1590,6 +1599,8 @@ def _visit_named_admonition(self, node: Element) -> None:
self.body.append(CR + r'\begin{sphinxadmonition}{%s}{%s:}' %
(node.tagname, label))
self.no_latex_floats += 1
if self.table:
self.table.has_problematic = True

def _depart_named_admonition(self, node: Element) -> None:
self.body.append(r'\end{sphinxadmonition}' + CR)
Expand Down
2 changes: 2 additions & 0 deletions tests/roots/test-latex-figure-in-admonition/conf.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
extensions = ['sphinx.ext.todo']
todo_include_todos = True
exclude_patterns = ['_build']
19 changes: 18 additions & 1 deletion tests/roots/test-latex-figure-in-admonition/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@ Test Figure in Admonition

.. caution::

This uses a figure in an admonition.
This uses a figure in a caution directive.

.. figure:: img.png

.. note::

This uses a figure in a note directive.

.. figure:: img.png

.. seealso::

This uses a figure in a seealso directive.

.. figure:: img.png

.. todo::

This uses a figure in a todo directive.

.. figure:: img.png
13 changes: 13 additions & 0 deletions tests/roots/test-root/markup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ Tables with multirow and multicol:

figure in table

* - .. warning::

warning in table

* - .. seealso::

figure in a seealso in a table

.. figure:: img.png

with a caption

and a legend

Figures
-------
Expand Down
28 changes: 27 additions & 1 deletion tests/test_builders/test_build_html.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test the HTML builder and check output against XPath."""

import contextlib
import os
import posixpath
import re
Expand All @@ -8,14 +9,39 @@

from sphinx.builders.html import validate_html_extra_path, validate_html_static_path
from sphinx.deprecation import RemovedInSphinx80Warning
from sphinx.errors import ConfigError
from sphinx.errors import ConfigError, ThemeError
from sphinx.util.console import strip_colors
from sphinx.util.inventory import InventoryFile

from tests.test_builders.xpath_data import FIGURE_CAPTION
from tests.test_builders.xpath_util import check_xpath


def test_html_sidebars_error(make_app, tmp_path):
(tmp_path / 'conf.py').touch()
(tmp_path / 'index.rst').touch()
app = make_app(
buildername='html',
srcdir=tmp_path,
confoverrides={'html_sidebars': {'index': 'searchbox.html'}},
)

# Test that the error is logged
warnings = app.warning.getvalue()
assert ("ERROR: Values in 'html_sidebars' must be a list of strings. "
"At least one pattern has a string value: 'index'. "
"Change to `html_sidebars = {'index': ['searchbox.html']}`.") in warnings

# But that the value is unchanged.
# (Remove this bit of the test in Sphinx 8)
def _html_context_hook(app, pagename, templatename, context, doctree):
assert context["sidebars"] == 'searchbox.html'
app.connect('html-page-context', _html_context_hook)
with contextlib.suppress(ThemeError):
# ignore template rendering issues (ThemeError).
app.build()


def test_html4_error(make_app, tmp_path):
(tmp_path / 'conf.py').write_text('', encoding='utf-8')
with pytest.raises(
Expand Down
10 changes: 6 additions & 4 deletions tests/test_builders/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,21 @@ def test_writer(app, status, warning):

assert ('\\begin{wrapfigure}{r}{0pt}\n\\centering\n'
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n'
'\\caption{figure with align option}\\label{\\detokenize{markup:id9}}'
'\\caption{figure with align option}\\label{\\detokenize{markup:id10}}'
'\\end{wrapfigure}\n\n'
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' in result)

assert ('\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n'
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n'
'\\caption{figure with align \\& figwidth option}'
'\\label{\\detokenize{markup:id10}}'
'\\label{\\detokenize{markup:id11}}'
'\\end{wrapfigure}\n\n'
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' in result)

assert ('\\begin{wrapfigure}{r}{3cm}\n\\centering\n'
'\\noindent\\sphinxincludegraphics[width=3cm]{{rimg}.png}\n'
'\\caption{figure with align \\& width option}'
'\\label{\\detokenize{markup:id11}}'
'\\label{\\detokenize{markup:id12}}'
'\\end{wrapfigure}\n\n'
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' in result)

Expand Down Expand Up @@ -1591,7 +1591,9 @@ def test_latex_labels(app, status, warning):
def test_latex_figure_in_admonition(app, status, warning):
app.build(force_all=True)
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
assert r'\begin{figure}[H]' in result
assert 'tabulary' not in result
for type in ('caution', 'note', 'seealso', 'todo'):
assert f'{type} directive.\n\n\\begin{{figure}}[H]' in result


def test_default_latex_documents():
Expand Down

0 comments on commit ce424ea

Please sign in to comment.