Skip to content

Commit 46c4db6

Browse files
authored
Merge pull request #224 from AA-Turner/cleanups
Fix incomplete cleanup in autodoc_enhancements.py
2 parents 0aa9864 + e15207f commit 46c4db6

File tree

3 files changed

+27
-44
lines changed

3 files changed

+27
-44
lines changed

sphinx_automodapi/autodoc_enhancements.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
"""
44
import dataclasses
55

6-
from sphinx.ext.autodoc import AttributeDocumenter
7-
86
__all__ = []
97

10-
class_types = (type,)
11-
MethodDescriptorType = type(type.__subclasses__)
12-
138

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

7267

7368
def setup(app):
74-
# Must have the autodoc extension set up first so we can override it
75-
app.setup_extension('sphinx.ext.autodoc')
76-
7769
app.add_autodoc_attrgetter(type, type_object_attrgetter)
7870

79-
suppress_warnings_orig = app.config.suppress_warnings[:]
80-
if 'app.add_directive' not in app.config.suppress_warnings:
81-
app.config.suppress_warnings.append('app.add_directive')
82-
try:
83-
app.add_autodocumenter(AttributeDocumenter)
84-
finally:
85-
app.config.suppress_warnings = suppress_warnings_orig
86-
8771
return {'parallel_read_safe': True,
8872
'parallel_write_safe': True}

sphinx_automodapi/automodsumm.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
487487
from jinja2.sandbox import SandboxedEnvironment
488488

489489
from .utils import find_autosummary_in_lines_for_automodsumm as find_autosummary_in_lines
490-
from .utils import get_documenter
490+
from .utils import get_object_type
491491

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

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

558-
doc = get_documenter(app, obj, parent)
558+
obj_type = get_object_type(app, obj, parent)
559559

560560
if template_name is not None:
561561
template = template_env.get_template(template_name)
562562
else:
563563
tmplstr = 'autosummary_core/%s.rst'
564564
try:
565-
template = template_env.get_template(tmplstr % doc.objtype)
565+
template = template_env.get_template(tmplstr % obj_type)
566566
except TemplateNotFound:
567567
template = template_env.get_template(tmplstr % 'base')
568568

@@ -573,10 +573,10 @@ def get_members_mod(obj, typ, include_public=[]):
573573
items = []
574574
for name in dir(obj):
575575
try:
576-
documenter = get_documenter(app, safe_getattr(obj, name), obj)
576+
obj_type = get_object_type(app, safe_getattr(obj, name), obj)
577577
except AttributeError:
578578
continue
579-
if typ is None or documenter.objtype == typ:
579+
if typ is None or obj_type == typ:
580580
items.append(name)
581581
public = [x for x in items
582582
if x in include_public or not x.startswith('_')]
@@ -604,36 +604,36 @@ def get_members_class(obj, typ, include_public=[],
604604

605605
for name in names:
606606
try:
607-
documenter = get_documenter(app, safe_getattr(obj, name), obj)
607+
obj_type = get_object_type(app, safe_getattr(obj, name), obj)
608608
except AttributeError:
609609
# for dataclasses try to get the attribute from the __dataclass_fields__
610610
if dataclasses.is_dataclass(obj):
611611
try:
612612
attr = obj.__dataclass_fields__[name]
613-
documenter = get_documenter(app, attr, obj)
613+
obj_type = get_object_type(app, attr, obj)
614614
except KeyError:
615615
continue
616-
if typ is None or documenter.objtype == typ:
616+
if typ is None or obj_type == typ:
617617
items.append(name)
618-
# elif typ == 'attribute' and documenter.objtype == 'property':
618+
# elif typ == 'attribute' and obj_type == 'property':
619619
# # In Sphinx 2.0 and above, properties have a separate
620-
# # objtype, but we treat them the same here.
620+
# # object type, but we treat them the same here.
621621
# items.append(name)
622622
public = [x for x in items
623623
if x in include_public or not x.startswith('_')]
624624
return public, items
625625

626626
ns = {}
627627

628-
if doc.objtype == 'module':
628+
if obj_type == 'module':
629629
ns['members'] = get_members_mod(obj, None)
630630
ns['functions'], ns['all_functions'] = \
631631
get_members_mod(obj, 'function')
632632
ns['classes'], ns['all_classes'] = \
633633
get_members_mod(obj, 'class')
634634
ns['exceptions'], ns['all_exceptions'] = \
635635
get_members_mod(obj, 'exception')
636-
elif doc.objtype == 'class':
636+
elif obj_type == 'class':
637637
if inherited_mem is not None:
638638
# option set in this specifc directive
639639
include_base = inherited_mem
@@ -662,7 +662,7 @@ def get_members_class(obj, typ, include_public=[],
662662
ns['attributes'].sort()
663663

664664
parts = name.split('.')
665-
if doc.objtype in ('method', 'attribute'):
665+
if obj_type in ('method', 'attribute'):
666666
mod_name = '.'.join(parts[:-2])
667667
cls_name = parts[-2]
668668
obj_name = '.'.join(parts[-2:])
@@ -676,7 +676,7 @@ def get_members_class(obj, typ, include_public=[],
676676
ns['objname'] = obj_name
677677
ns['name'] = parts[-1]
678678

679-
ns['objtype'] = doc.objtype
679+
ns['objtype'] = obj_type
680680
ns['underline'] = len(obj_name) * '='
681681

682682
# We now check whether a file for reference footnotes exists for

sphinx_automodapi/utils.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from sphinx.ext.autosummary.generate import find_autosummary_in_docstring
1010

1111
__all__ = ['cleanup_whitespace',
12-
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm',
13-
'get_documenter']
12+
'find_mod_objs',
13+
'find_autosummary_in_lines_for_automodsumm']
1414

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

@@ -234,11 +234,11 @@ def find_autosummary_in_lines_for_automodsumm(lines, module=None, filename=None)
234234
return documented
235235

236236

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.
237+
# sphinx-automodapi used to use sphinx.ext.autosummary.get_documenter()
238+
# from Sphinx proper, but the function was removed upstream in
239+
# https://github.com/sphinx-doc/sphinx/pull/13985.
240+
def get_object_type(app, obj, parent):
241+
"""Get the object type suitable for documenting the given object.
242242
243243
*obj* is the Python object to be documented, and *parent* is an
244244
another Python object (e.g. a module or a class) to which *obj*
@@ -247,12 +247,11 @@ def get_documenter(app, obj, parent):
247247
if SPHINX_LT_8_3:
248248
from sphinx.ext.autosummary import get_documenter
249249

250-
retval = get_documenter(app, obj, parent)
250+
documenter = get_documenter(app, obj, parent)
251+
obj_type = documenter.objtype
252+
return obj_type
251253

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]
254+
from sphinx.ext.autosummary import _get_documenter
257255

258-
return retval
256+
obj_type = _get_documenter(obj, parent)
257+
return obj_type

0 commit comments

Comments
 (0)