@@ -272,12 +272,16 @@ class inheritance_diagram(Body, Element):
272272 """
273273 pass
274274
275- def inheritance_diagram_directive_run (class_names , options , state ):
275+ def inheritance_diagram_directive (name , arguments , options , content , lineno ,
276+ content_offset , block_text , state ,
277+ state_machine ):
276278 """
277279 Run when the inheritance_diagram directive is first encountered.
278280 """
279281 node = inheritance_diagram ()
280282
283+ class_names = arguments
284+
281285 # Create a graph starting with the list of classes
282286 graph = InheritanceGraph (class_names )
283287
@@ -310,15 +314,12 @@ def html_output_graph(self, node):
310314
311315 graph_hash = get_graph_hash (node )
312316 name = "inheritance%s" % graph_hash
313- png_path = os .path .join ('_static' , name + ".png" )
314-
315- path = '_static'
316- source = self .document .attributes ['source' ]
317- count = source .split ('/doc/' )[- 1 ].count ('/' )
318- for i in range (count ):
319- if os .path .exists (path ): break
320- path = '../' + path
321- path = '../' + path #specifically added for matplotlib
317+ path = '_images'
318+ dest_path = os .path .join (setup .app .builder .outdir , path )
319+ if not os .path .exists (dest_path ):
320+ os .makedirs (dest_path )
321+ png_path = os .path .join (dest_path , name + ".png" )
322+ path = setup .app .builder .imgpath
322323
323324 # Create a mapping from fully-qualified class names to URLs.
324325 urls = {}
@@ -344,11 +345,14 @@ def latex_output_graph(self, node):
344345
345346 graph_hash = get_graph_hash (node )
346347 name = "inheritance%s" % graph_hash
347- pdf_path = os .path .join ('_static' , name + ".pdf" )
348+ dest_path = os .path .abspath (os .path .join (setup .app .builder .outdir , '_images' ))
349+ if not os .path .exists (dest_path ):
350+ os .makedirs (dest_path )
351+ pdf_path = os .path .abspath (os .path .join (dest_path , name + ".pdf" ))
348352
349353 graph .run_dot (['-Tpdf' , '-o%s' % pdf_path ],
350354 name , parts , graph_options = {'size' : '"6.0,6.0"' })
351- return '\\ includegraphics{../../ %s}' % pdf_path
355+ return '\\ includegraphics{%s}' % pdf_path
352356
353357def visit_inheritance_diagram (inner_func ):
354358 """
@@ -372,44 +376,14 @@ def visitor(self, node):
372376def do_nothing (self , node ):
373377 pass
374378
375- options_spec = {
376- 'parts' : directives .nonnegative_int
377- }
378-
379- # Deal with the old and new way of registering directives
380- try :
381- from docutils .parsers .rst import Directive
382- except ImportError :
383- from docutils .parsers .rst .directives import _directives
384- def inheritance_diagram_directive (name , arguments , options , content , lineno ,
385- content_offset , block_text , state ,
386- state_machine ):
387- return inheritance_diagram_directive_run (arguments , options , state )
388- inheritance_diagram_directive .__doc__ = __doc__
389- inheritance_diagram_directive .arguments = (1 , 100 , 0 )
390- inheritance_diagram_directive .options = options_spec
391- inheritance_diagram_directive .content = 0
392- _directives ['inheritance-diagram' ] = inheritance_diagram_directive
393- else :
394- class inheritance_diagram_directive (Directive ):
395- has_content = False
396- required_arguments = 1
397- optional_arguments = 100
398- final_argument_whitespace = False
399- option_spec = options_spec
400-
401- def run (self ):
402- return inheritance_diagram_directive_run (
403- self .arguments , self .options , self .state )
404- inheritance_diagram_directive .__doc__ = __doc__
405-
406- directives .register_directive ('inheritance-diagram' ,
407- inheritance_diagram_directive )
408-
409379def setup (app ):
410- app .add_node (inheritance_diagram ,
411- html = (visit_inheritance_diagram (html_output_graph ),
412- do_nothing ))
413- app .add_node (inheritance_diagram ,
414- latex = (visit_inheritance_diagram (latex_output_graph ),
415- do_nothing ))
380+ setup .app = app
381+ setup .confdir = app .confdir
382+
383+ app .add_node (
384+ inheritance_diagram ,
385+ latex = (visit_inheritance_diagram (latex_output_graph ), do_nothing ),
386+ html = (visit_inheritance_diagram (html_output_graph ), do_nothing ))
387+ app .add_directive (
388+ 'inheritance-diagram' , inheritance_diagram_directive ,
389+ False , (1 , 100 , 0 ), parts = directives .nonnegative_int )
0 commit comments