Close #1448: qthelp: Add new config value; qthelp_namespace

This commit is contained in:
Takeshi KOMIYA 2017-10-08 23:22:56 +09:00
parent 2839fc5f68
commit 1292089255
4 changed files with 41 additions and 1 deletions

View File

@ -35,6 +35,7 @@ Features added
* #3973: epub: allow to override build date
* #3972: epub: Sort manifest entries by filename
* #4052: viewcode: Sort before highlighting module code
* #1448: qthelp: Add new config value; :confval:`qthelp_namespace`
Features removed

View File

@ -2074,6 +2074,11 @@ builder, the HTML options also apply where appropriate.
The basename for the qthelp file. It defaults to the :confval:`project` name.
.. confval:: qthelp_namespace
The namespace for the qthelp file. It defaults to
``org.sphinx.<project_name>.<project_version>``.
.. confval:: qthelp_theme
The HTML theme for the qthelp output.

View File

@ -21,6 +21,7 @@ from docutils import nodes
from sphinx import addnodes
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.config import string_classes
from sphinx.environment.adapters.indexentries import IndexEntries
from sphinx.util import force_decode, logging
from sphinx.util.osutil import make_filename
@ -199,7 +200,11 @@ class QtHelpBuilder(StandaloneHTMLBuilder):
# it seems that the "namespace" may not contain non-alphanumeric
# characters, and more than one successive dot, or leading/trailing
# dots, are also forbidden
nspace = 'org.sphinx.%s.%s' % (outname, self.config.version)
if self.config.qthelp_namespace:
nspace = self.config.qthelp_namespace
else:
nspace = 'org.sphinx.%s.%s' % (outname, self.config.version)
nspace = re.sub('[^a-zA-Z0-9.]', '', nspace)
nspace = re.sub(r'\.+', '.', nspace).strip('.')
nspace = nspace.lower()
@ -328,6 +333,7 @@ def setup(app):
app.add_builder(QtHelpBuilder)
app.add_config_value('qthelp_basename', lambda self: make_filename(self.project), None)
app.add_config_value('qthelp_namespace', None, 'html', string_classes)
app.add_config_value('qthelp_theme', 'nonav', 'html')
app.add_config_value('qthelp_theme_options', {}, 'html')

View File

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
"""
test_build_qthelp
~~~~~~~~~~~~~~~~~
Test the Qt Help builder and check its output. We don't need to
test the HTML itself; that's already handled by
:file:`test_build_html.py`.
:copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import pytest
@pytest.mark.sphinx('qthelp', testroot='basic')
def test_qthelp_namespace(app, status, warning):
# default namespace
app.builder.build_all()
qhp = (app.outdir / 'Python.qhp').text()
assert '<namespace>org.sphinx.python</namespace>' in qhp
# give a namespace
app.config.qthelp_namespace = 'org.sphinx-doc.sphinx'
app.builder.build_all()
qhp = (app.outdir / 'Python.qhp').text()
assert '<namespace>org.sphinxdoc.sphinx</namespace>' in qhp