diff --git a/CHANGES b/CHANGES index 0e0998c32..687f73f39 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,8 @@ Dependencies Incompatible changes -------------------- +* texinfo: image files are copied into ``name-figure`` directory + Deprecated ---------- @@ -22,6 +24,7 @@ Bugs fixed * #5508: ``linenothreshold`` option for ``highlight`` directive was ignored * texinfo: ``make install-info`` causes syntax error * texinfo: ``make install-info`` fails on macOS +* #3079: texinfo: image files are not copied on ``make install-info`` Testing -------- diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py index 2655d7a0b..3b2816e77 100644 --- a/sphinx/builders/texinfo.py +++ b/sphinx/builders/texinfo.py @@ -27,7 +27,7 @@ from sphinx.util.console import darkgreen # type: ignore from sphinx.util.docutils import new_document from sphinx.util.fileutil import copy_asset_file from sphinx.util.nodes import inline_all_toctrees -from sphinx.util.osutil import SEP, make_filename_from_project +from sphinx.util.osutil import SEP, ensuredir, make_filename_from_project from sphinx.writers.texinfo import TexinfoWriter, TexinfoTranslator if False: @@ -134,6 +134,7 @@ class TexinfoBuilder(Builder): settings.docname = docname doctree.settings = settings docwriter.write(doctree, destination) + self.copy_image_files(targetname[:-5]) def assemble_doctree(self, indexfile, toctree_only, appendices): # type: (str, bool, List[str]) -> nodes.document @@ -180,11 +181,10 @@ class TexinfoBuilder(Builder): def finish(self): # type: () -> None - self.copy_image_files() self.copy_support_files() - def copy_image_files(self): - # type: () -> None + def copy_image_files(self, targetname): + # type: (str) -> None if self.images: stringify_func = ImageAdapter(self.app.env).get_original_image_uri for src in status_iterator(self.images, __('copying images... '), "brown", @@ -192,8 +192,9 @@ class TexinfoBuilder(Builder): stringify_func=stringify_func): dest = self.images[src] try: - copy_asset_file(path.join(self.srcdir, src), - path.join(self.outdir, dest)) + imagedir = path.join(self.outdir, targetname + '-figures') + ensuredir(imagedir) + copy_asset_file(path.join(self.srcdir, dest), imagedir) except Exception as err: logger.warning(__('cannot copy image file %r: %s'), path.join(self.srcdir, src), err) diff --git a/sphinx/templates/texinfo/Makefile b/sphinx/templates/texinfo/Makefile index 8befee3ca..e3b732cda 100644 --- a/sphinx/templates/texinfo/Makefile +++ b/sphinx/templates/texinfo/Makefile @@ -20,12 +20,18 @@ install-info: info for f in *.info; do \ mkdir -p $(infodir) && \ cp "$$f" $(infodir) && \ - $(INSTALL_INFO) --info-dir=$(infodir) "$$f" ; \ + $(INSTALL_INFO) --info-dir=$(infodir) "$$f" && \ + \ + FIGURE_DIR="`basename \"$$f\" .info`-figures" && \ + if [ -e "$$FIGURE_DIR" ]; then \ + cp -r "$$FIGURE_DIR" $(infodir) ; \ + fi; \ done uninstall-info: info for f in *.info; do \ rm -f "$(infodir)/$$f" ; \ + rm -rf "$(infodir)/`basename '$$f' .info`-figures" && \ $(INSTALL_INFO) --delete --info-dir=$(infodir) "$$f" ; \ done diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index ede48ec60..4262ccd66 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -1355,8 +1355,9 @@ class TexinfoTranslator(SphinxTranslator): width = self.tex_image_length(attrs.get('width', '')) height = self.tex_image_length(attrs.get('height', '')) alt = self.escape_arg(attrs.get('alt', '')) + filename = "%s-figures/%s" % (self.elements['filename'][:-5], name) # type: ignore self.body.append('\n@image{%s,%s,%s,%s,%s}\n' % - (name, width, height, alt, ext[1:])) + (filename, width, height, alt, ext[1:])) def depart_image(self, node): # type: (nodes.Element) -> None