quickstart: Simplify generated conf.py (for texinfo)

This commit is contained in:
Takeshi KOMIYA 2018-11-11 19:48:50 +09:00
parent 4c96c6efce
commit bdaedbcbe4
6 changed files with 19 additions and 32 deletions

View File

@ -28,12 +28,13 @@ 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
@ -209,17 +210,19 @@ class TexinfoBuilder(Builder):
path.join(self.srcdir, src), err)
def default_texinfo_documents(config):
# type: (Config) -> List[Tuple[unicode, unicode, unicode, unicode, unicode, unicode, unicode]] # NOQA
""" 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]
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])

View File

@ -157,18 +157,6 @@ man_pages = [
]
# -- Options for Texinfo output ----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, '{{ project_fn }}', u'{{ project_doc_str }}',
author, '{{ project_fn }}', 'One line description of project.',
'Miscellaneous'),
]
# -- Options for Epub output -------------------------------------------------
# Bibliographic Dublin Core info.

View File

@ -145,6 +145,7 @@ def copyfile(source, dest):
no_fn_re = re.compile(r'[^a-zA-Z0-9_-]')
project_suffix_re = re.compile(' Documentation$')
def make_filename(string):
@ -152,6 +153,11 @@ def make_filename(string):
return no_fn_re.sub('', string) or 'sphinx'
def make_filename_from_project(project):
# type: (str) -> unicode
return make_filename(project_suffix_re.sub('', project)).lower()
def ustrftime(format, *args):
# type: (unicode, Any) -> unicode
"""[DEPRECATED] strftime for unicode strings."""

View File

@ -53,11 +53,6 @@ latex_documents = [
latex_additional_files = ['svgimg.svg']
texinfo_documents = [
('index', 'SphinxTests', 'Sphinx Tests',
'Georg Brandl \\and someone else', 'Sphinx Testing', 'Miscellaneous'),
]
man_pages = [
('index', 'SphinxTests', 'Sphinx Tests Documentation',
'Georg Brandl and someone else', 1),

View File

@ -46,7 +46,7 @@ def test_texinfo_warnings(app, status, warning):
def test_texinfo(app, status, warning):
TexinfoTranslator.ignore_missing_images = True
app.builder.build_all()
result = (app.outdir / 'SphinxTests.texi').text(encoding='utf8')
result = (app.outdir / 'sphinxtests.texi').text(encoding='utf8')
assert ('@anchor{markup doc}@anchor{11}'
'@anchor{markup id1}@anchor{12}'
'@anchor{markup testing-various-markup}@anchor{13}' in result)
@ -55,7 +55,7 @@ def test_texinfo(app, status, warning):
os.chdir(app.outdir)
try:
try:
p = Popen(['makeinfo', '--no-split', 'SphinxTests.texi'],
p = Popen(['makeinfo', '--no-split', 'sphinxtests.texi'],
stdout=PIPE, stderr=PIPE)
except OSError:
raise pytest.skip.Exception # most likely makeinfo was not found

View File

@ -194,10 +194,6 @@ def test_quickstart_all_answers(tempdir):
assert ns['man_pages'] == [
('contents', 'stasi', u'STASI™ Documentation',
[u'Wolfgang Schäuble & G\'Beckstein'], 1)]
assert ns['texinfo_documents'] == [
('contents', 'STASI', u'STASI™ Documentation',
u'Wolfgang Schäuble & G\'Beckstein', 'STASI',
'One line description of project.', 'Miscellaneous')]
assert (tempdir / 'build').isdir()
assert (tempdir / 'source' / '.static').isdir()
@ -268,7 +264,6 @@ def test_default_filename(tempdir):
execfile_(conffile, ns)
assert ns['latex_documents'][0][1] == 'sphinx.tex'
assert ns['man_pages'][0][1] == 'sphinx'
assert ns['texinfo_documents'][0][1] == 'sphinx'
def test_extensions(tempdir):