From 12920892550a0fa0e50d876630175fd100291532 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 8 Oct 2017 23:22:56 +0900 Subject: [PATCH] Close #1448: qthelp: Add new config value; qthelp_namespace --- CHANGES | 1 + doc/config.rst | 5 +++++ sphinx/builders/qthelp.py | 8 +++++++- tests/test_build_qthelp.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/test_build_qthelp.py diff --git a/CHANGES b/CHANGES index 064808952..ad6fe5759 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/doc/config.rst b/doc/config.rst index 1762c84ec..9499c6276 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -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..``. + .. confval:: qthelp_theme The HTML theme for the qthelp output. diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py index 14979fe4b..12c28b1a3 100644 --- a/sphinx/builders/qthelp.py +++ b/sphinx/builders/qthelp.py @@ -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') diff --git a/tests/test_build_qthelp.py b/tests/test_build_qthelp.py new file mode 100644 index 000000000..3e4815fbe --- /dev/null +++ b/tests/test_build_qthelp.py @@ -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 'org.sphinx.python' in qhp + + # give a namespace + app.config.qthelp_namespace = 'org.sphinx-doc.sphinx' + app.builder.build_all() + qhp = (app.outdir / 'Python.qhp').text() + assert 'org.sphinxdoc.sphinx' in qhp