From 5c55cf2885a750e20c255178ef2fa604bdd28c2d Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:26:01 -0500 Subject: [PATCH 1/6] MNT: Remove unnecessary try-except --- sphinx_automodapi/automodsumm.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index 2ddb478..25316d7 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -532,9 +532,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) @@ -672,8 +670,6 @@ def get_members_class(obj, typ, include_public=[], rendered = template.render(**ns) f.write(cleanup_whitespace(rendered)) - finally: - f.close() def setup(app): From bdb90b2c90f7f15cb8cb4aff2cf7c4b8839c78c2 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:26:58 -0500 Subject: [PATCH 2/6] DEP: Require packaging --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 5a915e6..a4eec45 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,7 @@ zip_safe = False packages = find: python_requires = >=3.8 install_requires = + packaging sphinx>=4 [options.extras_require] From e44014873fddbe608b674f5be83fd32bb0a7b00a Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:33:50 -0500 Subject: [PATCH 3/6] Compat with sphinx 8.2 --- sphinx_automodapi/automodsumm.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index 25316d7..d02e0e0 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -99,16 +99,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): @@ -267,15 +270,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 From 3db2ea6d26c103a28e12e86fd9a1eab7539948c1 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:28:17 -0500 Subject: [PATCH 4/6] Fix op typo --- sphinx_automodapi/automodsumm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index d02e0e0..42bf292 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -111,7 +111,7 @@ class members that are inherited from a base class. This value can be __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") +SPHINX_LT_8_2 = Version(sphinx.__version__) < Version("8.2.dev") def _str_list_converter(argument): From b174a6f0bbe46589afe63c0da5809470c92ef981 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:24:11 -0500 Subject: [PATCH 5/6] patched_generate_dot now has asterisk in sig --- sphinx_automodapi/automodsumm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index 42bf292..4610ce9 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -271,7 +271,7 @@ def run(self): old_generate_dot = InheritanceGraph.generate_dot if SPHINX_LT_8_2: - def patched_generate_dot(self, name, urls={}, env=None, + 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 @@ -280,7 +280,7 @@ def patched_generate_dot(self, name, urls={}, env=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, + 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 From a054523ef2a556b719dd6238da99201f9de570a9 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:35:35 -0500 Subject: [PATCH 6/6] Revert because asterisk broke Sphinx --- sphinx_automodapi/automodsumm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sphinx_automodapi/automodsumm.py b/sphinx_automodapi/automodsumm.py index 4610ce9..42bf292 100644 --- a/sphinx_automodapi/automodsumm.py +++ b/sphinx_automodapi/automodsumm.py @@ -271,7 +271,7 @@ def run(self): old_generate_dot = InheritanceGraph.generate_dot if SPHINX_LT_8_2: - def patched_generate_dot(self, name, *, urls={}, env=None, + 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 @@ -280,7 +280,7 @@ def patched_generate_dot(self, name, *, urls={}, env=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, + 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