diff options
author | Brad King <brad.king@kitware.com> | 2020-10-05 17:38:08 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-10-05 17:38:08 (GMT) |
commit | 2254fcb68fe1e36feed65abd0f1327e01a38263c (patch) | |
tree | a867329e6915ac73c16786e8f5df00105516054b /Utilities/Sphinx | |
parent | e0f643dddc4c66b6afd582b1bb659399d8c0b76a (diff) | |
download | CMake-2254fcb68fe1e36feed65abd0f1327e01a38263c.zip CMake-2254fcb68fe1e36feed65abd0f1327e01a38263c.tar.gz CMake-2254fcb68fe1e36feed65abd0f1327e01a38263c.tar.bz2 |
Utilities/Sphinx: Avoid using deprecated sphinx APIs
Sphinx has deprecated `sphinx.util.pycompat.htmlescape` and
`sphinx.builders.qthelp.QtHelpBuilder`. We only import these as part of
a monkey-patch to work around a bug in versions of sphinx before 1.7.2,
so make that code path conditional. The imports are not deprecated on
the versions where we need them.
Diffstat (limited to 'Utilities/Sphinx')
-rw-r--r-- | Utilities/Sphinx/cmake.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/Utilities/Sphinx/cmake.py b/Utilities/Sphinx/cmake.py index d3aeb9d..e175d0d 100644 --- a/Utilities/Sphinx/cmake.py +++ b/Utilities/Sphinx/cmake.py @@ -57,25 +57,6 @@ CMakeLexer.tokens["root"] = [ # (r'[^<>\])\}\|$"# \t\n]+', Name.Exception), # fallback, for debugging only ] -# Monkey patch for sphinx generating invalid content for qcollectiongenerator -# https://bitbucket.org/birkenfeld/sphinx/issue/1435/qthelp-builder-should-htmlescape-keywords -from sphinx.util.pycompat import htmlescape -from sphinx.builders.qthelp import QtHelpBuilder -old_build_keywords = QtHelpBuilder.build_keywords -def new_build_keywords(self, title, refs, subitems): - old_items = old_build_keywords(self, title, refs, subitems) - new_items = [] - for item in old_items: - before, rest = item.split("ref=\"", 1) - ref, after = rest.split("\"") - if ("<" in ref and ">" in ref): - new_items.append(before + "ref=\"" + htmlescape(ref) + "\"" + after) - else: - new_items.append(item) - return new_items -QtHelpBuilder.build_keywords = new_build_keywords - - from docutils.parsers.rst import Directive, directives from docutils.transforms import Transform try: @@ -93,13 +74,36 @@ from sphinx.util.nodes import make_refnode from sphinx import addnodes sphinx_before_1_4 = False +sphinx_before_1_7_2 = False try: from sphinx import version_info if version_info < (1, 4): sphinx_before_1_4 = True + if version_info < (1, 7, 2): + sphinx_before_1_7_2 = True except ImportError: # The `sphinx.version_info` tuple was added in Sphinx v1.2: sphinx_before_1_4 = True + sphinx_before_1_7_2 = True + +if sphinx_before_1_7_2: + # Monkey patch for sphinx generating invalid content for qcollectiongenerator + # https://github.com/sphinx-doc/sphinx/issues/1435 + from sphinx.util.pycompat import htmlescape + from sphinx.builders.qthelp import QtHelpBuilder + old_build_keywords = QtHelpBuilder.build_keywords + def new_build_keywords(self, title, refs, subitems): + old_items = old_build_keywords(self, title, refs, subitems) + new_items = [] + for item in old_items: + before, rest = item.split("ref=\"", 1) + ref, after = rest.split("\"") + if ("<" in ref and ">" in ref): + new_items.append(before + "ref=\"" + htmlescape(ref) + "\"" + after) + else: + new_items.append(item) + return new_items + QtHelpBuilder.build_keywords = new_build_keywords class CMakeModule(Directive): required_arguments = 1 |