Merge branch '6.1.x'

# Conflicts:
#	CHANGES
#	sphinx/__init__.py
This commit is contained in:
Adam Turner
2023-01-10 16:00:59 +00:00
13 changed files with 67 additions and 61 deletions

12
CHANGES
View File

@@ -27,7 +27,7 @@ Bugs fixed
Testing
--------
Release 6.1.3 (in development)
Release 6.1.4 (in development)
==============================
Dependencies
@@ -48,6 +48,16 @@ Bugs fixed
Testing
--------
Release 6.1.3 (released Jan 10, 2023)
=====================================
Bugs fixed
----------
* #11116: Reverted to previous Sphinx 5 node copying method
* #11117: Reverted changes to parallel image processing from Sphinx 6.1.0
* #11119: Supress ``ValueError`` in the ``linkcheck`` builder
Release 6.1.2 (released Jan 07, 2023)
=====================================

View File

@@ -401,12 +401,9 @@ class EpubBuilder(StandaloneHTMLBuilder):
the format and resizing the image if necessary/possible.
"""
ensuredir(path.join(self.outdir, self.imagedir))
converted_images = {*self.env.original_image_uri.values()}
for src in status_iterator(self.env.images, __('copying images... '), "brown",
len(self.env.images), self.app.verbosity):
if src in converted_images:
continue
_docnames, dest = self.env.images[src]
for src in status_iterator(self.images, __('copying images... '), "brown",
len(self.images), self.app.verbosity):
dest = self.images[src]
try:
img = Image.open(path.join(self.srcdir, src))
except OSError:
@@ -441,7 +438,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
"""Copy image files to destination directory.
This overwritten method can use Pillow to convert image files.
"""
if self.env.images:
if self.images:
if self.config.epub_fix_images or self.config.epub_max_image_width:
if not Image:
logger.warning(__('Pillow not found - copying image files'))

View File

@@ -655,9 +655,6 @@ class StandaloneHTMLBuilder(Builder):
}
def write_doc(self, docname: str, doctree: nodes.document) -> None:
self.imgpath = relative_uri(self.get_target_uri(docname), self.imagedir)
self.post_process_images(doctree)
title_node = self.env.longtitles.get(docname)
title = self.render_partial(title_node)['title'] if title_node else ''
self.index_page(docname, doctree, title)
@@ -667,6 +664,7 @@ class StandaloneHTMLBuilder(Builder):
self.secnumbers = self.env.toc_secnumbers.get(docname, {})
self.fignumbers = self.env.toc_fignumbers.get(docname, {})
self.imgpath = relative_uri(self.get_target_uri(docname), '_images')
self.dlpath = relative_uri(self.get_target_uri(docname), '_downloads')
self.current_docname = docname
self.docwriter.write(doctree, destination)
@@ -677,6 +675,10 @@ class StandaloneHTMLBuilder(Builder):
ctx = self.get_doc_context(docname, body, metatags)
self.handle_page(docname, ctx, event_arg=doctree)
def write_doc_serialized(self, docname: str, doctree: nodes.document) -> None:
self.imgpath = relative_uri(self.get_target_uri(docname), self.imagedir)
self.post_process_images(doctree)
def finish(self) -> None:
self.finish_tasks.add_task(self.gen_indices)
self.finish_tasks.add_task(self.gen_pages_from_extensions)
@@ -763,16 +765,13 @@ class StandaloneHTMLBuilder(Builder):
self.handle_page(indexname, indexcontext, 'domainindex.html')
def copy_image_files(self) -> None:
if self.env.images:
converted_images = {*self.env.original_image_uri.values()}
if self.images:
stringify_func = ImageAdapter(self.app.env).get_original_image_uri
ensuredir(path.join(self.outdir, self.imagedir))
for src in status_iterator(self.env.images, __('copying images... '), "brown",
len(self.env.images), self.app.verbosity,
for src in status_iterator(self.images, __('copying images... '), "brown",
len(self.images), self.app.verbosity,
stringify_func=stringify_func):
if src in converted_images:
continue
_docnames, dest = self.env.images[src]
dest = self.images[src]
try:
copyfile(path.join(self.srcdir, src),
path.join(self.outdir, self.imagedir, dest))

View File

@@ -413,15 +413,12 @@ class LaTeXBuilder(Builder):
copy_asset_file(path.join(self.confdir, filename), self.outdir)
def copy_image_files(self) -> None:
if self.env.images:
converted_images = {*self.env.original_image_uri.values()}
if self.images:
stringify_func = ImageAdapter(self.app.env).get_original_image_uri
for src in status_iterator(self.env.images, __('copying images... '), "brown",
len(self.env.images), self.app.verbosity,
for src in status_iterator(self.images, __('copying images... '), "brown",
len(self.images), self.app.verbosity,
stringify_func=stringify_func):
if src in converted_images:
continue
_docnames, dest = self.env.images[src]
dest = self.images[src]
try:
copy_asset_file(path.join(self.srcdir, src),
path.join(self.outdir, dest))

View File

@@ -509,7 +509,10 @@ class HyperlinkCollector(SphinxPostTransform):
if newuri:
uri = newuri
lineno = get_node_line(node)
try:
lineno = get_node_line(node)
except ValueError:
lineno = None
uri_info = Hyperlink(uri, self.env.docname, lineno)
if uri not in hyperlinks:
hyperlinks[uri] = uri_info

View File

@@ -173,15 +173,12 @@ class TexinfoBuilder(Builder):
self.copy_support_files()
def copy_image_files(self, targetname: str) -> None:
if self.env.images:
converted_images = {*self.env.original_image_uri.values()}
if self.images:
stringify_func = ImageAdapter(self.app.env).get_original_image_uri
for src in status_iterator(self.env.images, __('copying images... '), "brown",
len(self.env.images), self.app.verbosity,
for src in status_iterator(self.images, __('copying images... '), "brown",
len(self.images), self.app.verbosity,
stringify_func=stringify_func):
if src in converted_images:
continue
_docnames, dest = self.env.images[src]
dest = self.images[src]
try:
imagedir = path.join(self.outdir, targetname + '-figures')
ensuredir(imagedir)

View File

@@ -172,7 +172,10 @@ def apply_source_workaround(node: Element) -> None:
))):
logger.debug('[i18n] PATCH: %r to have source and line: %s',
get_full_module_name(node), repr_domxml(node))
node.source = get_node_source(node) or ''
try:
node.source = get_node_source(node)
except ValueError:
node.source = ''
node.line = 0 # need fix docutils to get `node.line`
return
@@ -561,8 +564,9 @@ def set_role_source_info(inliner: Inliner, lineno: int, node: Node) -> None:
def copy_source_info(src: Element, dst: Element) -> None:
dst.source = get_node_source(src)
dst.line = get_node_line(src)
with contextlib.suppress(ValueError):
dst.source = get_node_source(src)
dst.line = get_node_line(src)
NON_SMARTQUOTABLE_PARENT_NODES = (
@@ -608,3 +612,18 @@ def process_only_nodes(document: Node, tags: Tags) -> None:
# the only node, so we make sure docutils can transfer the id to
# something, even if it's just a comment and will lose the id anyway...
node.replace_self(nodes.comment())
def _copy_except__document(self: Element) -> Element:
"""Monkey-patch ```nodes.Element.copy``` to not copy the ``_document``
attribute.
xref: https://github.com/sphinx-doc/sphinx/issues/11116#issuecomment-1376767086
"""
newnode = self.__class__(rawsource=self.rawsource, **self.attributes)
newnode.source = self.source
newnode.line = self.line
return newnode
nodes.Element.copy = _copy_except__document # type: ignore

View File

@@ -287,14 +287,14 @@ class HTML4Translator(SphinxTranslator, BaseTranslator):
else:
key = figtype
if figure_id in self.builder.fignumbers.get(key, {}): # type: ignore[has-type]
if figure_id in self.builder.fignumbers.get(key, {}):
self.body.append('<span class="caption-number">')
prefix = self.config.numfig_format.get(figtype)
if prefix is None:
msg = __('numfig_format is not defined for %s') % figtype
logger.warning(msg)
else:
numbers = self.builder.fignumbers[key][figure_id] # type: ignore[has-type]
numbers = self.builder.fignumbers[key][figure_id]
self.body.append(prefix % '.'.join(map(str, numbers)) + ' ')
self.body.append('</span>')
@@ -569,7 +569,7 @@ class HTML4Translator(SphinxTranslator, BaseTranslator):
self.context.append('</a>')
elif 'filename' in node:
atts['class'] += ' internal'
atts['href'] = posixpath.join(self.builder.dlpath, # type: ignore[has-type]
atts['href'] = posixpath.join(self.builder.dlpath,
urllib.parse.quote(node['filename']))
self.body.append(self.starttag(node, 'a', '', **atts))
self.context.append('</a>')

View File

@@ -293,14 +293,14 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
else:
key = figtype
if figure_id in self.builder.fignumbers.get(key, {}): # type: ignore[has-type]
if figure_id in self.builder.fignumbers.get(key, {}):
self.body.append('<span class="caption-number">')
prefix = self.config.numfig_format.get(figtype)
if prefix is None:
msg = __('numfig_format is not defined for %s') % figtype
logger.warning(msg)
else:
numbers = self.builder.fignumbers[key][figure_id] # type: ignore[has-type]
numbers = self.builder.fignumbers[key][figure_id]
self.body.append(prefix % '.'.join(map(str, numbers)) + ' ')
self.body.append('</span>')
@@ -544,7 +544,7 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
self.context.append('</a>')
elif 'filename' in node:
atts['class'] += ' internal'
atts['href'] = posixpath.join(self.builder.dlpath, # type: ignore[has-type]
atts['href'] = posixpath.join(self.builder.dlpath,
urllib.parse.quote(node['filename']))
self.body.append(self.starttag(node, 'a', '', **atts))
self.context.append('</a>')

View File

@@ -399,14 +399,11 @@ def test_copy_images(app, status, warning):
images_dir = Path(app.outdir) / '_images'
images = {image.name for image in images_dir.rglob('*')}
images.discard('python-logo.png')
assert images == {
'img.gif',
'img.pdf',
'img.png',
'python-logo.png',
'rimg.png',
'rimg1.png',
'svgimg.pdf',
'svgimg.svg',
'testimäge.png',
}

View File

@@ -1780,12 +1780,9 @@ def test_copy_images(app, status, warning):
images_dir = Path(app.outdir) / '_images'
images = {image.name for image in images_dir.rglob('*')}
assert images == {
'img.gif',
'img.pdf',
'img.png',
'rimg.png',
'rimg1.png',
'svgimg.pdf',
'svgimg.svg',
'testimäge.png',
}

View File

@@ -1685,14 +1685,9 @@ def test_copy_images(app, status, warning):
image.name for image in test_dir.rglob('*')
if image.suffix in {'.gif', '.pdf', '.png', '.svg'}
}
images.discard('python-logo.png')
assert images == {
'img.gif',
'img.pdf',
'img.png',
'python-logo.png',
'rimg.png',
'rimg1.png',
'svgimg.pdf',
'svgimg.svg',
'testimäge.png',
}

View File

@@ -146,14 +146,9 @@ def test_copy_images(app, status, warning):
images_dir = Path(app.outdir) / 'python-figures'
images = {image.name for image in images_dir.rglob('*')}
images.discard('python-logo.png')
assert images == {
'img.gif',
'img.pdf',
'img.png',
'python-logo.png',
'rimg.png',
'rimg1.png',
'svgimg.pdf',
'svgimg.svg',
'testimäge.png',
}