From 27c4cd47b754b8812f2c1a608f09cdfa97f52c25 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:24:54 +0200 Subject: [PATCH 1/5] STY: Apply ruff/flake8-pie rule PIE790 PIE790 Unnecessary `pass` statement --- nipype/interfaces/dipy/reconstruction.py | 1 - nipype/interfaces/mrtrix3/base.py | 1 - nipype/pipeline/plugins/sge.py | 4 ---- nipype/utils/draw_gantt_chart.py | 1 - 4 files changed, 7 deletions(-) diff --git a/nipype/interfaces/dipy/reconstruction.py b/nipype/interfaces/dipy/reconstruction.py index c16ccf7ddf..1b07bbf6d4 100644 --- a/nipype/interfaces/dipy/reconstruction.py +++ b/nipype/interfaces/dipy/reconstruction.py @@ -136,7 +136,6 @@ def _run_interface(self, runtime): ) except: bias = 0.0 - pass sigma = mean_std * (1 + bias) diff --git a/nipype/interfaces/mrtrix3/base.py b/nipype/interfaces/mrtrix3/base.py index c361620836..fb13ee2871 100644 --- a/nipype/interfaces/mrtrix3/base.py +++ b/nipype/interfaces/mrtrix3/base.py @@ -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": diff --git a/nipype/pipeline/plugins/sge.py b/nipype/pipeline/plugins/sge.py index c588c0478a..d54146ea7c 100644 --- a/nipype/pipeline/plugins/sge.py +++ b/nipype/pipeline/plugins/sge.py @@ -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): @@ -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: @@ -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. @@ -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""" diff --git a/nipype/utils/draw_gantt_chart.py b/nipype/utils/draw_gantt_chart.py index 6190e12fdf..79af8262ac 100644 --- a/nipype/utils/draw_gantt_chart.py +++ b/nipype/utils/draw_gantt_chart.py @@ -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): From 3681fa48ccc9e3e440b03bde2702529580f97ba2 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:27:35 +0200 Subject: [PATCH 2/5] STY: Apply ruff/flake8-pie rule PIE804 PIE804 Unnecessary `dict` kwargs --- nipype/pipeline/engine/tests/test_engine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nipype/pipeline/engine/tests/test_engine.py b/nipype/pipeline/engine/tests/test_engine.py index 7dc8920562..bcb44865fa 100644 --- a/nipype/pipeline/engine/tests/test_engine.py +++ b/nipype/pipeline/engine/tests/test_engine.py @@ -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() From cd4ef59054e75bd3ceaa0c4d5d9c6fedfdfdee68 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:29:23 +0200 Subject: [PATCH 3/5] STY: Apply ruff/flake8-pie rule PIE808 PIE808 Unnecessary `start` argument in `range` --- nipype/algorithms/misc.py | 2 +- nipype/interfaces/ants/registration.py | 2 +- nipype/interfaces/cmtk/cmtk.py | 4 ++-- nipype/interfaces/cmtk/nx.py | 2 +- nipype/interfaces/dipy/simulate.py | 2 +- nipype/interfaces/freesurfer/preprocess.py | 2 +- nipype/interfaces/fsl/model.py | 2 +- .../pipeline/plugins/tests/test_legacymultiproc_nondaemon.py | 2 +- nipype/utils/nipype2boutiques.py | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nipype/algorithms/misc.py b/nipype/algorithms/misc.py index c520004926..20316cd8e7 100644 --- a/nipype/algorithms/misc.py +++ b/nipype/algorithms/misc.py @@ -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 diff --git a/nipype/interfaces/ants/registration.py b/nipype/interfaces/ants/registration.py index 42caf3579a..6803eb94b9 100644 --- a/nipype/interfaces/ants/registration.py +++ b/nipype/interfaces/ants/registration.py @@ -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} diff --git a/nipype/interfaces/cmtk/cmtk.py b/nipype/interfaces/cmtk/cmtk.py index e49c7c8547..9bc3a36d6d 100644 --- a/nipype/interfaces/cmtk/cmtk.py +++ b/nipype/interfaces/cmtk/cmtk.py @@ -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])) @@ -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], diff --git a/nipype/interfaces/cmtk/nx.py b/nipype/interfaces/cmtk/nx.py index 75676745a1..7a9e2f9d8a 100644 --- a/nipype/interfaces/cmtk/nx.py +++ b/nipype/interfaces/cmtk/nx.py @@ -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: diff --git a/nipype/interfaces/dipy/simulate.py b/nipype/interfaces/dipy/simulate.py index ac6fc2afd5..24681b6e93 100644 --- a/nipype/interfaces/dipy/simulate.py +++ b/nipype/interfaces/dipy/simulate.py @@ -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) diff --git a/nipype/interfaces/freesurfer/preprocess.py b/nipype/interfaces/freesurfer/preprocess.py index c727e2c24c..215b2b6ef1 100644 --- a/nipype/interfaces/freesurfer/preprocess.py +++ b/nipype/interfaces/freesurfer/preprocess.py @@ -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"]: diff --git a/nipype/interfaces/fsl/model.py b/nipype/interfaces/fsl/model.py index e371335e86..d661a6ea01 100644 --- a/nipype/interfaces/fsl/model.py +++ b/nipype/interfaces/fsl/model.py @@ -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): diff --git a/nipype/pipeline/plugins/tests/test_legacymultiproc_nondaemon.py b/nipype/pipeline/plugins/tests/test_legacymultiproc_nondaemon.py index 9d0d490a87..2b93db026e 100644 --- a/nipype/pipeline/plugins/tests/test_legacymultiproc_nondaemon.py +++ b/nipype/pipeline/plugins/tests/test_legacymultiproc_nondaemon.py @@ -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) diff --git a/nipype/utils/nipype2boutiques.py b/nipype/utils/nipype2boutiques.py index da8f716f41..df06f9dd39 100644 --- a/nipype/utils/nipype2boutiques.py +++ b/nipype/utils/nipype2boutiques.py @@ -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, From 56b8c9347d3e96806d50ee0a948ffb6629ad00a3 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:30:02 +0200 Subject: [PATCH 4/5] STY: Apply ruff/flake8-pie rule PIE810 PIE810 Call `endswith` once with a `tuple` --- nipype/interfaces/dcm2nii.py | 7 ++----- nipype/interfaces/freesurfer/utils.py | 2 +- nipype/utils/filemanip.py | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/nipype/interfaces/dcm2nii.py b/nipype/interfaces/dcm2nii.py index 387c267c91..a6ca6a49a4 100644 --- a/nipype/interfaces/dcm2nii.py +++ b/nipype/interfaces/dcm2nii.py @@ -472,10 +472,7 @@ def _parse_files(self, 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") + fl.endswith((".nii", ".gz", ".nrrd", ".nhdr")) ): outfiles.append(fl) elif fl.endswith(".bval"): @@ -484,7 +481,7 @@ def _parse_files(self, filenames): 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 diff --git a/nipype/interfaces/freesurfer/utils.py b/nipype/interfaces/freesurfer/utils.py index e1be5d69ab..a5644baa61 100644 --- a/nipype/interfaces/freesurfer/utils.py +++ b/nipype/interfaces/freesurfer/utils.py @@ -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: diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index ef52d00cc6..351093f208 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -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") From 39800373c645c0fdf6a40113ba0d68fc3920625d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:31:57 +0200 Subject: [PATCH 5/5] STY: Apply ruff/flake8-pie rule PIE810 PIE810 Call `endswith` once with a `tuple` --- nipype/interfaces/dcm2nii.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nipype/interfaces/dcm2nii.py b/nipype/interfaces/dcm2nii.py index a6ca6a49a4..baeb21c1e8 100644 --- a/nipype/interfaces/dcm2nii.py +++ b/nipype/interfaces/dcm2nii.py @@ -471,9 +471,7 @@ 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", ".gz", ".nrrd", ".nhdr")) - ): + if fl.endswith((".nii", ".gz", ".nrrd", ".nhdr")): outfiles.append(fl) elif fl.endswith(".bval"): bvals.append(fl)