Skip to content

Commit 136ff23

Browse files
MNT: blue/isort/flake8 → ruff
1 parent 1436a6e commit 136ff23

22 files changed

+45
-63
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,13 @@ repos:
1212
- id: check-case-conflict
1313
- id: check-merge-conflict
1414
- id: check-vcs-permalinks
15-
- repo: https://github.com/grantjenks/blue
16-
rev: v0.9.1
15+
- repo: https://github.com/astral-sh/ruff-pre-commit
16+
rev: v0.1.9
1717
hooks:
18-
- id: blue
19-
- repo: https://github.com/pycqa/isort
20-
rev: 5.12.0
21-
hooks:
22-
- id: isort
23-
- repo: https://github.com/pycqa/flake8
24-
rev: 6.1.0
25-
hooks:
26-
- id: flake8
18+
- id: ruff
19+
args: [--fix, --show-fix, --exit-non-zero-on-fix]
20+
exclude: "^(doc|nisext|tools)/"
21+
- id: ruff-format
2722
exclude: "^(doc|nisext|tools)/"
2823
- repo: https://github.com/pre-commit/mirrors-mypy
2924
rev: v1.5.1

nibabel/benchmarks/bench_arrayproxy_slicing.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656

5757

5858
def bench_arrayproxy_slicing():
59-
6059
print_git_title('\nArrayProxy gzip slicing')
6160

6261
# each test is a tuple containing
@@ -100,7 +99,6 @@ def fmt_sliceobj(sliceobj):
10099
return f"[{', '.join(slcstr)}]"
101100

102101
with InTemporaryDirectory():
103-
104102
print(f'Generating test data... ({int(round(np.prod(SHAPE) * 4 / 1048576.0))} MB)')
105103

106104
data = np.array(np.random.random(SHAPE), dtype=np.float32)
@@ -128,7 +126,6 @@ def fmt_sliceobj(sliceobj):
128126
seeds = [np.random.randint(0, 2**32) for s in SLICEOBJS]
129127

130128
for ti, test in enumerate(tests):
131-
132129
label = get_test_label(test)
133130
have_igzip, keep_open, sliceobj = test
134131
seed = seeds[SLICEOBJS.index(sliceobj)]

nibabel/cmdline/diff.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ def get_data_diff(files, max_abs=0, max_rel=0, dtype=np.float64):
231231
diffs1 = [None] * (i + 1)
232232

233233
for j, d2 in enumerate(data[i + 1 :], i + 1):
234-
235234
if d1.shape == d2.shape:
236235
abs_diff = np.abs(d1 - d2)
237236
mean_abs = (np.abs(d1) + np.abs(d2)) * 0.5
@@ -255,7 +254,6 @@ def get_data_diff(files, max_abs=0, max_rel=0, dtype=np.float64):
255254
max_rel_diff = 0
256255

257256
if np.any(candidates):
258-
259257
diff_rec = OrderedDict() # so that abs goes before relative
260258

261259
diff_rec['abs'] = max_abs_diff.astype(dtype)
@@ -268,7 +266,6 @@ def get_data_diff(files, max_abs=0, max_rel=0, dtype=np.float64):
268266
diffs1.append({'CMP': 'incompat'})
269267

270268
if any(diffs1):
271-
272269
diffs['DATA(diff %d:)' % (i + 1)] = diffs1
273270

274271
return diffs

nibabel/dft.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def as_nifti(self):
161161
data = numpy.ndarray(
162162
(len(self.storage_instances), self.rows, self.columns), dtype=numpy.int16
163163
)
164-
for (i, si) in enumerate(self.storage_instances):
164+
for i, si in enumerate(self.storage_instances):
165165
if i + 1 != si.instance_number:
166166
raise InstanceStackError(self, i, si)
167167
logger.info('reading %d/%d' % (i + 1, len(self.storage_instances)))
@@ -243,7 +243,7 @@ def dicom(self):
243243

244244
def _get_subdirs(base_dir, files_dict=None, followlinks=False):
245245
dirs = []
246-
for (dirpath, dirnames, filenames) in os.walk(base_dir, followlinks=followlinks):
246+
for dirpath, dirnames, filenames in os.walk(base_dir, followlinks=followlinks):
247247
abs_dir = os.path.realpath(dirpath)
248248
if abs_dir in dirs:
249249
raise CachingError(f'link cycle detected under {base_dir}')

nibabel/ecat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,6 @@ def read_subheaders(fileobj, mlist, endianness):
513513

514514

515515
class EcatSubHeader:
516-
517516
_subhdrdtype = subhdr_dtype
518517
_data_type_codes = data_type_codes
519518

nibabel/freesurfer/tests/test_mghformat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ def test_as_byteswapped(self):
460460
for endianness in (None,) + LITTLE_CODES:
461461
with pytest.raises(ValueError):
462462
hdr.as_byteswapped(endianness)
463+
463464
# Note that contents is not rechecked on swap / copy
464465
class DC(self.header_class):
465466
def check_fix(self, *args, **kwargs):

nibabel/info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@
108108
109109
.. _Digital Object Identifier: https://en.wikipedia.org/wiki/Digital_object_identifier
110110
.. _zenodo: https://zenodo.org
111-
""" # noqa: E501
111+
""" # noqa: E501

nibabel/openers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ def _gzip_open(
8686
mtime: int = 0,
8787
keep_open: bool = False,
8888
) -> gzip.GzipFile:
89-
9089
if not HAVE_INDEXED_GZIP or mode != 'rb':
9190
gzip_file = DeterministicGzipFile(filename, mode, compresslevel, mtime=mtime)
9291

@@ -129,6 +128,7 @@ class Opener:
129128
passed to opening method when `fileish` is str. Change of defaults as
130129
for \*args
131130
"""
131+
132132
gz_def = (_gzip_open, ('mode', 'compresslevel', 'mtime', 'keep_open'))
133133
bz2_def = (BZ2File, ('mode', 'buffering', 'compresslevel'))
134134
zstd_def = (_zstd_open, ('mode', 'level_or_option', 'zstd_dict'))

nibabel/streamlines/tck.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ def _read_header(cls, fileobj):
309309
offset_data = 0
310310

311311
with Opener(fileobj) as f:
312-
313312
# Record start position
314313
start_position = f.tell()
315314

nibabel/streamlines/tests/test_tractogram.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def setup_module():
165165

166166

167167
def check_tractogram_item(tractogram_item, streamline, data_for_streamline={}, data_for_points={}):
168-
169168
assert_array_equal(tractogram_item.streamline, streamline)
170169

171170
assert len(tractogram_item.data_for_streamline) == len(data_for_streamline)

0 commit comments

Comments
 (0)