mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #656: Add `graphviz_dot
option to graphviz directives to switch the
dot
` command
This commit is contained in:
parent
388ee36d9f
commit
4c4450d958
1
CHANGES
1
CHANGES
@ -42,6 +42,7 @@ Features added
|
|||||||
* #1030: Make page reference names for latex_show_pagerefs translatable
|
* #1030: Make page reference names for latex_show_pagerefs translatable
|
||||||
* #2162: Add Sphinx.add_source_parser() to add source_suffix and source_parsers from extension
|
* #2162: Add Sphinx.add_source_parser() to add source_suffix and source_parsers from extension
|
||||||
* #2207: Add sphinx.parsers.Parser class; a base class for new parsers
|
* #2207: Add sphinx.parsers.Parser class; a base class for new parsers
|
||||||
|
* #656: Add ``graphviz_dot`` option to graphviz directives to switch the ``dot`` command
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -87,6 +87,10 @@ It adds these directives:
|
|||||||
caption to the diagram. Naturally, diagrams marked as "inline" cannot have a
|
caption to the diagram. Naturally, diagrams marked as "inline" cannot have a
|
||||||
caption.
|
caption.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.4
|
||||||
|
All three directives support a ``graphviz_dot`` option that can be switch the
|
||||||
|
``dot`` command within the directive.
|
||||||
|
|
||||||
There are also these new config values:
|
There are also these new config values:
|
||||||
|
|
||||||
.. confval:: graphviz_dot
|
.. confval:: graphviz_dot
|
||||||
|
@ -66,6 +66,7 @@ class Graphviz(Directive):
|
|||||||
'alt': directives.unchanged,
|
'alt': directives.unchanged,
|
||||||
'inline': directives.flag,
|
'inline': directives.flag,
|
||||||
'caption': directives.unchanged,
|
'caption': directives.unchanged,
|
||||||
|
'graphviz_dot': directives.unchanged,
|
||||||
}
|
}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -96,7 +97,9 @@ class Graphviz(Directive):
|
|||||||
line=self.lineno)]
|
line=self.lineno)]
|
||||||
node = graphviz()
|
node = graphviz()
|
||||||
node['code'] = dotcode
|
node['code'] = dotcode
|
||||||
node['options'] = []
|
node['options'] = {}
|
||||||
|
if 'graphviz_dot' in self.options:
|
||||||
|
node['options']['graphviz_dot'] = self.options['graphviz_dot']
|
||||||
if 'alt' in self.options:
|
if 'alt' in self.options:
|
||||||
node['alt'] = self.options['alt']
|
node['alt'] = self.options['alt']
|
||||||
if 'inline' in self.options:
|
if 'inline' in self.options:
|
||||||
@ -121,13 +124,16 @@ class GraphvizSimple(Directive):
|
|||||||
'alt': directives.unchanged,
|
'alt': directives.unchanged,
|
||||||
'inline': directives.flag,
|
'inline': directives.flag,
|
||||||
'caption': directives.unchanged,
|
'caption': directives.unchanged,
|
||||||
|
'graphviz_dot': directives.unchanged,
|
||||||
}
|
}
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
node = graphviz()
|
node = graphviz()
|
||||||
node['code'] = '%s %s {\n%s\n}\n' % \
|
node['code'] = '%s %s {\n%s\n}\n' % \
|
||||||
(self.name, self.arguments[0], '\n'.join(self.content))
|
(self.name, self.arguments[0], '\n'.join(self.content))
|
||||||
node['options'] = []
|
node['options'] = {}
|
||||||
|
if 'graphviz_dot' in self.options:
|
||||||
|
node['options']['graphviz_dot'] = self.options['graphviz_dot']
|
||||||
if 'alt' in self.options:
|
if 'alt' in self.options:
|
||||||
node['alt'] = self.options['alt']
|
node['alt'] = self.options['alt']
|
||||||
if 'inline' in self.options:
|
if 'inline' in self.options:
|
||||||
@ -142,8 +148,8 @@ class GraphvizSimple(Directive):
|
|||||||
|
|
||||||
def render_dot(self, code, options, format, prefix='graphviz'):
|
def render_dot(self, code, options, format, prefix='graphviz'):
|
||||||
"""Render graphviz code into a PNG or PDF output file."""
|
"""Render graphviz code into a PNG or PDF output file."""
|
||||||
hashkey = (code + str(options) +
|
graphviz_dot = options.get('graphviz_dot', self.builder.config.graphviz_dot)
|
||||||
str(self.builder.config.graphviz_dot) +
|
hashkey = (code + str(options) + str(graphviz_dot) +
|
||||||
str(self.builder.config.graphviz_dot_args)).encode('utf-8')
|
str(self.builder.config.graphviz_dot_args)).encode('utf-8')
|
||||||
|
|
||||||
fname = '%s-%s.%s' % (prefix, sha1(hashkey).hexdigest(), format)
|
fname = '%s-%s.%s' % (prefix, sha1(hashkey).hexdigest(), format)
|
||||||
@ -153,7 +159,8 @@ def render_dot(self, code, options, format, prefix='graphviz'):
|
|||||||
if path.isfile(outfn):
|
if path.isfile(outfn):
|
||||||
return relfn, outfn
|
return relfn, outfn
|
||||||
|
|
||||||
if hasattr(self.builder, '_graphviz_warned_dot'):
|
if (hasattr(self.builder, '_graphviz_warned_dot') and
|
||||||
|
self.builder._graphviz_warned_dot[graphviz_dot]):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
ensuredir(path.dirname(outfn))
|
ensuredir(path.dirname(outfn))
|
||||||
@ -162,9 +169,8 @@ def render_dot(self, code, options, format, prefix='graphviz'):
|
|||||||
if isinstance(code, text_type):
|
if isinstance(code, text_type):
|
||||||
code = code.encode('utf-8')
|
code = code.encode('utf-8')
|
||||||
|
|
||||||
dot_args = [self.builder.config.graphviz_dot]
|
dot_args = [graphviz_dot]
|
||||||
dot_args.extend(self.builder.config.graphviz_dot_args)
|
dot_args.extend(self.builder.config.graphviz_dot_args)
|
||||||
dot_args.extend(options)
|
|
||||||
dot_args.extend(['-T' + format, '-o' + outfn])
|
dot_args.extend(['-T' + format, '-o' + outfn])
|
||||||
if format == 'png':
|
if format == 'png':
|
||||||
dot_args.extend(['-Tcmapx', '-o%s.map' % outfn])
|
dot_args.extend(['-Tcmapx', '-o%s.map' % outfn])
|
||||||
@ -174,9 +180,10 @@ def render_dot(self, code, options, format, prefix='graphviz'):
|
|||||||
if err.errno != ENOENT: # No such file or directory
|
if err.errno != ENOENT: # No such file or directory
|
||||||
raise
|
raise
|
||||||
self.builder.warn('dot command %r cannot be run (needed for graphviz '
|
self.builder.warn('dot command %r cannot be run (needed for graphviz '
|
||||||
'output), check the graphviz_dot setting' %
|
'output), check the graphviz_dot setting' % graphviz_dot)
|
||||||
self.builder.config.graphviz_dot)
|
if not hasattr(self.builder, '_graphviz_warned_dot'):
|
||||||
self.builder._graphviz_warned_dot = True
|
self.builder._graphviz_warned_dot = {}
|
||||||
|
self.builder._graphviz_warned_dot[graphviz_dot] = True
|
||||||
return None, None
|
return None, None
|
||||||
try:
|
try:
|
||||||
# Graphviz may close standard input when an error occurs,
|
# Graphviz may close standard input when an error occurs,
|
||||||
|
@ -11,3 +11,8 @@ graphviz
|
|||||||
bar -> baz
|
bar -> baz
|
||||||
|
|
||||||
Hello |graph| graphviz world
|
Hello |graph| graphviz world
|
||||||
|
|
||||||
|
.. digraph:: foo
|
||||||
|
:graphviz_dot: neato
|
||||||
|
|
||||||
|
bar -> baz
|
||||||
|
Loading…
Reference in New Issue
Block a user