Skip to content

Commit f5c05c8

Browse files
committed
Move get_documenter over from Sphinx
because it was removed upstream in sphinx-doc/sphinx#13985
1 parent d3b83a0 commit f5c05c8

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

sphinx_automodapi/automodsumm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,14 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
479479
"""
480480

481481
from sphinx.jinja2glue import BuiltinTemplateLoader
482-
from sphinx.ext.autosummary import import_by_name, get_documenter
482+
from sphinx.ext.autosummary import import_by_name
483483
from sphinx.util.osutil import ensuredir
484484
from sphinx.util.inspect import safe_getattr
485485
from jinja2 import FileSystemLoader, TemplateNotFound
486486
from jinja2.sandbox import SandboxedEnvironment
487487

488488
from .utils import find_autosummary_in_lines_for_automodsumm as find_autosummary_in_lines
489+
from .utils import get_documenter
489490

490491
# Create our own templating environment - here we use Astropy's
491492
# templates rather than the default autosummary templates, in order to

sphinx_automodapi/utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from sphinx.ext.autosummary.generate import find_autosummary_in_docstring
88

99
__all__ = ['cleanup_whitespace',
10-
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm']
10+
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm',
11+
'get_documenter']
1112

1213
# We use \n instead of os.linesep because even on Windows, the generated files
1314
# use \n as the newline character.
@@ -227,3 +228,19 @@ def find_autosummary_in_lines_for_automodsumm(lines, module=None, filename=None)
227228
continue
228229

229230
return documented
231+
232+
233+
# This used to be in Sphinx proper but removed in
234+
# https://github.com/sphinx-doc/sphinx/pull/13985
235+
def get_documenter(app, obj, parent):
236+
"""Get an autodoc.Documenter class suitable for documenting the given
237+
object.
238+
239+
*obj* is the Python object to be documented, and *parent* is an
240+
another Python object (e.g. a module or a class) to which *obj*
241+
belongs to.
242+
"""
243+
from sphinx.ext.autosummary import _get_documenter
244+
245+
obj_type = _get_documenter(obj, parent)
246+
return app.registry.documenters[obj_type]

0 commit comments

Comments
 (0)