Skip to content

Commit a8ba35c

Browse files
committed
RF: Use consistent dot file renaming scheme
1 parent a2d054a commit a8ba35c

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

nipype/pipeline/engine/utils.py

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,55 +1279,58 @@ def export_graph(graph_in,
12791279
base_dir = os.getcwd()
12801280

12811281
makedirs(base_dir, exist_ok=True)
1282-
outfname = fname_presuffix(
1282+
out_dot = fname_presuffix(
12831283
dotfilename, suffix='_detailed.dot', use_ext=False, newpath=base_dir)
1284-
_write_detailed_dot(graph, outfname)
1285-
if format != 'dot':
1286-
cmd = 'dot -T%s -O %s' % (format, outfname)
1287-
res = CommandLine(
1288-
cmd, terminal_output='allatonce', resource_monitor=False).run()
1289-
if res.runtime.returncode:
1290-
logger.warning('dot2png: %s', res.runtime.stderr)
1284+
_write_detailed_dot(graph, out_dot)
1285+
1286+
# Convert .dot if format != 'dot'
1287+
outfname, res = _run_dot(out_dot, format_ext=format)
1288+
if res is not None and res.runtime.returncode:
1289+
logger.warning('dot2png: %s', res.runtime.stderr)
1290+
12911291
pklgraph = _create_dot_graph(graph, show_connectinfo, simple_form)
1292-
simplefname = fname_presuffix(
1292+
simple_dot = fname_presuffix(
12931293
dotfilename, suffix='.dot', use_ext=False, newpath=base_dir)
1294-
nx.drawing.nx_pydot.write_dot(pklgraph, simplefname)
1295-
if format != 'dot':
1296-
cmd = 'dot -T%s -O %s' % (format, simplefname)
1297-
res = CommandLine(
1298-
cmd, terminal_output='allatonce', resource_monitor=False).run()
1299-
if res.runtime.returncode:
1300-
logger.warning('dot2png: %s', res.runtime.stderr)
1294+
nx.drawing.nx_pydot.write_dot(pklgraph, simple_dot)
1295+
1296+
# Convert .dot if format != 'dot'
1297+
simplefname, res = _run_dot(simple_dot, format_ext=format)
1298+
if res is not None and res.runtime.returncode:
1299+
logger.warning('dot2png: %s', res.runtime.stderr)
1300+
13011301
if show:
13021302
pos = nx.graphviz_layout(pklgraph, prog='dot')
13031303
nx.draw(pklgraph, pos)
13041304
if show_connectinfo:
13051305
nx.draw_networkx_edge_labels(pklgraph, pos)
13061306

1307-
if format != 'dot':
1308-
outfname += '.%s' % format
1309-
simplefname += '.%s' % format
13101307
return simplefname if simple_form else outfname
13111308

13121309

13131310
def format_dot(dotfilename, format='png'):
13141311
"""Dump a directed graph (Linux only; install via `brew` on OSX)"""
1315-
if format != 'dot':
1316-
dot_base = os.path.splitext(dotfilename)[0]
1317-
formatted_dot = '{}.{}'.format(dot_base, format)
1318-
cmd = 'dot -T{} -o"{}" "{}"'.format(format, formatted_dot, dotfilename)
1319-
try:
1320-
CommandLine(cmd, resource_monitor=False).run()
1321-
except IOError as ioe:
1322-
if "could not be found" in str(ioe):
1323-
raise IOError("Cannot draw directed graph; executable 'dot' is unavailable")
1324-
else:
1325-
raise ioe
1326-
else:
1327-
formatted_dot = dotfilename
1312+
try:
1313+
formatted_dot, _ = _run_dot(dotfilename, format_ext=format)
1314+
except IOError as ioe:
1315+
if "could not be found" in str(ioe):
1316+
raise IOError("Cannot draw directed graph; executable 'dot' is unavailable")
1317+
else:
1318+
raise ioe
13281319
return formatted_dot
13291320

13301321

1322+
def _run_dot(dotfilename, format_ext):
1323+
if format_ext == 'dot':
1324+
return dotfilename, None
1325+
1326+
dot_base = os.path.splitext(dotfilename)[0]
1327+
formatted_dot = '{}.{}'.format(dot_base, format)
1328+
cmd = 'dot -T{} -o"{}" "{}"'.format(format, formatted_dot, dotfilename)
1329+
res = CommandLine(cmd, terminal_output='allatonce',
1330+
resource_monitor=False).run()
1331+
return formatted_dot, res
1332+
1333+
13311334
def get_all_files(infile):
13321335
files = [infile]
13331336
if infile.endswith(".img"):

0 commit comments

Comments
 (0)