Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Sphinx 8.2, minor clean up #196

Merged
merged 6 commits into from
Jan 10, 2025
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
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 @@ -99,16 +99,19 @@
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 @@ -267,15 +270,24 @@

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at this, if possible, make the kwargs mandatory so the API change won't have any chances to bite us back.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it, though hopefully won't break downstream...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Check warning on line 283 in sphinx_automodapi/automodsumm.py

View check run for this annotation

Codecov / codecov/patch

sphinx_automodapi/automodsumm.py#L283

Added line #L283 was not covered by tests
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

Check warning on line 287 in sphinx_automodapi/automodsumm.py

View check run for this annotation

Codecov / codecov/patch

sphinx_automodapi/automodsumm.py#L287

Added line #L287 was not covered by tests
for name, url in urls.items() if try_import(name) is not None}
return old_generate_dot(self, name, urls=fullname_urls, config=config,

Check warning on line 289 in sphinx_automodapi/automodsumm.py

View check run for this annotation

Codecov / codecov/patch

sphinx_automodapi/automodsumm.py#L289

Added line #L289 was not covered by tests
graph_attrs=graph_attrs, node_attrs=node_attrs, edge_attrs=edge_attrs)


InheritanceGraph.generate_dot = patched_generate_dot
Expand Down Expand Up @@ -532,9 +544,7 @@

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 @@ -672,8 +682,6 @@

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


def setup(app):
Expand Down
Loading