@@ -104,16 +104,19 @@ class members that are inherited from a base class. This value can be
104
104
import os
105
105
import re
106
106
107
+ import sphinx
108
+ from docutils .parsers .rst .directives import flag
109
+ from packaging .version import Version
107
110
from sphinx .util import logging
108
111
from sphinx .ext .autosummary import Autosummary
109
112
from sphinx .ext .inheritance_diagram import InheritanceDiagram , InheritanceGraph , try_import
110
- from docutils .parsers .rst .directives import flag
111
113
112
114
from .utils import find_mod_objs , cleanup_whitespace
113
115
114
116
__all__ = ['Automoddiagram' , 'Automodsumm' , 'automodsumm_to_autosummary_lines' ,
115
117
'generate_automodsumm_docs' , 'process_automodsumm_generation' ]
116
118
logger = logging .getLogger (__name__ )
119
+ SPHINX_LT_8_2 = Version (sphinx .__version__ ) < Version ("8.2.dev" )
117
120
118
121
119
122
def _str_list_converter (argument ):
@@ -272,15 +275,24 @@ def run(self):
272
275
273
276
old_generate_dot = InheritanceGraph .generate_dot
274
277
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 )
284
296
285
297
286
298
InheritanceGraph .generate_dot = patched_generate_dot
@@ -539,9 +551,7 @@ def generate_automodsumm_docs(lines, srcfn, app=None, suffix='.rst',
539
551
540
552
new_files .append (fn )
541
553
542
- f = open (fn , 'w' , encoding = 'utf8' )
543
-
544
- try :
554
+ with open (fn , 'w' , encoding = 'utf8' ) as f :
545
555
546
556
doc = get_documenter (app , obj , parent )
547
557
@@ -688,8 +698,6 @@ def get_members_class(obj, typ, include_public=[],
688
698
689
699
rendered = template .render (** ns )
690
700
f .write (cleanup_whitespace (rendered ))
691
- finally :
692
- f .close ()
693
701
694
702
695
703
def setup (app ):
0 commit comments