Skip to content

Commit 565ca25

Browse files
STY: Further simplification
Co-authored-by: Chris Markiewicz <[email protected]>
1 parent 0fdc45e commit 565ca25

File tree

9 files changed

+20
-22
lines changed

9 files changed

+20
-22
lines changed

nipype/algorithms/modelgen.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def bids_gen_info(
161161
for bids_event_file in bids_event_files:
162162
with open(bids_event_file) as f:
163163
f_events = csv.DictReader(f, skipinitialspace=True, delimiter="\t")
164-
events = [dict(row.items()) for row in f_events]
164+
events = list(f_events)
165165
if not condition_column:
166166
condition_column = "_trial_type"
167167
for i in events:

nipype/interfaces/base/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def load_inputs_from_json(self, json_file, overwrite=True):
486486
if not overwrite:
487487
def_inputs = list(self.inputs.get_traitsfree().keys())
488488

489-
new_inputs = list(set(inputs_dict.keys()) - set(def_inputs))
489+
new_inputs = set(inputs_dict) - set(def_inputs)
490490
for key in new_inputs:
491491
if hasattr(self.inputs, key):
492492
setattr(self.inputs, key, inputs_dict[key])

nipype/interfaces/diffusion_toolkit/dti.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class DTIRecon(CommandLine):
9797
def _create_gradient_matrix(self, bvecs_file, bvals_file):
9898
_gradient_matrix_file = "gradient_matrix.txt"
9999
with open(bvals_file) as fbvals:
100-
bvals = list(re.split(r"\s+", fbvals.readline().strip()))
100+
bvals = fbvals.readline().strip().split()
101101
with open(bvecs_file) as fbvecs:
102102
bvecs_x = fbvecs.readline().split()
103103
bvecs_y = fbvecs.readline().split()

nipype/interfaces/diffusion_toolkit/odf.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ class HARDIMat(CommandLine):
9898

9999
def _create_gradient_matrix(self, bvecs_file, bvals_file):
100100
_gradient_matrix_file = "gradient_matrix.txt"
101-
bvals = list(re.split(r"\s+", open(bvals_file).readline().strip()))
102-
bvecs_f = open(bvecs_file)
103-
bvecs_x = list(re.split(r"\s+", bvecs_f.readline().strip()))
104-
bvecs_y = list(re.split(r"\s+", bvecs_f.readline().strip()))
105-
bvecs_z = list(re.split(r"\s+", bvecs_f.readline().strip()))
106-
bvecs_f.close()
101+
with open(bvals_file) as bvals_f:
102+
bvals = bvals_f.readline().strip().split()
103+
with open(bvecs_file) as bvecs_f:
104+
bvecs_x = bvecs_f.readline().strip().split()
105+
bvecs_y = bvecs_f.readline().strip().split()
106+
bvecs_z = bvecs_f.readline().strip().split()
107107
gradient_matrix_f = open(_gradient_matrix_file, "w")
108108
for i in range(len(bvals)):
109109
if int(bvals[i]) == 0:

nipype/interfaces/io.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ def _list_outputs(self):
10251025
if self.inputs.sort_filelist:
10261026
outfiles = human_order_sorted(outfiles)
10271027
outputs[key].append(simplify_list(outfiles))
1028-
if any(val is None for val in outputs[key]):
1028+
if None in outputs[key]:
10291029
outputs[key] = []
10301030
if len(outputs[key]) == 0:
10311031
outputs[key] = None
@@ -1300,7 +1300,7 @@ def _list_outputs(self):
13001300
if self.inputs.drop_blank_outputs:
13011301
outputs[key] = [x for x in outputs[key] if x is not None]
13021302
else:
1303-
if any(val is None for val in outputs[key]):
1303+
if None in outputs[key]:
13041304
outputs[key] = []
13051305
if len(outputs[key]) == 0:
13061306
outputs[key] = None
@@ -2305,7 +2305,7 @@ def __init__(self, input_names, **inputs):
23052305
super().__init__(**inputs)
23062306

23072307
self._input_names = ensure_list(input_names)
2308-
add_traits(self.inputs, list(self._input_names))
2308+
add_traits(self.inputs, self._input_names)
23092309

23102310
def _list_outputs(self):
23112311
"""Execute this module."""
@@ -2367,7 +2367,7 @@ def __init__(self, input_names, **inputs):
23672367
super().__init__(**inputs)
23682368

23692369
self._input_names = ensure_list(input_names)
2370-
add_traits(self.inputs, list(self._input_names))
2370+
add_traits(self.inputs, self._input_names)
23712371

23722372
def _list_outputs(self):
23732373
"""Execute this module."""
@@ -2645,7 +2645,7 @@ def _list_outputs(self):
26452645
outputs[key].append(self._get_files_over_ssh(filledtemplate))
26462646

26472647
# disclude where there was any invalid matches
2648-
if any(val is None for val in outputs[key]):
2648+
if None in outputs[key]:
26492649
outputs[key] = []
26502650

26512651
# no outputs is None, not empty list

nipype/interfaces/spm/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _parse_inputs(self):
159159
"""validate spm realign options if set to None ignore"""
160160
einputs = super()._parse_inputs(skip=("mask_threshold", "flags"))
161161
if isdefined(self.inputs.flags):
162-
einputs[0].update(dict(self.inputs.flags.items()))
162+
einputs[0].update(self.inputs.flags)
163163
for sessinfo in einputs[0]["sess"]:
164164
sessinfo["scans"] = scans_for_fnames(
165165
ensure_list(sessinfo["scans"]), keep4d=False
@@ -309,7 +309,7 @@ def _parse_inputs(self):
309309
"""validate spm realign options if set to None ignore"""
310310
einputs = super()._parse_inputs(skip=("flags"))
311311
if isdefined(self.inputs.flags):
312-
einputs[0].update(dict(self.inputs.flags.items()))
312+
einputs[0].update(self.inputs.flags)
313313
return einputs
314314

315315
def _list_outputs(self):

nipype/interfaces/utility/wrappers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def __init__(
9595
self.inputs.on_trait_change(self._set_function_string, "function_str")
9696
self._input_names = ensure_list(input_names)
9797
self._output_names = ensure_list(output_names)
98-
add_traits(self.inputs, list(self._input_names))
98+
add_traits(self.inputs, self._input_names)
9999
self.imports = imports
100-
self._out = {}
100+
self._out = {name: None for name in self._output_names}
101101
for name in self._output_names:
102102
self._out[name] = None
103103

nipype/pipeline/engine/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1483,9 +1483,7 @@ def clean_working_directory(
14831483
if str2bool(config["execution"]["remove_unnecessary_outputs"]):
14841484
for f in walk_files(cwd):
14851485
if f not in needed_files:
1486-
if not needed_dirs:
1487-
files2remove.append(f)
1488-
elif not any(f.startswith(dname) for dname in needed_dirs):
1486+
if not f.startswith(tuple(needed_dirs)):
14891487
files2remove.append(f)
14901488
else:
14911489
if not str2bool(config["execution"]["keep_inputs"]):

nipype/utils/docparse.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def _parse_doc(doc, style=["--"]):
283283
flag = [
284284
item
285285
for i, item in enumerate(linelist)
286-
if i < 2 and any(item.startswith(s) for s in style) and len(item) > 1
286+
if i < 2 and item.startswith(tuple(style)) and len(item) > 1
287287
]
288288
if flag:
289289
if len(flag) == 1:

0 commit comments

Comments
 (0)