From 1e0c96aefafd5269af38bae24145b215ae199881 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 6 Jan 2020 12:55:53 +0000 Subject: [PATCH] Update sphinx_paramlinks to latest version --- docs/sphinx_exts/sphinx_paramlinks/README.rst | 4 ---- .../sphinx_paramlinks/sphinx_paramlinks.py | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/sphinx_exts/sphinx_paramlinks/README.rst b/docs/sphinx_exts/sphinx_paramlinks/README.rst index 4f9e9548f..e43bac4ce 100644 --- a/docs/sphinx_exts/sphinx_paramlinks/README.rst +++ b/docs/sphinx_exts/sphinx_paramlinks/README.rst @@ -102,7 +102,3 @@ Python role, but could also be expanded to support other Python role elements such as ``:returns:``, ``:raises:``, etc., and perhaps also could be made to support similar features in other roles. -Another area that's not addressed at all is search. While the params here -are linked, these objects are currently not part of the search index Sphinx -creates in any usable way. I don't know what would be involved to make that -work. \ No newline at end of file diff --git a/docs/sphinx_exts/sphinx_paramlinks/sphinx_paramlinks.py b/docs/sphinx_exts/sphinx_paramlinks/sphinx_paramlinks.py index 5f35038df..5b8319c4c 100644 --- a/docs/sphinx_exts/sphinx_paramlinks/sphinx_paramlinks.py +++ b/docs/sphinx_exts/sphinx_paramlinks/sphinx_paramlinks.py @@ -12,9 +12,12 @@ from sphinx import __version__ # the searchindex.js system relies upon the object types # in the PythonDomain to create search entries from sphinx.domains import ObjType +from sphinx.util import logging PythonDomain.object_types['parameter'] = ObjType('parameter', 'param') +LOG = logging.getLogger(__name__) + def _is_html(app): return app.builder.name in ('html', 'readthedocs') @@ -57,7 +60,15 @@ def autodoc_process_docstring(app, what, name, obj, options, lines): doc_idx.append(item) return ":param %s_sphinx_paramlinks_%s.%s:" % ( modifier, objname, paramname) - return re.sub(r'^:param ([^:]+? )?([^:]+?):', cvt, line) + + def secondary_cvt(m): + modifier, objname, paramname = m.group(1) or '', name, m.group(2) + return ":type %s_sphinx_paramlinks_%s.%s:" % ( + modifier, objname, paramname) + + line = re.sub(r'^:param ([^:]+? )?([^:]+?):', cvt, line) + line = re.sub(r'^:type ([^:]+? )?([^:]+?):', secondary_cvt, line) + return line if what in ('function', 'method', 'class'): lines[:] = [_cvt_param(name, line) for line in lines] @@ -200,12 +211,12 @@ def add_stylesheet(app): def copy_stylesheet(app, exception): - app.info( + LOG.info( bold('The name of the builder is: %s' % app.builder.name), nonl=True) if not _is_html(app) or exception: return - app.info(bold('Copying sphinx_paramlinks stylesheet... '), nonl=True) + LOG.info(bold('Copying sphinx_paramlinks stylesheet... '), nonl=True) source = os.path.abspath(os.path.dirname(__file__)) @@ -215,7 +226,7 @@ def copy_stylesheet(app, exception): # give it the path to a .css file and it does the right thing. dest = os.path.join(app.builder.outdir, '_static', 'sphinx_paramlinks.css') copyfile(os.path.join(source, "sphinx_paramlinks.css"), dest) - app.info('done') + LOG.info('done') def build_index(app, doctree):