Skip to content

Commit 77be352

Browse files
Merge branch 'main' into autoproperty
2 parents f6565c0 + 77a0e29 commit 77be352

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ zip_safe = False
2020
packages = find:
2121
python_requires = >=3.8
2222
install_requires =
23+
packaging
2324
sphinx>=4
2425

2526
[options.extras_require]

sphinx_automodapi/automodsumm.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,19 @@ class members that are inherited from a base class. This value can be
104104
import os
105105
import re
106106

107+
import sphinx
108+
from docutils.parsers.rst.directives import flag
109+
from packaging.version import Version
107110
from sphinx.util import logging
108111
from sphinx.ext.autosummary import Autosummary
109112
from sphinx.ext.inheritance_diagram import InheritanceDiagram, InheritanceGraph, try_import
110-
from docutils.parsers.rst.directives import flag
111113

112114
from .utils import find_mod_objs, cleanup_whitespace
113115

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

118121

119122
def _str_list_converter(argument):
@@ -272,15 +275,24 @@ def run(self):
272275

273276
old_generate_dot = InheritanceGraph.generate_dot
274277

275-
276-
def patched_generate_dot(self, name, urls={}, env=None,
277-
graph_attrs={}, node_attrs={}, edge_attrs={}):
278-
# Make a new mapping dictionary that uses class full names by importing each
279-
# class documented name
280-
fullname_urls = {self.class_name(try_import(name), 0, None): url
281-
for name, url in urls.items() if try_import(name) is not None}
282-
return old_generate_dot(self, name, urls=fullname_urls, env=env,
283-
graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)
278+
if SPHINX_LT_8_2:
279+
def patched_generate_dot(self, name, urls={}, env=None,
280+
graph_attrs={}, node_attrs={}, edge_attrs={}):
281+
# Make a new mapping dictionary that uses class full names by importing each
282+
# class documented name
283+
fullname_urls = {self.class_name(try_import(name), 0, None): url
284+
for name, url in urls.items() if try_import(name) is not None}
285+
return old_generate_dot(self, name, urls=fullname_urls, env=env,
286+
graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)
287+
else:
288+
def patched_generate_dot(self, name, urls={}, config=None,
289+
graph_attrs={}, node_attrs={}, edge_attrs={}):
290+
# Make a new mapping dictionary that uses class full names by importing each
291+
# class documented name
292+
fullname_urls = {self.class_name(try_import(name), 0, None): url
293+
for name, url in urls.items() if try_import(name) is not None}
294+
return old_generate_dot(self, name, urls=fullname_urls, config=config,
295+
graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)
284296

285297

286298
InheritanceGraph.generate_dot = patched_generate_dot
@@ -539,9 +551,7 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
539551

540552
new_files.append(fn)
541553

542-
f = open(fn, 'w', encoding='utf8')
543-
544-
try:
554+
with open(fn, 'w', encoding='utf8') as f:
545555

546556
doc = get_documenter(app, obj, parent)
547557

@@ -688,8 +698,6 @@ def get_members_class(obj, typ, include_public=[],
688698

689699
rendered = template.render(**ns)
690700
f.write(cleanup_whitespace(rendered))
691-
finally:
692-
f.close()
693701

694702

695703
def setup(app):

0 commit comments

Comments
 (0)