summaryrefslogtreecommitdiff
path: root/sphinx/builders/texinfo.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/builders/texinfo.py')
-rw-r--r--sphinx/builders/texinfo.py114
1 files changed, 32 insertions, 82 deletions
diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py
index a45f83fb7..d01ef68b6 100644
--- a/sphinx/builders/texinfo.py
+++ b/sphinx/builders/texinfo.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
"""
sphinx.builders.texinfo
~~~~~~~~~~~~~~~~~~~~~~~
@@ -17,6 +16,7 @@ from docutils.frontend import OptionParser
from docutils.io import FileOutput
from sphinx import addnodes
+from sphinx import package_dir
from sphinx.builders import Builder
from sphinx.environment import NoUri
from sphinx.environment.adapters.asset import ImageAdapter
@@ -27,69 +27,18 @@ from sphinx.util.console import bold, 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 sphinx.util.osutil import SEP, make_filename_from_project
from sphinx.writers.texinfo import TexinfoWriter, TexinfoTranslator
if False:
# For type annotation
from sphinx.application import Sphinx # NOQA
+ from sphinx.config import Config # NOQA
from typing import Any, Dict, Iterable, List, Tuple, Union # NOQA
logger = logging.getLogger(__name__)
-
-TEXINFO_MAKEFILE = '''\
-# Makefile for Sphinx Texinfo output
-
-infodir ?= /usr/share/info
-
-MAKEINFO = makeinfo --no-split
-MAKEINFO_html = makeinfo --no-split --html
-MAKEINFO_plaintext = makeinfo --no-split --plaintext
-TEXI2PDF = texi2pdf --batch --expand
-INSTALL_INFO = install-info
-
-ALLDOCS = $(basename $(wildcard *.texi))
-
-all: info
-info: $(addsuffix .info,$(ALLDOCS))
-plaintext: $(addsuffix .txt,$(ALLDOCS))
-html: $(addsuffix .html,$(ALLDOCS))
-pdf: $(addsuffix .pdf,$(ALLDOCS))
-
-install-info: info
-\tfor f in *.info; do \\
-\t cp -t $(infodir) "$$f" && \\
-\t $(INSTALL_INFO) --info-dir=$(infodir) "$$f" ; \\
-\tdone
-
-uninstall-info: info
-\tfor f in *.info; do \\
-\t rm -f "$(infodir)/$$f" ; \\
-\t $(INSTALL_INFO) --delete --info-dir=$(infodir) "$$f" ; \\
-\tdone
-
-%.info: %.texi
-\t$(MAKEINFO) -o '$@' '$<'
-
-%.txt: %.texi
-\t$(MAKEINFO_plaintext) -o '$@' '$<'
-
-%.html: %.texi
-\t$(MAKEINFO_html) -o '$@' '$<'
-
-%.pdf: %.texi
-\t-$(TEXI2PDF) '$<'
-\t-$(TEXI2PDF) '$<'
-\t-$(TEXI2PDF) '$<'
-
-clean:
-\trm -f *.info *.pdf *.txt *.html
-\trm -f *.log *.ind *.aux *.toc *.syn *.idx *.out *.ilg *.pla *.ky *.pg
-\trm -f *.vr *.tp *.fn *.fns *.def *.defs *.cp *.cps *.ge *.ges *.mo
-
-.PHONY: all info plaintext html pdf install-info uninstall-info clean
-'''
+template_dir = os.path.join(package_dir, 'templates', 'texinfo')
class TexinfoBuilder(Builder):
@@ -110,22 +59,22 @@ class TexinfoBuilder(Builder):
def init(self):
# type: () -> None
- self.docnames = [] # type: Iterable[unicode]
- self.document_data = [] # type: List[Tuple[unicode, unicode, unicode, unicode, unicode, unicode, unicode, bool]] # NOQA
+ self.docnames = [] # type: Iterable[str]
+ self.document_data = [] # type: List[Tuple[str, str, str, str, str, str, str, bool]]
def get_outdated_docs(self):
- # type: () -> Union[unicode, List[unicode]]
+ # type: () -> Union[str, List[str]]
return 'all documents' # for now
def get_target_uri(self, docname, typ=None):
- # type: (unicode, unicode) -> unicode
+ # type: (str, str) -> str
if docname not in self.docnames:
raise NoUri
else:
return '%' + docname
def get_relative_uri(self, from_, to, typ=None):
- # type: (unicode, unicode, unicode) -> unicode
+ # type: (str, str, str) -> str
# ignore source path
return self.get_target_uri(to, typ)
@@ -137,7 +86,7 @@ class TexinfoBuilder(Builder):
'will be written'))
return
# assign subdirs to titles
- self.titles = [] # type: List[Tuple[unicode, unicode]]
+ self.titles = [] # type: List[Tuple[str, str]]
for entry in preliminary_document_data:
docname = entry[0]
if docname not in self.env.all_docs:
@@ -155,7 +104,7 @@ class TexinfoBuilder(Builder):
for entry in self.document_data:
docname, targetname, title, author = entry[:4]
targetname += '.texi'
- direntry = description = category = '' # type: unicode
+ direntry = description = category = ''
if len(entry) > 6:
direntry, description, category = entry[4:7]
toctree_only = False
@@ -164,17 +113,17 @@ class TexinfoBuilder(Builder):
destination = FileOutput(
destination_path=path.join(self.outdir, targetname),
encoding='utf-8')
- logger.info(__("processing %s..."), targetname, nonl=1)
+ logger.info(__("processing %s..."), targetname, nonl=True)
doctree = self.assemble_doctree(
docname, toctree_only,
appendices=(self.config.texinfo_appendices or []))
- logger.info(__("writing... "), nonl=1)
+ logger.info(__("writing... "), nonl=True)
self.post_process_images(doctree)
docwriter = TexinfoWriter(self)
settings = OptionParser(
defaults=self.env.settings,
components=(docwriter,),
- read_config_files=True).get_default_values()
+ read_config_files=True).get_default_values() # type: Any
settings.author = author
settings.title = title
settings.texinfo_filename = targetname[:-5] + '.info'
@@ -188,9 +137,9 @@ class TexinfoBuilder(Builder):
logger.info(__("done"))
def assemble_doctree(self, indexfile, toctree_only, appendices):
- # type: (unicode, bool, List[unicode]) -> nodes.Node
+ # type: (str, bool, List[str]) -> nodes.document
self.docnames = set([indexfile] + appendices)
- logger.info(darkgreen(indexfile) + " ", nonl=1)
+ logger.info(darkgreen(indexfile) + " ", nonl=True)
tree = self.env.get_doctree(indexfile)
tree['docname'] = indexfile
if toctree_only:
@@ -198,8 +147,8 @@ class TexinfoBuilder(Builder):
# fresh document
new_tree = new_document('<texinfo output>')
new_sect = nodes.section()
- new_sect += nodes.title(u'<Set title in conf.py>',
- u'<Set title in conf.py>')
+ new_sect += nodes.title('<Set title in conf.py>',
+ '<Set title in conf.py>')
new_tree += new_sect
for node in tree.traverse(addnodes.toctree):
new_sect += node
@@ -218,7 +167,7 @@ class TexinfoBuilder(Builder):
for pendingnode in largetree.traverse(addnodes.pending_xref):
docname = pendingnode['refdocname']
sectname = pendingnode['refsectname']
- newnodes = [nodes.emphasis(sectname, sectname)]
+ newnodes = [nodes.emphasis(sectname, sectname)] # type: List[nodes.Node]
for subdir, title in self.titles:
if docname.startswith(subdir):
newnodes.append(nodes.Text(_(' (in '), _(' (in ')))
@@ -237,11 +186,10 @@ class TexinfoBuilder(Builder):
logger.info(bold(__('copying Texinfo support files... ')), nonl=True)
# copy Makefile
fn = path.join(self.outdir, 'Makefile')
- logger.info(fn, nonl=1)
+ logger.info(fn, nonl=True)
try:
- with open(fn, 'w') as mkfile:
- mkfile.write(TEXINFO_MAKEFILE)
- except (IOError, OSError) as err:
+ copy_asset_file(os.path.join(template_dir, 'Makefile'), fn)
+ except OSError as err:
logger.warning(__("error writing file %s: %s"), fn, err)
logger.info(__(' done'))
@@ -261,17 +209,19 @@ class TexinfoBuilder(Builder):
path.join(self.srcdir, src), err)
+def default_texinfo_documents(config):
+ # type: (Config) -> List[Tuple[str, str, str, str, str, str, str]]
+ """ Better default texinfo_documents settings. """
+ filename = make_filename_from_project(config.project)
+ return [(config.master_doc, filename, config.project, config.author, filename,
+ 'One line description of project', 'Miscellaneous')]
+
+
def setup(app):
- # type: (Sphinx) -> Dict[unicode, Any]
+ # type: (Sphinx) -> Dict[str, Any]
app.add_builder(TexinfoBuilder)
- app.add_config_value('texinfo_documents',
- lambda self: [(self.master_doc, make_filename(self.project).lower(),
- self.project, '', make_filename(self.project),
- 'The %s reference manual.' %
- make_filename(self.project),
- 'Python')],
- None)
+ app.add_config_value('texinfo_documents', default_texinfo_documents, None)
app.add_config_value('texinfo_appendices', [], None)
app.add_config_value('texinfo_elements', {}, None)
app.add_config_value('texinfo_domain_indices', True, None, [list])