Skip to content

STY: Apply ruff/flake8-pie rules (PIE) #3678

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 5 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion nipype/algorithms/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def _run_interface(self, runtime):
mx = shape[0]
else:
mx = 1
for idx in range(0, mx):
for idx in range(mx):
extrafieldlist.append(self.inputs.extra_field)
iflogger.info(len(extrafieldlist))
output[extraheading] = extrafieldlist
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/ants/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ def _format_metric(self, index):
# from the non-list inputs.
if isinstance(name_input, list):
items = list(stage_inputs.items())
indexes = list(range(0, len(name_input)))
indexes = list(range(len(name_input)))
specs = list()
for i in indexes:
temp = {k: v[i] for k, v in items}
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/cmtk/cmtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def length(xyz, along=False):
def get_rois_crossed(pointsmm, roiData, voxelSize):
n_points = len(pointsmm)
rois_crossed = []
for j in range(0, n_points):
for j in range(n_points):
# store point
x = int(pointsmm[j, 0] / float(voxelSize[0]))
y = int(pointsmm[j, 1] / float(voxelSize[1]))
Expand Down Expand Up @@ -894,7 +894,7 @@ def _run_interface(self, runtime):
iflogger.info("Number of labels in LUT: %s", numLUTLabels)
LUTlabelDict = {}
""" Create dictionary for input LUT table"""
for labels in range(0, numLUTLabels):
for labels in range(numLUTLabels):
LUTlabelDict[LUTlabelsRGBA[labels][0]] = [
LUTlabelsRGBA[labels][1],
LUTlabelsRGBA[labels][2],
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/cmtk/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def add_edge_data(edge_array, ntwk, above=0, below=0):
edge_ntwk = ntwk.copy()
data = {}
for x, row in enumerate(edge_array):
for y in range(0, np.max(np.shape(edge_array[x]))):
for y in range(np.max(np.shape(edge_array[x]))):
if not edge_array[x, y] == 0:
data["value"] = edge_array[x, y]
if data["value"] <= below or data["value"] >= above:
Expand Down
9 changes: 2 additions & 7 deletions nipype/interfaces/dcm2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,15 @@ def _parse_files(self, filenames):
for filename in filenames:
# search for relevant files, and sort accordingly
for fl in search_files(filename, outtypes, self.inputs.crop):
if (
fl.endswith(".nii")
or fl.endswith(".gz")
or fl.endswith(".nrrd")
or fl.endswith(".nhdr")
):
if fl.endswith((".nii", ".gz", ".nrrd", ".nhdr")):
outfiles.append(fl)
elif fl.endswith(".bval"):
bvals.append(fl)
elif fl.endswith(".bvec"):
bvecs.append(fl)
elif fl.endswith(".mvec"):
mvecs.append(fl)
elif fl.endswith(".json") or fl.endswith(".txt"):
elif fl.endswith((".json", ".txt")):
bids.append(fl)

# in siemens mosaic conversion nipype misread dcm2niix output and generate a duplicate list of results
Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/dipy/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def _run_interface(self, runtime):
)
except:
bias = 0.0
pass

sigma = mean_std * (1 + bias)

Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/dipy/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def _generate_gradients(ndirs=64, values=[1000, 3000], nb0s=1):
bvecs = np.vstack((bvecs, vertices))
bvals = np.hstack((bvals, v * np.ones(vertices.shape[0])))

for i in range(0, nb0s):
for i in range(nb0s):
bvals = bvals.tolist()
bvals.insert(0, 0)

Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/freesurfer/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def _list_outputs(self):
stem = ".".join(outfile.split(".")[:-1])
ext = "." + outfile.split(".")[-1]
outfile = []
for idx in range(0, tp):
for idx in range(tp):
outfile.append(stem + "%04d" % idx + ext)
if isdefined(self.inputs.out_type):
if self.inputs.out_type in ["spm", "analyze"]:
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/freesurfer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,7 @@ def _format_arg(self, name, spec, value):
suffix = basename.split(".")[1]
return spec.argstr % suffix
elif name == "in_orig":
if value.endswith("lh.orig") or value.endswith("rh.orig"):
if value.endswith(("lh.orig", "rh.orig")):
# {lh,rh}.orig inputs are not specified on command line
return
else:
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/fsl/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def _create_ev_files(
# add ev orthogonalization
for i in range(1, num_evs[0] + 1):
initial = ev_ortho.substitute(c0=i, c1=0, orthogonal=1)
for j in range(0, num_evs[0] + 1):
for j in range(num_evs[0] + 1):
try:
orthogonal = int(orthogonalization[i][j])
except (KeyError, TypeError, ValueError, IndexError):
Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/mrtrix3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def _format_arg(self, name, trait_spec, value):
value = cpu_count()
except:
iflogger.warning("Number of threads could not be computed")
pass
return trait_spec.argstr % value

if name == "in_bvec":
Expand Down
2 changes: 1 addition & 1 deletion nipype/pipeline/engine/tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def func1(in1):
# check that multiple json's don't trigger rerun
with open(os.path.join(node.output_dir(), "test.json"), "w") as fp:
fp.write("dummy file")
w1.config["execution"].update(**{"stop_on_first_rerun": True})
w1.config["execution"].update(stop_on_first_rerun=True)

w1.run()

Expand Down
4 changes: 0 additions & 4 deletions nipype/pipeline/plugins/sge.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ def _qacct_verified_complete(taskid):
except:
sge_debug_print("NOTE: qacct call failed")
time.sleep(5)
pass
return is_complete

def _parse_qstat_job_list(self, xml_job_list):
Expand Down Expand Up @@ -259,7 +258,6 @@ def _parse_qstat_job_list(self, xml_job_list):
dictionary_job, self._task_dictionary[dictionary_job]
)
)
pass
if self._task_dictionary[dictionary_job].is_initializing():
is_completed = self._qacct_verified_complete(dictionary_job)
if is_completed:
Expand All @@ -271,7 +269,6 @@ def _parse_qstat_job_list(self, xml_job_list):
dictionary_job, self._task_dictionary[dictionary_job]
)
)
pass

def _run_qstat(self, reason_for_qstat, force_instant=True):
"""request all job information for the current user in xmlformat.
Expand Down Expand Up @@ -320,7 +317,6 @@ def _run_qstat(self, reason_for_qstat, force_instant=True):
)
sge_debug_print(exception_message)
time.sleep(5)
pass

def print_dictionary(self):
"""For debugging"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def dummyFunction(filename):
This function writes the value 45 to the given filename.
"""
j = 0
for i in range(0, 10):
for i in range(10):
j += i

# j is now 45 (0+1+2+3+4+5+6+7+8+9)
Expand Down
1 change: 0 additions & 1 deletion nipype/utils/draw_gantt_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"Pandas not found; in order for full functionality of this module "
"install the pandas package"
)
pass


def create_event_dict(start_time, nodes_list):
Expand Down
2 changes: 1 addition & 1 deletion nipype/utils/filemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def load_json(filename):


def loadcrash(infile, *args):
if infile.endswith("pkl") or infile.endswith("pklz"):
if infile.endswith(("pkl", "pklz")):
return loadpkl(infile)
else:
raise ValueError("Only pickled crashfiles are supported")
Expand Down
2 changes: 1 addition & 1 deletion nipype/utils/nipype2boutiques.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def get_boutiques_input(
if handler_type == "TraitCompound":
input_list = []
# Recursively create an input for each trait
for i in range(0, len(trait_handler.handlers)):
for i in range(len(trait_handler.handlers)):
inp = get_boutiques_input(
inputs,
interface,
Expand Down