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
16 changes: 0 additions & 16 deletions sphinx_automodapi/autodoc_enhancements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
"""
import dataclasses

from sphinx.ext.autodoc import AttributeDocumenter

__all__ = []

class_types = (type,)
MethodDescriptorType = type(type.__subclasses__)


# See
# https://github.com/astropy/astropy-helpers/issues/116#issuecomment-71254836
Expand Down Expand Up @@ -71,18 +66,7 @@ def type_object_attrgetter(obj, attr, *defargs):


def setup(app):
# Must have the autodoc extension set up first so we can override it
app.setup_extension('sphinx.ext.autodoc')

app.add_autodoc_attrgetter(type, type_object_attrgetter)

suppress_warnings_orig = app.config.suppress_warnings[:]
if 'app.add_directive' not in app.config.suppress_warnings:
app.config.suppress_warnings.append('app.add_directive')
try:
app.add_autodocumenter(AttributeDocumenter)
finally:
app.config.suppress_warnings = suppress_warnings_orig

return {'parallel_read_safe': True,
'parallel_write_safe': True}
28 changes: 14 additions & 14 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
from jinja2.sandbox import SandboxedEnvironment

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

# Create our own templating environment - here we use Astropy's
# templates rather than the default autosummary templates, in order to
Expand Down Expand Up @@ -555,14 +555,14 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',

with open(fn, 'w', encoding='utf8') as f:

doc = get_documenter(app, obj, parent)
obj_type = get_object_type(app, obj, parent)

if template_name is not None:
template = template_env.get_template(template_name)
else:
tmplstr = 'autosummary_core/%s.rst'
try:
template = template_env.get_template(tmplstr % doc.objtype)
template = template_env.get_template(tmplstr % obj_type)
except TemplateNotFound:
template = template_env.get_template(tmplstr % 'base')

Expand All @@ -573,10 +573,10 @@ def get_members_mod(obj, typ, include_public=[]):
items = []
for name in dir(obj):
try:
documenter = get_documenter(app, safe_getattr(obj, name), obj)
obj_type = get_object_type(app, safe_getattr(obj, name), obj)
except AttributeError:
continue
if typ is None or documenter.objtype == typ:
if typ is None or obj_type == typ:
items.append(name)
public = [x for x in items
if x in include_public or not x.startswith('_')]
Expand Down Expand Up @@ -604,36 +604,36 @@ def get_members_class(obj, typ, include_public=[],

for name in names:
try:
documenter = get_documenter(app, safe_getattr(obj, name), obj)
obj_type = get_object_type(app, safe_getattr(obj, name), obj)
except AttributeError:
# for dataclasses try to get the attribute from the __dataclass_fields__
if dataclasses.is_dataclass(obj):
try:
attr = obj.__dataclass_fields__[name]
documenter = get_documenter(app, attr, obj)
obj_type = get_object_type(app, attr, obj)
except KeyError:
continue
if typ is None or documenter.objtype == typ:
if typ is None or obj_type == typ:
items.append(name)
# elif typ == 'attribute' and documenter.objtype == 'property':
# elif typ == 'attribute' and obj_type == 'property':
# # In Sphinx 2.0 and above, properties have a separate
# # objtype, but we treat them the same here.
# # object type, but we treat them the same here.
# items.append(name)
public = [x for x in items
if x in include_public or not x.startswith('_')]
return public, items

ns = {}

if doc.objtype == 'module':
if obj_type == 'module':
ns['members'] = get_members_mod(obj, None)
ns['functions'], ns['all_functions'] = \
get_members_mod(obj, 'function')
ns['classes'], ns['all_classes'] = \
get_members_mod(obj, 'class')
ns['exceptions'], ns['all_exceptions'] = \
get_members_mod(obj, 'exception')
elif doc.objtype == 'class':
elif obj_type == 'class':
if inherited_mem is not None:
# option set in this specifc directive
include_base = inherited_mem
Expand Down Expand Up @@ -662,7 +662,7 @@ def get_members_class(obj, typ, include_public=[],
ns['attributes'].sort()

parts = name.split('.')
if doc.objtype in ('method', 'attribute'):
if obj_type in ('method', 'attribute'):
mod_name = '.'.join(parts[:-2])
cls_name = parts[-2]
obj_name = '.'.join(parts[-2:])
Expand All @@ -676,7 +676,7 @@ def get_members_class(obj, typ, include_public=[],
ns['objname'] = obj_name
ns['name'] = parts[-1]

ns['objtype'] = doc.objtype
ns['objtype'] = obj_type
ns['underline'] = len(obj_name) * '='

# We now check whether a file for reference footnotes exists for
Expand Down
27 changes: 13 additions & 14 deletions sphinx_automodapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from sphinx.ext.autosummary.generate import find_autosummary_in_docstring

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

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

Expand Down Expand Up @@ -234,11 +234,11 @@ def find_autosummary_in_lines_for_automodsumm(lines, module=None, filename=None)
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.
# sphinx-automodapi used to use sphinx.ext.autosummary.get_documenter()
# from Sphinx proper, but the function was removed upstream in
# https://github.com/sphinx-doc/sphinx/pull/13985.
def get_object_type(app, obj, parent):
"""Get the object type 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*
Expand All @@ -247,12 +247,11 @@ def get_documenter(app, obj, parent):
if SPHINX_LT_8_3:
from sphinx.ext.autosummary import get_documenter

retval = get_documenter(app, obj, parent)
documenter = get_documenter(app, obj, parent)
obj_type = documenter.objtype
return obj_type

else:
from sphinx.ext.autosummary import _get_documenter

obj_type = _get_documenter(obj, parent)
retval = app.registry.documenters[obj_type]
from sphinx.ext.autosummary import _get_documenter

return retval
obj_type = _get_documenter(obj, parent)
return obj_type
Loading