Skip to content

Commit a2e5dee

Browse files
authored
Merge pull request #1289 from DimitriPapadopoulos/blue_ruff
MNT: blue/isort/flake8 → ruff
2 parents a6b8dcc + 066431d commit a2e5dee

File tree

172 files changed

+277
-349
lines changed

Some content is hidden

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

172 files changed

+277
-349
lines changed

.flake8

Lines changed: 0 additions & 9 deletions
This file was deleted.

.pep8speaks.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@ 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.3.4
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
27-
exclude: "^(doc|nisext|tools)/"
18+
- id: ruff
19+
args: [--fix, --show-fix, --exit-non-zero-on-fix]
20+
exclude: = ["doc", "tools"]
21+
- id: ruff-format
22+
exclude: = ["doc", "tools"]
2823
- repo: https://github.com/pre-commit/mirrors-mypy
2924
rev: v1.5.1
3025
hooks:

doc/source/conf.py

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

doc/tools/apigen.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,7 @@ def discover_modules(self):
405405

406406
def write_modules_api(self, modules, outdir):
407407
# upper-level modules
408-
main_module = modules[0].split('.')[0]
409-
ulms = [
410-
'.'.join(m.split('.')[:2]) if m.count('.') >= 1 else m.split('.')[0] for m in modules
411-
]
408+
ulms = ['.'.join(m.split('.')[:2]) for m in modules]
412409

413410
from collections import OrderedDict
414411

doc/tools/build_modref_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def abort(error):
3838

3939
try:
4040
__import__(package)
41-
except ImportError as e:
41+
except ImportError:
4242
abort('Can not import ' + package)
4343

4444
module = sys.modules[package]

nibabel/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,10 @@
3939

4040
# module imports
4141
from . import analyze as ana
42-
from . import ecat, imagestats, mriutils
42+
from . import ecat, imagestats, mriutils, orientations, streamlines, viewers
4343
from . import nifti1 as ni1
44-
from . import orientations
4544
from . import spm2analyze as spm2
4645
from . import spm99analyze as spm99
47-
from . import streamlines, viewers
4846

4947
# isort: split
5048

nibabel/_compression.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99
"""Constants and types for dealing transparently with compression"""
10+
1011
from __future__ import annotations
1112

1213
import bz2

nibabel/affines.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
"""Utility routines for working with points and affine transforms"""
4+
45
from functools import reduce
56

67
import numpy as np

nibabel/analyze.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
can be loaded with and without a default flip, so the saved zoom will not
8282
constrain the affine.
8383
"""
84+
8485
from __future__ import annotations
8586

8687
import numpy as np

nibabel/arrayproxy.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
2626
See :mod:`nibabel.tests.test_proxy_api` for proxy API conformance checks.
2727
"""
28+
2829
from __future__ import annotations
2930

3031
import typing as ty
@@ -74,21 +75,19 @@ class ArrayLike(ty.Protocol):
7475
shape: tuple[int, ...]
7576

7677
@property
77-
def ndim(self) -> int:
78-
... # pragma: no cover
78+
def ndim(self) -> int: ... # pragma: no cover
7979

8080
# If no dtype is passed, any dtype might be returned, depending on the array-like
8181
@ty.overload
82-
def __array__(self, dtype: None = ..., /) -> np.ndarray[ty.Any, np.dtype[ty.Any]]:
83-
... # pragma: no cover
82+
def __array__(
83+
self, dtype: None = ..., /
84+
) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: ... # pragma: no cover
8485

8586
# Any dtype might be passed, and *that* dtype must be returned
8687
@ty.overload
87-
def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]:
88-
... # pragma: no cover
88+
def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: ... # pragma: no cover
8989

90-
def __getitem__(self, key, /) -> npt.NDArray:
91-
... # pragma: no cover
90+
def __getitem__(self, key, /) -> npt.NDArray: ... # pragma: no cover
9291

9392

9493
class ArrayProxy(ArrayLike):

nibabel/arraywriters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(self, array, out_dtype=None)
2828
something else to make sense of conversions between float and int, or between
2929
larger ints and smaller.
3030
"""
31+
3132
import numpy as np
3233

3334
from .casting import best_float, floor_exact, int_abs, shared_range, type_info

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/benchmarks/butils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Benchmarking utilities
2-
"""
1+
"""Benchmarking utilities"""
32

43
from .. import get_info
54

nibabel/brikhead.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
am aware) always be >= 1. This permits sub-brick indexing common in AFNI
2727
programs (e.g., example4d+orig'[0]').
2828
"""
29+
2930
import os
3031
import re
3132
from copy import deepcopy

nibabel/casting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Most routines work round some numpy oddities in floating point precision and
44
casting. Others work round numpy casting to and from python ints
55
"""
6+
67
from __future__ import annotations
78

89
import warnings

nibabel/cifti2/cifti2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
http://www.nitrc.org/projects/cifti
1818
"""
19+
1920
import re
2021
from collections import OrderedDict
2122
from collections.abc import Iterable, MutableMapping, MutableSequence

nibabel/cifti2/cifti2_axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
... bm_cortex)))
119119
<class 'nibabel.cifti2.cifti2.Cifti2Header'>
120120
"""
121+
121122
import abc
122123
from operator import xor
123124

nibabel/cifti2/tests/test_cifti2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"""Testing CIFTI-2 objects
2-
"""
1+
"""Testing CIFTI-2 objects"""
2+
33
import collections
44
from xml.etree import ElementTree
55

66
import numpy as np
77
import pytest
88

99
from nibabel import cifti2 as ci
10-
from nibabel.cifti2.cifti2 import Cifti2HeaderError, _float_01, _value_if_klass
10+
from nibabel.cifti2.cifti2 import _float_01, _value_if_klass
1111
from nibabel.nifti2 import Nifti2Header
1212
from nibabel.tests.test_dataobj_images import TestDataobjAPI as _TDA
1313
from nibabel.tests.test_image_api import DtypeOverrideMixin, SerializeMixin

nibabel/cifti2/tests/test_cifti2io_header.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99

10-
import io
1110
from os.path import dirname
1211
from os.path import join as pjoin
1312

@@ -38,7 +37,7 @@
3837

3938

4039
def test_space_separated_affine():
41-
img = ci.Cifti2Image.from_filename(pjoin(NIBABEL_TEST_DATA, 'row_major.dconn.nii'))
40+
ci.Cifti2Image.from_filename(pjoin(NIBABEL_TEST_DATA, 'row_major.dconn.nii'))
4241

4342

4443
def test_read_nifti2():

nibabel/cifti2/tests/test_new_cifti2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
These functions are used in the tests to generate most CIFTI file types from
77
scratch.
88
"""
9+
910
import numpy as np
1011
import pytest
1112

nibabel/cmdline/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
# copyright and license terms.
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9-
"""Functionality to be exposed in the command line
10-
"""
9+
"""Functionality to be exposed in the command line"""

nibabel/cmdline/diff.py

Lines changed: 3 additions & 6 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
@@ -247,15 +246,14 @@ def get_data_diff(files, max_abs=0, max_rel=0, dtype=np.float64):
247246
sub_thr = rel_diff <= max_rel
248247
# Since we operated on sub-selected values already, we need
249248
# to plug them back in
250-
candidates[
251-
tuple(indexes[sub_thr] for indexes in np.where(candidates))
252-
] = False
249+
candidates[tuple(indexes[sub_thr] for indexes in np.where(candidates))] = (
250+
False
251+
)
253252
max_rel_diff = np.max(rel_diff)
254253
else:
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/cmdline/parrec2nii.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Code for PAR/REC to NIfTI converter command
2-
"""
1+
"""Code for PAR/REC to NIfTI converter command"""
32

43
import csv
54
import os

nibabel/cmdline/tck2trk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Convert tractograms (TCK -> TRK).
33
"""
4+
45
import argparse
56
import os
67

nibabel/cmdline/tests/test_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_convert_imgtype(tmp_path, ext, img_class):
119119

120120
def test_convert_nifti_int_fail(tmp_path):
121121
infile = get_test_data(fname='anatomical.nii')
122-
outfile = tmp_path / f'output.nii'
122+
outfile = tmp_path / 'output.nii'
123123

124124
orig = nib.load(infile)
125125
assert not outfile.exists()

nibabel/cmdline/tests/test_parrec2nii.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""Tests for the parrec2nii exe code
2-
"""
1+
"""Tests for the parrec2nii exe code"""
2+
33
from os.path import basename, isfile, join
44
from unittest.mock import MagicMock, Mock, patch
55

nibabel/cmdline/tests/test_roi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import unittest
32
from unittest import mock
43

54
import numpy as np
@@ -140,7 +139,7 @@ def test_entrypoint(capsys):
140139
# Check that we handle missing args as expected
141140
with mock.patch('sys.argv', ['nib-roi', '--help']):
142141
try:
143-
retval = main()
142+
main()
144143
except SystemExit:
145144
pass
146145
else:

nibabel/cmdline/tests/test_stats.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
#
99
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
1010

11-
import sys
12-
from io import StringIO
13-
1411
import numpy as np
1512

1613
from nibabel import Nifti1Image

nibabel/cmdline/tests/test_utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@
1212
import pytest
1313

1414
import nibabel as nib
15-
from nibabel.cmdline.diff import *
16-
from nibabel.cmdline.utils import *
15+
from nibabel.cmdline.diff import (
16+
display_diff,
17+
get_data_diff,
18+
get_data_hash_diff,
19+
get_headers_diff,
20+
main,
21+
)
22+
from nibabel.cmdline.utils import (
23+
ap,
24+
safe_get,
25+
table2string,
26+
)
1727
from nibabel.testing import data_path
1828

1929

nibabel/cmdline/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
Helper utilities to be used in cmdline applications
1111
"""
1212

13-
1413
# global verbosity switch
1514
import re
1615
from io import StringIO

nibabel/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Ignore warning requesting help with nicom
77
with pytest.warns(UserWarning):
8-
import nibabel.nicom
8+
import nibabel.nicom # noqa :401
99

1010

1111
@pytest.fixture(scope='session', autouse=True)

0 commit comments

Comments
 (0)