Skip to content

Commit 1b47aca

Browse files
committed
Compatibility fix cause by upstream
sphinx-doc/sphinx#13985
1 parent d3b83a0 commit 1b47aca

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

sphinx_automodapi/automodsumm.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ class members that are inherited from a base class. This value can be
112112
from sphinx.ext.autosummary import Autosummary
113113
from sphinx.ext.inheritance_diagram import InheritanceDiagram, InheritanceGraph, try_import
114114

115-
from .utils import find_mod_objs, cleanup_whitespace
115+
from .utils import find_mod_objs, cleanup_whitespace, SPHINX_LT_8_3
116116

117117
__all__ = ['Automoddiagram', 'Automodsumm', 'automodsumm_to_autosummary_lines',
118118
'generate_automodsumm_docs', 'process_automodsumm_generation']
119119
logger = logging.getLogger(__name__)
120-
SPHINX_LT_8_2 = Version(sphinx.__version__) < Version("8.2.dev")
120+
SPHINX_LT_8_2 = Version(sphinx.__version__) < Version("8.2")
121121

122122

123123
def _str_list_converter(argument):
@@ -219,7 +219,8 @@ def run(self):
219219

220220
def get_items(self, names):
221221

222-
self.bridge.genopt.imported_members = True
222+
if SPHINX_LT_8_3:
223+
self.bridge.genopt.imported_members = True
223224

224225
return Autosummary.get_items(self, names)
225226

@@ -479,13 +480,14 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
479480
"""
480481

481482
from sphinx.jinja2glue import BuiltinTemplateLoader
482-
from sphinx.ext.autosummary import import_by_name, get_documenter
483+
from sphinx.ext.autosummary import import_by_name
483484
from sphinx.util.osutil import ensuredir
484485
from sphinx.util.inspect import safe_getattr
485486
from jinja2 import FileSystemLoader, TemplateNotFound
486487
from jinja2.sandbox import SandboxedEnvironment
487488

488489
from .utils import find_autosummary_in_lines_for_automodsumm as find_autosummary_in_lines
490+
from .utils import get_documenter
489491

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

sphinx_automodapi/utils.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
from inspect import ismodule
55
from warnings import warn
66

7+
import sphinx
8+
from packaging.version import Version
79
from sphinx.ext.autosummary.generate import find_autosummary_in_docstring
810

911
__all__ = ['cleanup_whitespace',
10-
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm']
12+
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm',
13+
'get_documenter']
14+
15+
SPHINX_LT_8_3 = Version(sphinx.__version__) < Version("8.3.dev")
1116

1217
# We use \n instead of os.linesep because even on Windows, the generated files
1318
# use \n as the newline character.
@@ -227,3 +232,27 @@ def find_autosummary_in_lines_for_automodsumm(lines, module=None, filename=None)
227232
continue
228233

229234
return documented
235+
236+
237+
# This used to be in Sphinx proper but removed in
238+
# https://github.com/sphinx-doc/sphinx/pull/13985
239+
def get_documenter(app, obj, parent):
240+
"""Get an autodoc.Documenter class suitable for documenting the given
241+
object.
242+
243+
*obj* is the Python object to be documented, and *parent* is an
244+
another Python object (e.g. a module or a class) to which *obj*
245+
belongs to.
246+
"""
247+
if SPHINX_LT_8_3:
248+
from sphinx.ext.autosummary import get_documenter
249+
250+
retval = get_documenter(app, obj, parent)
251+
252+
else:
253+
from sphinx.ext.autosummary import _get_documenter
254+
255+
obj_type = _get_documenter(obj, parent)
256+
retval = app.registry.documenters[obj_type]
257+
258+
return retval

0 commit comments

Comments
 (0)