Skip to content

Commit b8b2ab5

Browse files
committed
STY: pyupgrade + black
1 parent 1567b72 commit b8b2ab5

File tree

413 files changed

+1077
-1649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

413 files changed

+1077
-1649
lines changed

doc/conf.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# emacs: -*- coding: utf-8; mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2-
# vi: set fileencoding=utf-8 ft=python sts=4 ts=4 sw=4 et:
31
#
42
# nipype documentation build configuration file, created by
53
# sphinx-quickstart on Mon Jul 20 12:30:18 2009.
@@ -151,8 +149,8 @@
151149
master_doc = "index"
152150

153151
# General information about the project.
154-
project = u"nipype"
155-
copyright = u"2009-21, Neuroimaging in Python team"
152+
project = "nipype"
153+
copyright = "2009-21, Neuroimaging in Python team"
156154

157155
# The version info for the project you're documenting, acts as replacement for
158156
# |version| and |release|, also used in various other places throughout the

nipype/__init__.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""
@@ -26,14 +25,14 @@
2625
import faulthandler
2726

2827
faulthandler.enable()
29-
except (ImportError, IOError) as e:
28+
except (ImportError, OSError) as e:
3029
pass
3130

3231
config = NipypeConfig()
3332
logging = Logging(config)
3433

3534

36-
class NipypeTester(object):
35+
class NipypeTester:
3736
def __call__(self, doctests=True, parallel=False):
3837
try:
3938
import pytest

nipype/algorithms/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""

nipype/algorithms/confounds.py

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""
@@ -150,7 +149,7 @@ class ComputeDVARS(BaseInterface):
150149

151150
def __init__(self, **inputs):
152151
self._results = {}
153-
super(ComputeDVARS, self).__init__(**inputs)
152+
super().__init__(**inputs)
154153

155154
def _gen_fname(self, suffix, ext=None):
156155
fname, in_ext = op.splitext(op.basename(self.inputs.in_file))
@@ -165,7 +164,7 @@ def _gen_fname(self, suffix, ext=None):
165164
if ext.startswith("."):
166165
ext = ext[1:]
167166

168-
return op.abspath("{}_{}.{}".format(fname, suffix, ext))
167+
return op.abspath(f"{fname}_{suffix}.{ext}")
169168

170169
def _run_interface(self, runtime):
171170
dvars = compute_dvars(
@@ -584,7 +583,7 @@ class CompCor(SimpleInterface):
584583

585584
def __init__(self, *args, **kwargs):
586585
"""exactly the same as compcor except the header"""
587-
super(CompCor, self).__init__(*args, **kwargs)
586+
super().__init__(*args, **kwargs)
588587
self._header = "CompCor"
589588

590589
def _run_interface(self, runtime):
@@ -713,7 +712,7 @@ def _run_interface(self, runtime):
713712
self.inputs.pre_filter
714713
]
715714
ncols = filter_basis.shape[1] if filter_basis.size > 0 else 0
716-
header = ["{}{:02d}".format(ftype, i) for i in range(ncols)]
715+
header = [f"{ftype}{i:02d}" for i in range(ncols)]
717716
if skip_vols:
718717
old_basis = filter_basis
719718
# nrows defined above
@@ -724,7 +723,7 @@ def _run_interface(self, runtime):
724723
filter_basis[skip_vols:, :ncols] = old_basis
725724
filter_basis[:skip_vols, -skip_vols:] = np.eye(skip_vols)
726725
header.extend(
727-
["NonSteadyStateOutlier{:02d}".format(i) for i in range(skip_vols)]
726+
[f"NonSteadyStateOutlier{i:02d}" for i in range(skip_vols)]
728727
)
729728
np.savetxt(
730729
self._results["pre_filter_file"],
@@ -747,7 +746,7 @@ def _run_interface(self, runtime):
747746
not_retained = np.where(np.logical_not(metadata["retained"]))
748747
components_names[retained] = components_header
749748
components_names[not_retained] = [
750-
"dropped{}".format(i) for i in range(len(not_retained[0]))
749+
f"dropped{i}" for i in range(len(not_retained[0]))
751750
]
752751
with open(self._results["metadata_file"], "w") as f:
753752
f.write("\t".join(["component"] + list(metadata.keys())) + "\n")
@@ -768,7 +767,7 @@ def _make_headers(self, num_col):
768767
if isdefined(self.inputs.header_prefix)
769768
else self._header
770769
)
771-
headers = ["{}{:02d}".format(header, i) for i in range(num_col)]
770+
headers = [f"{header}{i:02d}" for i in range(num_col)]
772771
return headers
773772

774773

@@ -781,7 +780,7 @@ class ACompCor(CompCor):
781780

782781
def __init__(self, *args, **kwargs):
783782
"""exactly the same as compcor except the header"""
784-
super(ACompCor, self).__init__(*args, **kwargs)
783+
super().__init__(*args, **kwargs)
785784
self._header = "aCompCor"
786785

787786

@@ -807,7 +806,7 @@ class TCompCorInputSpec(CompCorInputSpec):
807806
class TCompCorOutputSpec(CompCorOutputSpec):
808807
# and all the fields in CompCorOutputSpec
809808
high_variance_masks = OutputMultiPath(
810-
File(exists=True), desc=(("voxels exceeding the variance" " threshold"))
809+
File(exists=True), desc=("voxels exceeding the variance" " threshold")
811810
)
812811

813812

@@ -832,7 +831,7 @@ class TCompCor(CompCor):
832831

833832
def __init__(self, *args, **kwargs):
834833
"""exactly the same as compcor except the header"""
835-
super(TCompCor, self).__init__(*args, **kwargs)
834+
super().__init__(*args, **kwargs)
836835
self._header = "tCompCor"
837836
self._mask_files = []
838837

@@ -854,7 +853,7 @@ def _process_masks(self, mask_images, timeseries=None):
854853
out_image = nb.Nifti1Image(mask_data, affine=img.affine, header=img.header)
855854

856855
# save mask
857-
mask_file = os.path.abspath("mask_{:03d}.nii.gz".format(i))
856+
mask_file = os.path.abspath(f"mask_{i:03d}.nii.gz")
858857
out_image.to_filename(mask_file)
859858
IFLOGGER.debug(
860859
"tCompcor computed and saved mask of shape %s to " "mask_file %s",
@@ -866,7 +865,7 @@ def _process_masks(self, mask_images, timeseries=None):
866865
return out_images
867866

868867
def _list_outputs(self):
869-
outputs = super(TCompCor, self)._list_outputs()
868+
outputs = super()._list_outputs()
870869
outputs["high_variance_masks"] = self._mask_files
871870
return outputs
872871

@@ -1136,7 +1135,7 @@ def plot_confound(tseries, figsize, name, units=None, series_tr=None, normalize=
11361135

11371136
xlabel = "Frame #"
11381137
if series_tr is not None:
1139-
xlabel = "Frame # ({} sec TR)".format(series_tr)
1138+
xlabel = f"Frame # ({series_tr} sec TR)"
11401139
ax.set_xlabel(xlabel)
11411140
ylim = ax.get_ylim()
11421141

@@ -1280,17 +1279,15 @@ def combine_mask_files(mask_files, mask_method=None, mask_index=None):
12801279
mask_index = 0
12811280
else:
12821281
raise ValueError(
1283-
(
1284-
"When more than one mask file is provided, "
1285-
"one of merge_method or mask_index must be "
1286-
"set"
1287-
)
1282+
"When more than one mask file is provided, "
1283+
"one of merge_method or mask_index must be "
1284+
"set"
12881285
)
12891286
if mask_index < len(mask_files):
12901287
mask = nb.load(mask_files[mask_index])
12911288
return [mask]
12921289
raise ValueError(
1293-
("mask_index {0} must be less than number of mask " "files {1}").format(
1290+
("mask_index {} must be less than number of mask " "files {}").format(
12941291
mask_index, len(mask_files)
12951292
)
12961293
)

nipype/algorithms/icc.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import os
32
from functools import lru_cache
43
import numpy as np

nipype/algorithms/mesh.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""
@@ -30,7 +29,7 @@ class TVTKBaseInterface(BaseInterface):
3029
def __init__(self, **inputs):
3130
if VTKInfo.no_tvtk():
3231
raise ImportError("This interface requires tvtk to run.")
33-
super(TVTKBaseInterface, self).__init__(**inputs)
32+
super().__init__(**inputs)
3433

3534

3635
class WarpPointsInputSpec(BaseInterfaceInputSpec):
@@ -92,7 +91,7 @@ def _gen_fname(self, in_file, suffix="generated", ext=None):
9291

9392
if ext[0] == ".":
9493
ext = ext[1:]
95-
return op.abspath("%s_%s.%s" % (fname, suffix, ext))
94+
return op.abspath(f"{fname}_{suffix}.{ext}")
9695

9796
def _run_interface(self, runtime):
9897
import nibabel as nb
@@ -423,7 +422,7 @@ class P2PDistance(ComputeMeshWarp):
423422
"""
424423

425424
def __init__(self, **inputs):
426-
super(P2PDistance, self).__init__(**inputs)
425+
super().__init__(**inputs)
427426
IFLOGGER.warning(
428427
"This interface has been deprecated since 1.0, please "
429428
"use ComputeMeshWarp"

nipype/algorithms/metrics.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""

nipype/algorithms/misc.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
32
# vi: set ft=python sts=4 ts=4 sw=4 et:
43
"""Miscellaneous algorithms."""
@@ -494,7 +493,7 @@ def merge_csvs(in_list):
494493
try:
495494
in_array = np.loadtxt(in_file, delimiter=",", skiprows=1)
496495
except ValueError:
497-
with open(in_file, "r") as first:
496+
with open(in_file) as first:
498497
header_line = first.readline()
499498

500499
header_list = header_line.split(",")
@@ -671,7 +670,7 @@ def _run_interface(self, runtime):
671670
iflogger.info(
672671
'Row headings have been provided. Adding "labels"' "column header."
673672
)
674-
prefix = '"{p}","'.format(p=self.inputs.row_heading_title)
673+
prefix = f'"{self.inputs.row_heading_title}","'
675674
csv_headings = prefix + '","'.join(itertools.chain(headings)) + '"\n'
676675
rowheadingsBool = True
677676
else:
@@ -772,7 +771,7 @@ class AddCSVColumn(BaseInterface):
772771
output_spec = AddCSVColumnOutputSpec
773772

774773
def _run_interface(self, runtime):
775-
in_file = open(self.inputs.in_file, "r")
774+
in_file = open(self.inputs.in_file)
776775
_, name, ext = split_filename(self.inputs.out_file)
777776
if not ext == ".csv":
778777
ext = ".csv"
@@ -808,12 +807,12 @@ class AddCSVRowInputSpec(DynamicTraitedSpec, BaseInterfaceInputSpec):
808807
def __setattr__(self, key, value):
809808
if key not in self.copyable_trait_names():
810809
if not isdefined(value):
811-
super(AddCSVRowInputSpec, self).__setattr__(key, value)
810+
super().__setattr__(key, value)
812811
self._outputs[key] = value
813812
else:
814813
if key in self._outputs:
815814
self._outputs[key] = value
816-
super(AddCSVRowInputSpec, self).__setattr__(key, value)
815+
super().__setattr__(key, value)
817816

818817

819818
class AddCSVRowOutputSpec(TraitedSpec):
@@ -850,7 +849,7 @@ class AddCSVRow(BaseInterface):
850849
output_spec = AddCSVRowOutputSpec
851850

852851
def __init__(self, infields=None, force_run=True, **kwargs):
853-
super(AddCSVRow, self).__init__(**kwargs)
852+
super().__init__(**kwargs)
854853
undefined_traits = {}
855854
self._infields = infields
856855
self._have_lock = False
@@ -882,10 +881,8 @@ def _run_interface(self, runtime):
882881
from warnings import warn
883882

884883
warn(
885-
(
886-
"Python module filelock was not found: AddCSVRow will not be"
887-
" thread-safe in multi-processor execution"
888-
)
884+
"Python module filelock was not found: AddCSVRow will not be"
885+
" thread-safe in multi-processor execution"
889886
)
890887

891888
input_dict = {}
@@ -926,7 +923,7 @@ def _list_outputs(self):
926923
return outputs
927924

928925
def _outputs(self):
929-
return self._add_output_traits(super(AddCSVRow, self)._outputs())
926+
return self._add_output_traits(super()._outputs())
930927

931928
def _add_output_traits(self, base):
932929
return base
@@ -1070,7 +1067,7 @@ def _run_interface(self, runtime):
10701067
def _gen_output_filename(self):
10711068
if not isdefined(self.inputs.out_file):
10721069
_, base, ext = split_filename(self.inputs.in_file)
1073-
out_file = os.path.abspath("%s_SNR%03.2f%s" % (base, self.inputs.snr, ext))
1070+
out_file = os.path.abspath(f"{base}_SNR{self.inputs.snr:03.2f}{ext}")
10741071
else:
10751072
out_file = self.inputs.out_file
10761073

@@ -1121,7 +1118,7 @@ def gen_noise(self, image, mask=None, snr_db=10.0, dist="normal", bg_dist="norma
11211118
im_noise = np.sqrt((image + stde_1) ** 2 + (stde_2) ** 2)
11221119
else:
11231120
raise NotImplementedError(
1124-
("Only normal and rician distributions " "are supported")
1121+
"Only normal and rician distributions " "are supported"
11251122
)
11261123

11271124
return im_noise
@@ -1547,7 +1544,7 @@ class CalculateMedian(BaseInterface):
15471544
output_spec = CalculateMedianOutputSpec
15481545

15491546
def __init__(self, *args, **kwargs):
1550-
super(CalculateMedian, self).__init__(*args, **kwargs)
1547+
super().__init__(*args, **kwargs)
15511548
self._median_files = []
15521549

15531550
def _gen_fname(self, suffix, idx=None, ext=None):
@@ -1569,10 +1566,10 @@ def _gen_fname(self, suffix, idx=None, ext=None):
15691566
if self.inputs.median_file:
15701567
outname = self.inputs.median_file
15711568
else:
1572-
outname = "{}_{}".format(fname, suffix)
1569+
outname = f"{fname}_{suffix}"
15731570
if idx:
15741571
outname += str(idx)
1575-
return op.abspath("{}.{}".format(outname, ext))
1572+
return op.abspath(f"{outname}.{ext}")
15761573

15771574
def _run_interface(self, runtime):
15781575
total = None

0 commit comments

Comments
 (0)