Skip to content

Commit 15b13ea

Browse files
committed
pep8 fixups
1 parent 7e66b04 commit 15b13ea

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

nipype/pipeline/engine/utils.py

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,24 @@
44
"""Utility routines for workflow graphs
55
"""
66
from __future__ import print_function, division, unicode_literals, absolute_import
7-
from builtins import str, open, map, next, zip, range
7+
from builtins import str, open, next, zip, range
88

9+
import os
910
import sys
10-
from future import standard_library
11-
standard_library.install_aliases()
11+
import pickle
1212
from collections import defaultdict
13-
13+
import re
1414
from copy import deepcopy
1515
from glob import glob
16+
from distutils.version import LooseVersion
17+
1618
try:
1719
from inspect import signature
1820
except ImportError:
1921
from funcsigs import signature
2022

21-
import os
22-
import re
23-
import pickle
2423
from functools import reduce
2524
import numpy as np
26-
from distutils.version import LooseVersion
27-
2825
import networkx as nx
2926

3027
from ...utils.filemanip import (fname_presuffix, FileNotFoundError, to_str,
@@ -37,6 +34,9 @@
3734
from ...utils.provenance import ProvStore, pm, nipype_ns, get_id
3835

3936
from ... import logging, config
37+
from future import standard_library
38+
39+
standard_library.install_aliases()
4040
logger = logging.getLogger('workflow')
4141
PY3 = sys.version_info[0] > 2
4242

@@ -262,8 +262,6 @@ def _write_detailed_dot(graph, dotfilename):
262262
text = ['digraph structs {', 'node [shape=record];']
263263
# write nodes
264264
edges = []
265-
replacefunk = lambda x: x.replace('_', '').replace('.', ''). \
266-
replace('@', '').replace('-', '')
267265
for n in nx.topological_sort(graph):
268266
nodename = str(n)
269267
inports = []
@@ -274,18 +272,16 @@ def _write_detailed_dot(graph, dotfilename):
274272
else:
275273
outport = cd[0][0]
276274
inport = cd[1]
277-
ipstrip = 'in' + replacefunk(inport)
278-
opstrip = 'out' + replacefunk(outport)
275+
ipstrip = 'in%s' % _replacefunk(inport)
276+
opstrip = 'out%s' % _replacefunk(outport)
279277
edges.append('%s:%s:e -> %s:%s:w;' % (str(u).replace('.', ''),
280278
opstrip,
281279
str(v).replace('.', ''),
282280
ipstrip))
283281
if inport not in inports:
284282
inports.append(inport)
285-
inputstr = '{IN'
286-
for ip in sorted(inports):
287-
inputstr += '|<in%s> %s' % (replacefunk(ip), ip)
288-
inputstr += '}'
283+
inputstr = ['{IN'] + ['|<in%s> %s' % (_replacefunk(ip), ip)
284+
for ip in sorted(inports)] + ['}']
289285
outports = []
290286
for u, v, d in graph.out_edges(nbunch=n, data=True):
291287
for cd in d['connect']:
@@ -295,10 +291,8 @@ def _write_detailed_dot(graph, dotfilename):
295291
outport = cd[0][0]
296292
if outport not in outports:
297293
outports.append(outport)
298-
outputstr = '{OUT'
299-
for op in sorted(outports):
300-
outputstr += '|<out%s> %s' % (replacefunk(op), op)
301-
outputstr += '}'
294+
outputstr = ['{OUT'] + ['|<out%s> %s' % (_replacefunk(oport), oport)
295+
for oport in sorted(outports)] + ['}']
302296
srcpackage = ''
303297
if hasattr(n, '_interface'):
304298
pkglist = n._interface.__class__.__module__.split('.')
@@ -309,19 +303,23 @@ def _write_detailed_dot(graph, dotfilename):
309303
srcpackage,
310304
srchierarchy)
311305
text += ['%s [label="%s|%s|%s"];' % (nodename.replace('.', ''),
312-
inputstr,
306+
''.join(inputstr),
313307
nodenamestr,
314-
outputstr)]
308+
''.join(outputstr))]
315309
# write edges
316310
for edge in sorted(edges):
317311
text.append(edge)
318312
text.append('}')
319-
filep = open(dotfilename, 'wt')
320-
filep.write('\n'.join(text))
321-
filep.close()
313+
with open(dotfilename, 'wt') as filep:
314+
filep.write('\n'.join(text))
322315
return text
323316

324317

318+
def _replacefunk(x):
319+
return x.replace('_', '').replace(
320+
'.', '').replace('@', '').replace('-', '')
321+
322+
325323
# Graph manipulations for iterable expansion
326324
def _get_valid_pathstr(pathstr):
327325
"""Remove disallowed characters from path

0 commit comments

Comments
 (0)