8000 MNT: run `ruff --fix` and `ruf format` · nipy/nibabel@98f3db5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 98f3db5

Browse files
MNT: run ruff --fix and ruf format
Also fix remaining issues manually.
1 parent 6c77892 commit 98f3db5

Some content is hidden

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

70 files changed

+80
-129
lines changed

doc/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
# Check for external Sphinx extensions we depend on
3232
try:
33-
import numpydoc
33+
import numpydoc # noqa: F401
3434
except ImportError:
3535
raise RuntimeError('Need to install "numpydoc" package for doc build')
3636
try:
37-
import texext
37+
import texext # noqa: F401
3838
except ImportError:
3939
raise RuntimeError('Need to install "texext" package for doc build')
4040

doc/tools/apigen.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ def discover_modules(self):
405405

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

doc/tools/build_modref_templates.py

Lines changed: 1 addition & 1 deletion
EED3
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99

10+
# ruff: noqa: F401
11+
1012
import os
1113

1214
from .info import long_description as __doc__
@@ -39,12 +41,10 @@
3941

4042
# module imports
4143
from . import analyze as ana
42-
from . import ecat, imagestats, mriutils
44+
from . import ecat, imagestats, mriutils, orientations, streamlines, viewers
4345
from . import nifti1 as ni1
44-
from . import orientations
4546
from . import spm2analyze as spm2
4647
from . import spm99analyze as spm99
47-
from . import streamlines, viewers
4848

4949
# isort: split
5050

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/cifti2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# copyright and license terms.
77
#
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
9+
# ruff: noqa: F401
910
"""CIFTI-2 format IO
1011
1112
.. currentmodule:: nibabel.cifti2

nibabel/cifti2/tests/test_cifti2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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/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/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_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/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)

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/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Reading functions for freesurfer files
22
"""
33

4+
# ruff: noqa: F401
5+
46
from .io import (
57
read_annot,
68
read_geometry,

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/gifti/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
gifti
1717
"""
1818

19+
# ruff: noqa: F401
20+
1921
from .gifti import (
2022
GiftiCoordSystem,
2123
GiftiDataArray,

nibabel/gifti/tests/test_gifti.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
"""
33
import itertools
44
import sys
5-
import warnings
65
from io import BytesIO
76

87
import numpy as np
98
import pytest
10-
from numpy.testing import assert_array_almost_equal, assert_array_equal
9+
from numpy.testing import assert_array_equal
1110

1211
from nibabel.tmpdirs import InTemporaryDirectory
1312

@@ -312,7 +311,7 @@ def test_metadata_list_interface():
312311
assert md['foo'] == 'bar'
313312

314313
# Append new NVPair
315-
with pytest.warns(DeprecationWarning) as w:
314+
with pytest.warns(DeprecationWarning) as _:
316315
nvpair = GiftiNVPairs('key', 'value')
317316
mdlist.append(nvpair)
318317
assert len(mdlist) == 2
@@ -327,15 +326,15 @@ def test_metadata_list_interface():
327326
assert len(md) == 0
328327

329328
# Extension adds multiple keys
330-
with pytest.warns(DeprecationWarning) as w:
329+
with pytest.warns(DeprecationWarning) as _:
331330
foobar = GiftiNVPairs('foo', 'bar')
332331
mdlist.extend([nvpair, foobar])
333332
assert len(mdlist) == 2
334333
assert len(md) == 2
335334
assert md == {'key': 'value', 'foo': 'bar'}
336335

337336
# Insertion updates list order, though we don't attempt to preserve it in the dict
338-
with pytest.warns(DeprecationWarning) as w:
337+
with pytest.warns(DeprecationWarning) as _:
339338
lastone = GiftiNVPairs('last', 'one')
340339
mdlist.insert(1, lastone)
341340
assert len(mdlist) == 3
@@ -358,14 +357,14 @@ def test_metadata_list_interface():
358357
mypair.value = 'strings'
359358
assert 'completelynew' not in md
360359
assert md == {'foo': 'bar', 'last': 'one'}
361-
# Check popping from the end (lastone inserted before foobar)
362-
lastpair = mdlist.pop()
360+
# Check popping from the end (last one inserted before foobar)
361+
_ = mdlist.pop()
363362
assert len(mdlist) == 1
364363
assert len(md) == 1
365364
assert md == {'last': 'one'}
366365

367366
# And let's remove an old pair with a new object
368-
with pytest.warns(DeprecationWarning) as w:
367+
with pytest.warns(DeprecationWarning) as _:
369368
lastoneagain = GiftiNVPairs('last', 'one')
370369
mdlist.remove(lastoneagain)
371370
assert len(mdlist) == 0

nibabel/gifti/tests/test_parse_gifti_fast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,13 @@ def test_external_file_failure_cases():
433433
shutil.copy(DATA_FILE7, '.')
434434
filename = pjoin(tmpdir, basename(DATA_FILE7))
435435
with pytest.raises(GiftiParseError):
436-
img = load(filename)
436+
_ = load(filename)
437437
# load from in-memory xml string (parser requires it as bytes)
438438
with open(DATA_FILE7, 'rb') as f:
439439
xmldata = f.read()
440440
parser = GiftiImageParser()
441441
with pytest.raises(GiftiParseError):
442-
img = parser.parse(xmldata)
442+
_ = parser.parse(xmldata)
443443

444444

445445
def test_load_compressed():

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/nicom/tests/test_ascconv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from os.path import dirname
66
from os.path import join as pjoin
77

8-
import numpy as np
98
from numpy.testing import assert_array_almost_equal, assert_array_equal
109

1110
from .. import ascconv

nibabel/nicom/tests/test_csareader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Testing Siemens CSA header reader
22
"""
33
import gzip
4-
import sys
54
from copy import deepcopy
65
from os.path import join as pjoin
76

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def test_image_position(self):
626626
def test_affine(self):
627627
# Make sure we find orientation/position/spacing info
628628
dw = didw.wrapper_from_file(DATA_FILE_4D)
629-
aff = dw.affine
629+
_ = dw.affine
630630

631631
@dicom_test
632632
@pytest.mark.xfail(reason='Not packaged in install', raises=FileNotFoundError)

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/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Multiformat-capable streamline format read / write interface
22
"""
3+
# ruff: noqa: F401
4+
35
import os
46
import warnings
57

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

0 commit comments

Comments
 (0)
0