Skip to content

Commit

Permalink
Merge branch 'main' into autoproperty
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Jan 10, 2025
2 parents f6565c0 + 77a0e29 commit 77be352
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ zip_safe = False
packages = find:
python_requires = >=3.8
install_requires =
packaging
sphinx>=4

[options.extras_require]
Expand Down
38 changes: 23 additions & 15 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,19 @@ class members that are inherited from a base class. This value can be
import os
import re

import sphinx
from docutils.parsers.rst.directives import flag
from packaging.version import Version
from sphinx.util import logging
from sphinx.ext.autosummary import Autosummary
from sphinx.ext.inheritance_diagram import InheritanceDiagram, InheritanceGraph, try_import
from docutils.parsers.rst.directives import flag

from .utils import find_mod_objs, cleanup_whitespace

__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")


def _str_list_converter(argument):
Expand Down Expand Up @@ -272,15 +275,24 @@ def run(self):

old_generate_dot = InheritanceGraph.generate_dot


def patched_generate_dot(self, name, urls={}, env=None,
graph_attrs={}, node_attrs={}, edge_attrs={}):
# Make a new mapping dictionary that uses class full names by importing each
# class documented name
fullname_urls = {self.class_name(try_import(name), 0, None): url
for name, url in urls.items() if try_import(name) is not None}
return old_generate_dot(self, name, urls=fullname_urls, env=env,
graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)
if SPHINX_LT_8_2:
def patched_generate_dot(self, name, urls={}, env=None,
graph_attrs={}, node_attrs={}, edge_attrs={}):
# Make a new mapping dictionary that uses class full names by importing each
# class documented name
fullname_urls = {self.class_name(try_import(name), 0, None): url
for name, url in urls.items() if try_import(name) is not None}
return old_generate_dot(self, name, urls=fullname_urls, env=env,
graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)
else:
def patched_generate_dot(self, name, urls={}, config=None,
graph_attrs={}, node_attrs={}, edge_attrs={}):
# Make a new mapping dictionary that uses class full names by importing each
# class documented name
fullname_urls = {self.class_name(try_import(name), 0, None): url
for name, url in urls.items() if try_import(name) is not None}
return old_generate_dot(self, name, urls=fullname_urls, config=config,
graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)


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

new_files.append(fn)

f = open(fn, 'w', encoding='utf8')

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

doc = get_documenter(app, obj, parent)

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

rendered = template.render(**ns)
f.write(cleanup_whitespace(rendered))
finally:
f.close()


def setup(app):
Expand Down

0 comments on commit 77be352

Please sign in to comment.