Skip to content

Commit

Permalink
Undo parallel image changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 10, 2023
1 parent 7841d3d commit 2a7c40d
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 56 deletions.
11 changes: 4 additions & 7 deletions sphinx/builders/_epub_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,9 @@ def copy_image_files_pil(self) -> None:
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:
Expand Down Expand Up @@ -441,7 +438,7 @@ def copy_image_files(self) -> None:
"""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'))
Expand Down
19 changes: 9 additions & 10 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,9 +656,6 @@ def get_doc_context(self, docname: str, body: str, metatags: str) -> dict[str, A
}

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)
Expand All @@ -668,6 +665,7 @@ def write_doc(self, docname: str, doctree: nodes.document) -> None:

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)
Expand All @@ -678,6 +676,10 @@ def write_doc(self, docname: str, doctree: nodes.document) -> None:
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)
Expand Down Expand Up @@ -764,16 +766,13 @@ def write_domain_indices(self) -> None:
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))
Expand Down
11 changes: 4 additions & 7 deletions sphinx/builders/latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,12 @@ def copy_latex_additional_files(self) -> None:
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))
Expand Down
11 changes: 4 additions & 7 deletions sphinx/builders/texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,12 @@ def finish(self) -> None:
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)
Expand Down
6 changes: 3 additions & 3 deletions sphinx/writers/_html4.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ def append_fignumber(figtype: str, figure_id: str) -> None:
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>')

Expand Down Expand Up @@ -569,7 +569,7 @@ def visit_download_reference(self, node: Element) -> None:
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>')
Expand Down
6 changes: 3 additions & 3 deletions sphinx/writers/html5.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ def append_fignumber(figtype: str, figure_id: str) -> None:
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>')

Expand Down Expand Up @@ -544,7 +544,7 @@ def visit_download_reference(self, node: Element) -> None:
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>')
Expand Down
5 changes: 1 addition & 4 deletions tests/test_build_epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
3 changes: 0 additions & 3 deletions tests/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
7 changes: 1 addition & 6 deletions tests/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1682,14 +1682,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',
}
7 changes: 1 addition & 6 deletions tests/test_build_texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

0 comments on commit 2a7c40d

Please sign in to comment.