Skip to content

Commit 0547f67

Browse files
authored
Merge pull request nipy#1896 from oesteban/enh/SphinxExtension-workflows
[ENH] Sphinx extension to plot workflows
2 parents c6d24b8 + 1f6335b commit 0547f67

File tree

10 files changed

+769
-17
lines changed

10 files changed

+769
-17
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Upcoming Release
22
=====================
33

4+
* ENH: Sphinx extension to plot workflows (https://github.com/nipy/nipype/pull/1896)
45
* ENH: Added non-steady state detector for EPI data (https://github.com/nipy/nipype/pull/1839)
56
* ENH: Enable new BBRegister init options for FSv6+ (https://github.com/nipy/nipype/pull/1811)
67
* REF: Splits nipype.interfaces.utility into base, csv, and wrappers (https://github.com/nipy/nipype/pull/1828)
@@ -22,7 +23,7 @@ Upcoming Release
2223

2324
0.13.0-rc1 (January 4, 2017)
2425
===============================
25-
26+
2627
* FIX: Compatibility with traits 4.6 (https://github.com/nipy/nipype/pull/1770)
2728
* FIX: Multiproc deadlock (https://github.com/nipy/nipype/pull/1756)
2829
* TST: Replace nose and unittest with pytest (https://github.com/nipy/nipype/pull/1722, https://github.com/nipy/nipype/pull/1751)

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@
4242
# Add any Sphinx extension module names here, as strings. They can be extensions
4343
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
4444
extensions = ['sphinx.ext.todo',
45-
'sphinx.ext.pngmath',
45+
'sphinx.ext.imgmath',
4646
'sphinx.ext.inheritance_diagram',
4747
'sphinx.ext.graphviz',
4848
'sphinx.ext.autodoc',
4949
'sphinx.ext.doctest',
50-
'sphinx.ext.pngmath',
5150
'sphinx.ext.autosummary',
5251
'numpy_ext.numpydoc',
5352
'matplotlib.sphinxext.plot_directive',
5453
'matplotlib.sphinxext.only_directives',
54+
'nipype.sphinxext.plot_workflow',
5555
#'IPython.sphinxext.ipython_directive',
5656
#'IPython.sphinxext.ipython_console_highlighting'
5757
]

doc/documentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ Previous versions: `0.12.0 <http://nipype.readthedocs.io/en/0.12.0/>`_ `0.11.0
2424
:maxdepth: 2
2525

2626
users/index
27+
2728
.. toctree::
2829
:maxdepth: 1
2930

3031
changes
32+
3133
* Developer
3234

3335
.. toctree::

doc/users/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
mipav
4040
nipypecmd
4141
aws
42+
resource_sched_profiler
43+
sphinx_ext
4244

4345

4446

doc/users/sphinx_ext.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
.. _sphinx_ext:
3+
4+
Sphinx extensions
5+
-----------------
6+
7+
8+
To help users document their *Nipype*-based code, the software is shipped
9+
with a set of extensions (currently only one) to customize the appearance
10+
and simplify the generation process.
11+
12+
.. automodule:: nipype.sphinxext.plot_workflow
13+
:undoc-members:
14+
:noindex:

nipype/info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def get_nipype_gitversion():
152152
]
153153

154154
EXTRA_REQUIRES = {
155-
'doc': ['Sphinx>=0.3', 'matplotlib', 'pydotplus'],
155+
'doc': ['Sphinx>=1.4', 'matplotlib', 'pydotplus'],
156156
'tests': TESTS_REQUIRES,
157157
'fmri': ['nitime', 'nilearn', 'dipy', 'nipy', 'matplotlib'],
158158
'profiler': ['psutil'],

nipype/pipeline/engine/utils.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,20 +1018,18 @@ def export_graph(graph_in, base_dir=None, show=False, use_execgraph=False,
10181018
suffix='_detailed.dot',
10191019
use_ext=False,
10201020
newpath=base_dir)
1021-
logger.info('Creating detailed dot file: %s' % outfname)
10221021
_write_detailed_dot(graph, outfname)
10231022
cmd = 'dot -T%s -O %s' % (format, outfname)
10241023
res = CommandLine(cmd, terminal_output='allatonce').run()
10251024
if res.runtime.returncode:
10261025
logger.warn('dot2png: %s', res.runtime.stderr)
10271026
pklgraph = _create_dot_graph(graph, show_connectinfo, simple_form)
1028-
outfname = fname_presuffix(dotfilename,
1029-
suffix='.dot',
1030-
use_ext=False,
1031-
newpath=base_dir)
1032-
nx.drawing.nx_pydot.write_dot(pklgraph, outfname)
1033-
logger.info('Creating dot file: %s' % outfname)
1034-
cmd = 'dot -T%s -O %s' % (format, outfname)
1027+
simplefname = fname_presuffix(dotfilename,
1028+
suffix='.dot',
1029+
use_ext=False,
1030+
newpath=base_dir)
1031+
nx.drawing.nx_pydot.write_dot(pklgraph, simplefname)
1032+
cmd = 'dot -T%s -O %s' % (format, simplefname)
10351033
res = CommandLine(cmd, terminal_output='allatonce').run()
10361034
if res.runtime.returncode:
10371035
logger.warn('dot2png: %s', res.runtime.stderr)
@@ -1041,6 +1039,10 @@ def export_graph(graph_in, base_dir=None, show=False, use_execgraph=False,
10411039
if show_connectinfo:
10421040
nx.draw_networkx_edge_labels(pklgraph, pos)
10431041

1042+
if format != 'dot':
1043+
outfname += '.%s' % format
1044+
return outfname
1045+
10441046

10451047
def format_dot(dotfilename, format=None):
10461048
"""Dump a directed graph (Linux only; install via `brew` on OSX)"""
@@ -1052,8 +1054,10 @@ def format_dot(dotfilename, format=None):
10521054
raise IOError("Cannot draw directed graph; executable 'dot' is unavailable")
10531055
else:
10541056
raise ioe
1055-
else:
1056-
logger.info('Converting dotfile: %s to %s format' % (dotfilename, format))
1057+
1058+
if format != 'dot':
1059+
dotfilename += '.%s' % format
1060+
return dotfilename
10571061

10581062

10591063
def make_output_dir(outdir):

nipype/pipeline/engine/workflows.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,19 @@ def write_graph(self, dotfilename='graph.dot', graph2use='hierarchical',
429429
self.write_hierarchical_dotfile(dotfilename=dotfilename,
430430
colored=graph2use == "colored",
431431
simple_form=simple_form)
432-
format_dot(dotfilename, format=format)
432+
outfname = format_dot(dotfilename, format=format)
433433
else:
434434
graph = self._graph
435435
if graph2use in ['flat', 'exec']:
436436
graph = self._create_flat_graph()
437437
if graph2use == 'exec':
438438
graph = generate_expanded_graph(deepcopy(graph))
439-
export_graph(graph, base_dir, dotfilename=dotfilename,
440-
format=format, simple_form=simple_form)
439+
outfname = export_graph(graph, base_dir, dotfilename=dotfilename,
440+
format=format, simple_form=simple_form)
441+
442+
logger.info('Generated workflow graph: %s (graph2use=%s, simple_form=%s).' % (
443+
outfname, graph2use, simple_form))
444+
return outfname
441445

442446
def write_hierarchical_dotfile(self, dotfilename=None, colored=False,
443447
simple_form=True):

nipype/sphinxext/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
4+
# vi: set ft=python sts=4 ts=4 sw=4 et:
5+
from __future__ import print_function, division, absolute_import, unicode_literals

0 commit comments

Comments
 (0)