8000 STY: Apply ruff/flake8-comprehensions rules (C4) by DimitriPapadopoulos · Pull Request #3680 · nipy/nipype · GitHub
[go: up one dir, main page]

Skip to content

STY: Apply ruff/flake8-comprehensions rules (C4) #3680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
STY: Further simplification
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
  • Loading branch information
DimitriPapadopoulos and effigies committed Oct 6, 2024
commit 1747356e0cc3f8d9ce02fb5c03ef8a226eb4252d
2 changes: 1 addition & 1 deletion nipype/algorithms/modelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def bids_gen_info(
for bids_event_file in bids_event_files:
with open(bids_event_file) as f:
f_events = csv.DictReader(f, skipinitialspace=True, delimiter="\t")
events = [dict(row.items()) for row in f_events]
events = list(f_events)
if not condition_column:
condition_column = "_trial_type"
for i in events:
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def load_inputs_from_json(self, json_file, overwrite=True):
if not overwrite:
def_inputs = list(self.inputs.get_traitsfree().keys())

new_inputs = list(set(inputs_dict.keys()) - set(def_inputs))
new_inputs = set(inputs_dict) - set(def_inputs)
for key in new_inputs:
if hasattr(self.inputs, key):
setattr(self.inputs, key, inputs_dict[key])
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/diffusion_toolkit/dti.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
def _create_gradient_matrix(self, bvecs_file, bvals_file):
_gradient_matrix_file = "gradient_matrix.txt"
with open(bvals_file) as fbvals:
bvals = list(re.split(r"\s+", fbvals.readline().strip()))
bvals = fbvals.readline().strip().split()

Check warning on line 100 in nipype/interfaces/diffusion_toolkit/dti.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/diffusion_toolkit/dti.py#L100

Added line #L100 was not covered by tests
with open(bvecs_file) as fbvecs:
bvecs_x = fbvecs.readline().split()
bvecs_y = fbvecs.readline().split()
Expand Down
12 changes: 6 additions & 6 deletions nipype/interfaces/diffusion_toolkit/odf.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@

def _create_gradient_matrix(self, bvecs_file, bvals_file):
_gradient_matrix_file = "gradient_matrix.txt"
bvals = list(re.split(r"\s+", open(bvals_file).readline().strip()))
bvecs_f = open(bvecs_file)
bvecs_x = list(re.split(r"\s+", bvecs_f.readline().strip()))
bvecs_y = list(re.split(r"\s+", bvecs_f.readline().strip()))
bvecs_z = list(re.split(r"\s+", bvecs_f.readline().strip()))
bvecs_f.close()
with open(bvals_file) as bvals_f:
bvals = bvals_f.readline().strip().split()

Check warning on line 102 in nipype/interfaces/diffusion_toolkit/odf.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/diffusion_toolkit/odf.py#L102

Added line #L102 was not covered by tests
with open(bvecs_file) as bvecs_f:
bvecs_x = bvecs_f.readline().strip().split()
bvecs_y = bvecs_f.readline().strip().split()
bvecs_z = bvecs_f.readline().strip().split()

Check warning on line 106 in nipype/interfaces/diffusion_toolkit/odf.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/diffusion_toolkit/odf.py#L104-L106

Added lines #L104 - L106 were not covered by tests
gradient_matrix_f = open(_gradient_matrix_file, "w")
for i in range(len(bvals)):
if int(bvals[i]) == 0:
Expand Down
10 changes: 5 additions & 5 deletions nipype/interfaces/io.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ def _list_outputs(self):
if self.inputs.sort_filelist:
outfiles = human_order_sorted(outfiles)
outputs[key].append(simplify_list(outfiles))
if any(val is None for val in outputs[key]):
if None in outputs[key]:
outputs[key] = []
if len(outputs[key]) == 0:
outputs[key] = None
Expand Down Expand Up @@ -1297,7 +1297,7 @@ def _list_outputs(self):
if self.inputs.drop_blank_outputs:
outputs[key] = [x for x in outputs[key] if x is not None]
else:
if any(val is None for val in outputs[key]):
if None in outputs[key]:
outputs[key] = []
if len(outputs[key]) == 0:
outputs[key] = None
Expand Down Expand Up @@ -2302,7 +2302,7 @@ def __init__(self, input_names, **inputs):
super().__init__(**inputs)

self._input_names = ensure_list(input_names)
add_traits(self.inputs, list(self._input_names))
add_traits(self.inputs, self._input_names)

def _list_outputs(self):
"""Execute this module."""
Expand Down Expand Up @@ -2364,7 +2364,7 @@ def __init__(self, input_names, **inputs):
super().__init__(**inputs)

self._input_names = ensure_list(input_names)
add_traits(self.inputs, list(self._input_names))
add_traits(self.inputs, self._input_names)

def _list_outputs(self):
"""Execute this module."""
Expand Down Expa 628C nd Up @@ -2642,7 +2642,7 @@ def _list_outputs(self):
outputs[key].append(self._get_files_over_ssh(filledtemplate))

# disclude where there was any invalid matches
if any(val is None for val in outputs[key]):
if None in outputs[key]:
outputs[key] = []

# no outputs is None, not empty list
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/spm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
"""validate spm realign options if set to None ignore"""
einputs = super()._parse_inputs(skip=("mask_threshold", "flags"))
if isdefined(self.inputs.flags):
einputs[0].update(dict(self.inputs.flags.items()))
einputs[0].update(self.inputs.flags)

Check warning on line 162 in nipype/interfaces/spm/model.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/spm/model.py#L162

Added line #L162 was not covered by tests
for sessinfo in einputs[0]["sess"]:
sessinfo["scans"] = scans_for_fnames(
ensure_list(sessinfo["scans"]), keep4d=False
Expand Down Expand Up @@ -309,7 +309,7 @@
"""validate spm realign options if set to None ignore"""
einputs = super()._parse_inputs(skip=("flags"))
if isdefined(self.inputs.flags):
einputs[0].update(dict(self.inputs.flags.items()))
einputs[0].update(self.inputs.flags)

Check warning on line 312 in nipype/interfaces/spm/model.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/spm/model.py#L312

Added line #L312 was not covered by tests
return einputs

def _list_outputs(self):
Expand Down
6 changes: 2 additions & 4 deletions nipype/interfaces/utility/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ def __init__(
self.inputs.on_trait_change(self._set_function_string, "function_str")
self._input_names = ensure_list(input_names)
self._output_names = ensure_list(output_names)
add_traits(self.inputs, list(self._input_names))
add_traits(self.inputs, self._input_names)
self.imports = imports
self._out = {}
for name in self._output_names:
self._out[name] = None
self._out = {name: None for name in self._output_names}

def _set_function_string(self, obj, name, old, new):
if name == "function_str":
Expand Down
7 changes: 2 additions & 5 deletions nipype/pipeline/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,11 +1482,8 @@ def clean_working_directory(
files2remove = []
if str2bool(config["execution"]["remove_unnecessary_outputs"]):
for f in walk_files(cwd):
if f not in needed_files:
if not needed_dirs:
files2remove.append(f)
elif not any(f.startswith(dname) for dname in needed_dirs):
files2remove.append(f)
if f not in needed_files and not f.startswith(tuple(needed_dirs)):
files2remove.append(f)
else:
if not str2bool(config["execution"]["keep_inputs"]):
input_files = {
Expand Down
2 changes: 1 addition & 1 deletion nipype/utils/docparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def _parse_doc(doc, style=["--"]):
flag = [
item
for i, item in enumerate(linelist)
if i < 2 and any(item.startswith(s) for s in style) and len(item) > 1
if i < 2 and item.startswith(tuple(style)) and len(item) > 1
]
if flag:
if len(flag) == 1:
Expand Down
Loading
0