Skip to content
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

STY: Apply ruff/Pyflakes rules (F) #3681

Merged
merged 6 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/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import faulthandler

faulthandler.enable()
except (ImportError, OSError) as e:
except (ImportError, OSError):

Check warning on line 28 in nipype/__init__.py

View check run for this annotation

Codecov / codecov/patch

nipype/__init__.py#L28

Added line #L28 was not covered by tests
pass

config = NipypeConfig()
Expand Down
2 changes: 1 addition & 1 deletion nipype/algorithms/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def split_rois(in_file, mask=None, roishape=None):
"""
import nibabel as nb
import numpy as np
from math import sqrt, ceil
from math import ceil
import os.path as op

if roishape is None:
Expand Down
3 changes: 0 additions & 3 deletions nipype/algorithms/tests/test_ErrorMap.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env python

import pytest
from nipype.testing import example_data
from nipype.algorithms.metrics import ErrorMap
import nibabel as nb
import numpy as np
import os


def test_errormap(tmpdir):
Expand Down
1 change: 0 additions & 1 deletion nipype/algorithms/tests/test_Overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:

import os

from nipype.testing import example_data

Expand Down
1 change: 0 additions & 1 deletion nipype/algorithms/tests/test_confounds.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
import os

import pytest
from nipype.testing import example_data
Expand Down
2 changes: 0 additions & 2 deletions nipype/algorithms/tests/test_mesh_ops.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:

import os

import pytest
import nipype.testing as npt
from nipype.testing import example_data
import numpy as np
from nipype.algorithms import mesh as m
Expand Down
1 change: 0 additions & 1 deletion nipype/algorithms/tests/test_modelgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# vi: set ft=python sts=4 ts=4 sw=4 et:

from copy import deepcopy
import os

from nibabel import Nifti1Image
import numpy as np
Expand Down
3 changes: 0 additions & 3 deletions nipype/algorithms/tests/test_normalize_tpms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:

import os

import pytest
from nipype.testing import example_data

import numpy as np
import nibabel as nb
import nipype.testing as nit

from nipype.algorithms.misc import normalize_tpms

Expand Down
2 changes: 0 additions & 2 deletions nipype/algorithms/tests/test_splitmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
def test_split_and_merge(tmpdir):
import numpy as np
import nibabel as nb
import os.path as op
import os

from nipype.algorithms.misc import split_rois, merge_rois

Expand Down
7 changes: 0 additions & 7 deletions nipype/interfaces/afni/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,19 @@
import os

from ..base import (
CommandLineInputSpec,
CommandLine,
Directory,
TraitedSpec,
traits,
isdefined,
File,
InputMultiPath,
Undefined,
Str,
Tuple,
)
from ...external.due import BibTeX

from .base import (
AFNICommandBase,
AFNICommand,
AFNICommandInputSpec,
AFNICommandOutputSpec,
Info,
)


Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/ants/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""The ants module provides basic functions for interfacing with ANTS tools."""
import os
from packaging.version import Version, parse
from packaging.version import parse

# Local imports
from ... import logging
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/ants/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _format_arg(self, opt, spec, val):
if isdefined(self.inputs.invert_affine):
diff_inv = set(self.inputs.invert_affine) - set(affine_invert)
if diff_inv:
raise Exceptions(
raise Exception(
"Review invert_affine, not all indexes from invert_affine were used, "
"check the description for the full definition"
)
Expand Down Expand Up @@ -275,7 +275,7 @@ def _format_arg(self, opt, spec, val):
if isdefined(self.inputs.invert_affine):
diff_inv = set(self.inputs.invert_affine) - set(affine_invert)
if diff_inv:
raise Exceptions(
raise Exception(
"Review invert_affine, not all indexes from invert_affine were used, "
"check the description for the full definition"
)
Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/cat12/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _list_outputs(self):
]

outputs["report"] = fname_presuffix(
f, prefix=os.path.join("report", f"cat_"), suffix=".xml", use_ext=False
f, prefix=os.path.join("report", "cat_"), suffix=".xml", use_ext=False
)

outputs["label_files"] = [
Expand Down
3 changes: 1 addition & 2 deletions nipype/interfaces/cmtk/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os.path as op
import datetime
import string
import networkx as nx

from ...utils.filemanip import split_filename
from ..base import (
Expand All @@ -13,7 +12,7 @@
InputMultiPath,
isdefined,
)
from .base import CFFBaseInterface, have_cfflib
from .base import CFFBaseInterface


def _read_pickle(fname):
Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/cmtk/nbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
OutputMultiPath,
isdefined,
)
from .base import have_cv

iflogger = logging.getLogger("nipype.interface")

Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/cmtk/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
OutputMultiPath,
isdefined,
)
from .base import have_cmp

iflogger = logging.getLogger("nipype.interface")

Expand Down
17 changes: 8 additions & 9 deletions nipype/interfaces/cmtk/parcellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from ... import logging
from ..base import (
BaseInterface,
LibraryBaseInterface,
BaseInterfaceInputSpec,
traits,
Expand All @@ -19,21 +18,20 @@
Directory,
isdefined,
)
from .base import have_cmp

iflogger = logging.getLogger("nipype.interface")


def create_annot_label(subject_id, subjects_dir, fs_dir, parcellation_name):
import cmp
from cmp.configuration import PipelineConfiguration

Check warning on line 26 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L26

Added line #L26 was not covered by tests
from cmp.util import runCmd

iflogger.info("Create the cortical labels necessary for our ROIs")
iflogger.info("=================================================")
fs_label_dir = op.join(op.join(subjects_dir, subject_id), "label")
output_dir = op.abspath(op.curdir)
paths = []
cmp_config = cmp.configuration.PipelineConfiguration()
cmp_config = PipelineConfiguration()

Check warning on line 34 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L34

Added line #L34 was not covered by tests
cmp_config.parcellation_scheme = "Lausanne2008"
for hemi in ["lh", "rh"]:
spath = (
Expand Down Expand Up @@ -334,13 +332,13 @@
def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name, dilation):
"""Creates the ROI_%s.nii.gz files using the given parcellation information
from networks. Iteratively create volume."""
import cmp
from cmp.configuration import PipelineConfiguration

Check warning on line 335 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L335

Added line #L335 was not covered by tests
from cmp.util import runCmd

iflogger.info("Create the ROIs:")
output_dir = op.abspath(op.curdir)
fs_dir = op.join(subjects_dir, subject_id)
cmp_config = cmp.configuration.PipelineConfiguration()
cmp_config = PipelineConfiguration()

Check warning on line 341 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L341

Added line #L341 was not covered by tests
cmp_config.parcellation_scheme = "Lausanne2008"
log = cmp_config.get_logger()
parval = cmp_config._get_lausanne_parcellation("Lausanne2008")[parcellation_name]
Expand Down Expand Up @@ -469,12 +467,12 @@


def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
import cmp
from cmp.configuration import PipelineConfiguration

Check warning on line 470 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L470

Added line #L470 was not covered by tests
import scipy.ndimage.morphology as nd

iflogger.info("Create white matter mask")
fs_dir = op.join(subjects_dir, subject_id)
cmp_config = cmp.configuration.PipelineConfiguration()
cmp_config = PipelineConfiguration()

Check warning on line 475 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L475

Added line #L475 was not covered by tests
cmp_config.parcellation_scheme = "Lausanne2008"
pgpath = cmp_config._get_lausanne_parcellation("Lausanne2008")[parcellation_name][
"node_information_graphml"
Expand Down Expand Up @@ -620,10 +618,11 @@
def crop_and_move_datasets(
subject_id, subjects_dir, fs_dir, parcellation_name, out_roi_file, dilation
):
from cmp.configuration import PipelineConfiguration

Check warning on line 621 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L621

Added line #L621 was not covered by tests
from cmp.util import runCmd

fs_dir = op.join(subjects_dir, subject_id)
cmp_config = cmp.configuration.PipelineConfiguration()
cmp_config = PipelineConfiguration()

Check warning on line 625 in nipype/interfaces/cmtk/parcellation.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/cmtk/parcellation.py#L625

Added line #L625 was not covered by tests
cmp_config.parcellation_scheme = "Lausanne2008"
log = cmp_config.get_logger()
output_dir = op.abspath(op.curdir)
Expand Down
4 changes: 2 additions & 2 deletions nipype/interfaces/cmtk/tests/test_nbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
have_cv = True
try:
package_check("cviewer")
except Exception as e:
except Exception:
have_cv = False


Expand Down Expand Up @@ -39,7 +39,7 @@ def test_importerror(creating_graphs, tmpdir):
nbs.inputs.in_group2 = group2
nbs.inputs.edge_key = "weight"

with pytest.raises(ImportError) as e:
with pytest.raises(ImportError):
nbs.run()


Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/dipy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os.path as op
import inspect
import numpy as np
from ... import logging
from ..base import (
traits,
File,
Expand Down
2 changes: 0 additions & 2 deletions nipype/interfaces/dipy/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class RESTORE(DipyDiffusionInterface):
def _run_interface(self, runtime):
from scipy.special import gamma
from dipy.reconst.dti import TensorModel
import gc

img = nb.load(self.inputs.in_file)
hdr = img.header.copy()
Expand Down Expand Up @@ -222,7 +221,6 @@ class EstimateResponseSH(DipyDiffusionInterface):
output_spec = EstimateResponseSHOutputSpec

def _run_interface(self, runtime):
from dipy.core.gradients import GradientTable
from dipy.reconst.dti import fractional_anisotropy, mean_diffusivity
from dipy.reconst.csdeconv import recursive_response, auto_response

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 @@ -324,7 +324,7 @@

"""
import numpy as np
from dipy.core.sphere import disperse_charges, Sphere, HemiSphere
from dipy.core.sphere import disperse_charges, HemiSphere

Check warning on line 327 in nipype/interfaces/dipy/simulate.py

View check run for this annotation

Codecov / codecov/patch

nipype/interfaces/dipy/simulate.py#L327

Added line #L327 was not covered by tests
from dipy.core.gradients import gradient_table

theta = np.pi * np.random.rand(ndirs)
Expand Down
5 changes: 0 additions & 5 deletions nipype/interfaces/freesurfer/longitudinal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@
InputMultiPath,
OutputMultiPath,
isdefined,
InputMultiObject,
Directory,
)
from .base import (
FSCommand,
FSTraitedSpec,
FSCommandOpenMP,
FSTraitedSpecOpenMP,
CommandLine,
)
from .preprocess import ReconAllInputSpec
from ..io import FreeSurferSource

__docformat__ = "restructuredtext"
iflogger = logging.getLogger("nipype.interface")
Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/freesurfer/tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:

import os
import numpy as np
import nibabel as nb

Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/fsl/aroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
File,
Directory,
traits,
isdefined,
)
import os

Expand Down
2 changes: 1 addition & 1 deletion nipype/interfaces/fsl/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import nipype.interfaces.fsl as fsl
from nipype.interfaces.base import InterfaceResult
from nipype.interfaces.fsl import check_fsl, no_fsl
from nipype.interfaces.fsl import no_fsl

import pytest

Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/fsl/tests/test_epi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import os

import pytest
from nipype.testing.fixtures import create_files_in_directory
Expand Down
1 change: 0 additions & 1 deletion nipype/interfaces/fsl/tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import os

import pytest
import nipype.interfaces.fsl.model as fsl
Expand Down
2 changes: 0 additions & 2 deletions nipype/interfaces/fsl/tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from copy import deepcopy

import pytest
import pdb
from nipype.utils.filemanip import split_filename, ensure_list
from .. import preprocess as fsl
from nipype.interfaces.fsl import Info
Expand Down Expand Up @@ -579,7 +578,6 @@ def test_applywarp(setup_flirt):
def setup_fugue(tmpdir):
import nibabel as nb
import numpy as np
import os.path as op

d = np.ones((80, 80, 80))
infile = tmpdir.join("dumbfile.nii.gz").strpath
Expand Down
3 changes: 1 addition & 2 deletions nipype/interfaces/fsl/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

import numpy as np

import nibabel as nb
import pytest
import nipype.interfaces.fsl.utils as fsl
from nipype.interfaces.fsl import no_fsl, Info
from nipype.interfaces.fsl import no_fsl

from nipype.testing.fixtures import create_files_in_directory_plus_output_type

Expand Down
Loading