Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ class members that are inherited from a base class. This value can be
from sphinx.ext.autosummary import Autosummary
from sphinx.ext.inheritance_diagram import InheritanceDiagram, InheritanceGraph, try_import

from .utils import find_mod_objs, cleanup_whitespace
from .utils import find_mod_objs, cleanup_whitespace, SPHINX_LT_8_3

__all__ = ['Automoddiagram', 'Automodsumm', 'automodsumm_to_autosummary_lines',
'generate_automodsumm_docs', 'process_automodsumm_generation']
logger = logging.getLogger(__name__)
SPHINX_LT_8_2 = Version(sphinx.__version__) < Version("8.2.dev")
SPHINX_LT_8_2 = Version(sphinx.__version__) < Version("8.2")


def _str_list_converter(argument):
Expand Down Expand Up @@ -219,7 +219,8 @@ def run(self):

def get_items(self, names):

self.bridge.genopt.imported_members = True
if SPHINX_LT_8_3:
self.bridge.genopt.imported_members = True

return Autosummary.get_items(self, names)

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

from sphinx.jinja2glue import BuiltinTemplateLoader
from sphinx.ext.autosummary import import_by_name, get_documenter
from sphinx.ext.autosummary import import_by_name
from sphinx.util.osutil import ensuredir
from sphinx.util.inspect import safe_getattr
from jinja2 import FileSystemLoader, TemplateNotFound
from jinja2.sandbox import SandboxedEnvironment

from .utils import find_autosummary_in_lines_for_automodsumm as find_autosummary_in_lines
from .utils import get_documenter

# Create our own templating environment - here we use Astropy's
# templates rather than the default autosummary templates, in order to
Expand Down
31 changes: 30 additions & 1 deletion sphinx_automodapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
from inspect import ismodule
from warnings import warn

import sphinx
from packaging.version import Version
from sphinx.ext.autosummary.generate import find_autosummary_in_docstring

__all__ = ['cleanup_whitespace',
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm']
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm',
'get_documenter']

SPHINX_LT_8_3 = Version(sphinx.__version__) < Version("8.3.dev")

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

return documented


# This used to be in Sphinx proper but removed in
# https://github.com/sphinx-doc/sphinx/pull/13985
def get_documenter(app, obj, parent):
"""Get an autodoc.Documenter class suitable for documenting the given
object.

*obj* is the Python object to be documented, and *parent* is an
another Python object (e.g. a module or a class) to which *obj*
belongs to.
"""
if SPHINX_LT_8_3:
from sphinx.ext.autosummary import get_documenter

retval = get_documenter(app, obj, parent)

else:
from sphinx.ext.autosummary import _get_documenter

obj_type = _get_documenter(obj, parent)
retval = app.registry.documenters[obj_type]

return retval
Loading