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)

nibabel/streamlines/tests/test_tractogram_file.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99

1010
def test_subclassing_tractogram_file():
11-
1211
# Missing 'save' method
1312
class DummyTractogramFile(TractogramFile):
1413
@classmethod

nibabel/streamlines/trk.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ def _read():
366366
tractogram = LazyTractogram.from_data_func(_read)
367367

368368
else:
369-
370369
# Speed up loading by guessing a suitable buffer size.
371370
with Opener(fileobj) as f:
372371
old_file_position = f.tell()
@@ -773,6 +772,4 @@ def __str__(self):
773772
swap_yz: {swap_yz}
774773
swap_zx: {swap_zx}
775774
n_count: {NB_STREAMLINES}
776-
hdr_size: {hdr_size}""".format(
777-
**vars
778-
)
775+
hdr_size: {hdr_size}""".format(**vars)

nibabel/tests/test_funcs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_concat():
5858

5959
# Loop over every possible axis, including None (explicit and implied)
6060
for axis in list(range(-(dim - 2), (dim - 1))) + [None, '__default__']:
61-
6261
# Allow testing default vs. passing explicit param
6362
if axis == '__default__':
6463
np_concat_kwargs = dict(axis=-1)

nibabel/tests/test_image_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def check_img(img_path, img_klass, sniff_mode, sniff, expect_success, msg):
8888
irrelevant=b'a' * (sizeof_hdr - 1), # A too-small sniff, query
8989
bad_sniff=b'a' * sizeof_hdr, # Bad sniff, should fail
9090
).items():
91-
9291
for klass in img_klasses:
9392
if klass == expected_img_klass:
9493
# Class will load unless you pass a bad sniff,

nibabel/tests/test_nifti1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ def unshear_44(affine):
731731

732732

733733
class TestNifti1SingleHeader(TestNifti1PairHeader):
734-
735734
header_class = Nifti1Header
736735

737736
def test_empty(self):

nibabel/tests/test_parrec.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ def test_dualTR():
884884
def test_ADC_map():
885885
# test reading an apparent diffusion coefficient map
886886
with open(ADC_PAR) as fobj:
887-
888887
# two truncation warnings expected because general_info indicates:
889888
# 1.) multiple directions
890889
# 2.) multiple b-values

nibabel/tests/test_spatialimages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def test_slicer(self):
400400
in_data_template = np.arange(240, dtype=np.int16)
401401
base_affine = np.eye(4)
402402
t_axis = None
403-
for dshape in ((4, 5, 6, 2), (8, 5, 6)): # Time series # Volume
403+
for dshape in ((4, 5, 6, 2), (8, 5, 6)): # Time series # Volume
404404
in_data = in_data_template.copy().reshape(dshape)
405405
img = img_klass(in_data, base_affine.copy())
406406

nisext/py3builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
except ImportError:
77
# 2.x - no parsing of code
88
from distutils.command.build_py import build_py
9-
else: # Python 3
9+
else: # Python 3
1010
# Command to also apply 2to3 to doctests
1111
from distutils import log
1212

nisext/testers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ def run_mod_cmd(mod_name, pkg_path, cmd, script_dir=None, print_location=True):
135135
os.environ['PYTHONPATH'] = r'"{pkg_path}"'
136136
else:
137137
os.environ['PYTHONPATH'] = r'"{pkg_path}"' + os.path.pathsep + PYTHONPATH
138-
""".format(
139-
**locals()
140-
)
138+
""".format(**locals())
141139
if print_location:
142140
p_loc = f'print({mod_name}.__file__);'
143141
else:
@@ -155,9 +153,7 @@ def run_mod_cmd(mod_name, pkg_path, cmd, script_dir=None, print_location=True):
155153
{paths_add}
156154
import {mod_name}
157155
{p_loc}
158-
{cmd}""".format(
159-
**locals()
160-
)
156+
{cmd}""".format(**locals())
161157
)
162158
res = back_tick(f'{PYTHON} script.py', ret_err=True)
163159
finally:

pyproject.toml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,32 @@ __version__ = version = {version!r}
109109
__version_tuple__ = version_tuple = {version_tuple!r}
110110
'''
111111

112-
[tool.blue]
113-
line_length = 99
114-
target-version = ["py38"]
115-
force-exclude = """
116-
(
117-
_version.py
118-
| nibabel/externals/
119-
| versioneer.py
120-
)
121-
"""
112+
[tool.ruff]
113+
line-length = 99
114+
exclude = ["version.py", "nibabel/externals", "versioneer.py"]
122115

123-
[tool.isort]
124-
profile = "black"
125-
line_length = 99
126-
extend_skip = ["_version.py", "externals"]
116+
[tool.ruff.lint]
117+
select = ["E4", "E7", "E9", "F", "I", "Q"]
118+
ignore = [
119+
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
120+
"W191",
121+
"E111",
122+
"E114",
123+
"E117",
124+
"D206",
125+
"D300",
126+
"Q000",
127+
"Q001",
128+
"Q002",
129+
"Q003",
130+
"COM812",
131+
"COM819",
132+
"ISC001",
133+
"ISC002",
134+
]
135+
136+
[tool.ruff.format]
137+
quote-style = "single"
127138

128139
[tool.mypy]
129140
python_version = "3.11"

tools/markdown_release_notes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def main():
2727
if in_release_notes:
2828
break
2929
in_release_notes = match.group(1) == version
30-
next(f) # Skip the underline
30+
next(f) # Skip the underline
3131
continue
3232

3333
if in_release_notes:

tox.ini

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,11 @@ commands =
139139
description = Check our style guide
140140
labels = check
141141
deps =
142-
flake8
143-
blue
144-
# Broken extras, remove when fix is released
145-
isort[colors]!=5.13.1
142+
ruff>=0.1.9
146143
skip_install = true
147144
commands =
148-
blue --check --diff --color nibabel
149-
isort --check --diff --color nibabel
150-
flake8 nibabel
145+
ruff --check --diff nibabel
146+
ruff --format --check --diff nibabel
151147

152148
[testenv:style-fix]
153149
description = Auto-apply style guide to the extent possible

0 commit comments

Comments
 (0)