From 733c0f36af71808185245617a156b3e7b4bd26a2 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 26 Dec 2023 14:00:58 +0100 Subject: [PATCH 01/32] =?UTF-8?q?MNT:=20blue/isort/flake8=20=E2=86=92=20ru?= =?UTF-8?q?ff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 19 +++++++------------ pyproject.toml | 39 +++++++++++++++++++++++++-------------- tox.ini | 17 ++++++----------- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b620a6de..ef2d891fb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,19 +12,14 @@ repos: - id: check-case-conflict - id: check-merge-conflict - id: check-vcs-permalinks - - repo: https://github.com/grantjenks/blue - rev: v0.9.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.9 hooks: - - id: blue - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 - hooks: - - id: flake8 - exclude: "^(doc|nisext|tools)/" + - id: ruff + args: [--fix, --show-fix, --exit-non-zero-on-fix] + exclude: = ["doc", "tools"] + - id: ruff-format + exclude: = ["doc", "tools"] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.5.1 hooks: diff --git a/pyproject.toml b/pyproject.toml index 3cd81f93e..515c35850 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -109,21 +109,32 @@ __version__ = version = {version!r} __version_tuple__ = version_tuple = {version_tuple!r} ''' -[tool.blue] -line_length = 99 -target-version = ["py38"] -force-exclude = """ -( - _version.py - | nibabel/externals/ - | versioneer.py -) -""" +[tool.ruff] +line-length = 99 +exclude = ["doc", "nibabel/externals", "tools", "version.py", "versioneer.py"] -[tool.isort] -profile = "black" -line_length = 99 -extend_skip = ["_version.py", "externals"] +[tool.ruff.lint] +select = ["F", "I", "Q"] +ignore = [ + # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules + "W191", + "E111", + "E114", + "E117", + "D206", + "D300", + "Q000", + "Q001", + "Q002", + "Q003", + "COM812", + "COM819", + "ISC001", + "ISC002", +] + +[tool.ruff.format] +quote-style = "single" [tool.mypy] python_version = "3.11" diff --git a/tox.ini b/tox.ini index cc2b263cb..4e9b220ce 100644 --- a/tox.ini +++ b/tox.ini @@ -139,26 +139,21 @@ commands = description = Check our style guide labels = check deps = - flake8 - blue - # Broken extras, remove when fix is released - isort[colors]!=5.13.1 + ruff>=0.1.9 skip_install = true commands = - blue --check --diff --color nibabel - isort --check --diff --color nibabel - flake8 nibabel + ruff --diff nibabel + ruff format --diff nibabel [testenv:style-fix] description = Auto-apply style guide to the extent possible labels = pre-release deps = - blue - isort + ruff skip_install = true commands = - blue nibabel - isort nibabel + ruff --fix nibabel + ruff format nibabel [testenv:spellcheck] description = Check spelling From 39429f9708ede298088c1a9206fca83ef2b73b49 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 26 Dec 2023 15:17:14 +0100 Subject: [PATCH 02/32] MNT: run `ruff --fix` and `ruf format` Also fix remaining issues manually. --- doc/source/conf.py | 4 ++-- doc/tools/apigen.py | 1 - doc/tools/build_modref_templates.py | 2 +- nibabel/__init__.py | 6 +++--- nibabel/benchmarks/bench_arrayproxy_slicing.py | 3 --- nibabel/cifti2/__init__.py | 1 + nibabel/cifti2/tests/test_cifti2.py | 2 +- nibabel/cifti2/tests/test_cifti2io_header.py | 3 +-- nibabel/cmdline/diff.py | 3 --- nibabel/cmdline/tests/test_convert.py | 2 +- nibabel/cmdline/tests/test_roi.py | 3 +-- nibabel/cmdline/tests/test_stats.py | 3 --- nibabel/cmdline/tests/test_utils.py | 14 ++++++++++++-- nibabel/conftest.py | 2 +- nibabel/dft.py | 4 ++-- nibabel/ecat.py | 1 - nibabel/freesurfer/__init__.py | 2 ++ nibabel/freesurfer/tests/test_mghformat.py | 1 + nibabel/gifti/__init__.py | 2 ++ nibabel/gifti/tests/test_gifti.py | 13 ++++++------- nibabel/gifti/tests/test_parse_gifti_fast.py | 4 ++-- nibabel/info.py | 2 +- nibabel/nicom/tests/test_ascconv.py | 1 - nibabel/nicom/tests/test_csareader.py | 1 - nibabel/nicom/tests/test_dicomwrappers.py | 2 +- nibabel/openers.py | 2 +- nibabel/streamlines/__init__.py | 2 ++ nibabel/streamlines/tck.py | 1 - nibabel/streamlines/tests/test_array_sequence.py | 3 +-- nibabel/streamlines/tests/test_streamlines.py | 1 - nibabel/streamlines/tests/test_tck.py | 3 +-- nibabel/streamlines/tests/test_tractogram.py | 2 -- nibabel/streamlines/tests/test_tractogram_file.py | 1 - nibabel/streamlines/tests/test_trk.py | 2 +- nibabel/streamlines/trk.py | 5 +---- nibabel/testing/__init__.py | 3 +++ nibabel/tests/nibabel_data.py | 3 +-- nibabel/tests/scriptrunner.py | 3 +-- nibabel/tests/test_affines.py | 2 +- nibabel/tests/test_arraywriters.py | 6 +++--- nibabel/tests/test_brikhead.py | 2 +- nibabel/tests/test_data.py | 2 +- nibabel/tests/test_ecat.py | 1 - nibabel/tests/test_ecat_data.py | 2 +- nibabel/tests/test_floating.py | 3 --- nibabel/tests/test_funcs.py | 1 - nibabel/tests/test_image_load_save.py | 3 +-- nibabel/tests/test_image_types.py | 1 - nibabel/tests/test_imageclasses.py | 4 +--- nibabel/tests/test_init.py | 1 + nibabel/tests/test_minc1.py | 6 +----- nibabel/tests/test_minc2.py | 2 +- nibabel/tests/test_nibabel_data.py | 3 +-- nibabel/tests/test_nifti1.py | 1 - nibabel/tests/test_nifti2.py | 2 +- nibabel/tests/test_openers.py | 1 - nibabel/tests/test_orientations.py | 2 -- nibabel/tests/test_parrec.py | 5 ++--- nibabel/tests/test_parrec_data.py | 4 +--- nibabel/tests/test_pkg_info.py | 2 +- nibabel/tests/test_pointset.py | 3 --- nibabel/tests/test_quaternions.py | 7 ------- nibabel/tests/test_removalschedule.py | 1 - nibabel/tests/test_scripts.py | 5 ++--- nibabel/tests/test_spatialimages.py | 3 +-- nibabel/tests/test_testing.py | 4 ++-- nibabel/tests/test_wrapstruct.py | 9 --------- tools/make_tarball.py | 2 +- tools/markdown_release_notes.py | 2 +- tools/mpkg_wrapper.py | 2 +- 70 files changed, 79 insertions(+), 128 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 175c6340b..e8999b7d2 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -30,11 +30,11 @@ # Check for external Sphinx extensions we depend on try: - import numpydoc + import numpydoc # noqa: F401 except ImportError: raise RuntimeError('Need to install "numpydoc" package for doc build') try: - import texext + import texext # noqa: F401 except ImportError: raise RuntimeError('Need to install "texext" package for doc build') diff --git a/doc/tools/apigen.py b/doc/tools/apigen.py index 316736264..a1279a3e9 100644 --- a/doc/tools/apigen.py +++ b/doc/tools/apigen.py @@ -405,7 +405,6 @@ def discover_modules(self): def write_modules_api(self, modules, outdir): # upper-level modules - main_module = modules[0].split('.')[0] ulms = [ '.'.join(m.split('.')[:2]) if m.count('.') >= 1 else m.split('.')[0] for m in modules ] diff --git a/doc/tools/build_modref_templates.py b/doc/tools/build_modref_templates.py index 11eae9974..0e82cf6bf 100755 --- a/doc/tools/build_modref_templates.py +++ b/doc/tools/build_modref_templates.py @@ -38,7 +38,7 @@ def abort(error): try: __import__(package) - except ImportError as e: + except ImportError: abort('Can not import ' + package) module = sys.modules[package] diff --git a/nibabel/__init__.py b/nibabel/__init__.py index db427435a..1cb7abf53 100644 --- a/nibabel/__init__.py +++ b/nibabel/__init__.py @@ -7,6 +7,8 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## +# ruff: noqa: F401 + import os from .info import long_description as __doc__ @@ -39,12 +41,10 @@ # module imports from . import analyze as ana -from . import ecat, imagestats, mriutils +from . import ecat, imagestats, mriutils, orientations, streamlines, viewers from . import nifti1 as ni1 -from . import orientations from . import spm2analyze as spm2 from . import spm99analyze as spm99 -from . import streamlines, viewers # isort: split diff --git a/nibabel/benchmarks/bench_arrayproxy_slicing.py b/nibabel/benchmarks/bench_arrayproxy_slicing.py index 305c5215e..3444cb8d8 100644 --- a/nibabel/benchmarks/bench_arrayproxy_slicing.py +++ b/nibabel/benchmarks/bench_arrayproxy_slicing.py @@ -56,7 +56,6 @@ def bench_arrayproxy_slicing(): - print_git_title('\nArrayProxy gzip slicing') # each test is a tuple containing @@ -100,7 +99,6 @@ def fmt_sliceobj(sliceobj): return f"[{', '.join(slcstr)}]" with InTemporaryDirectory(): - print(f'Generating test data... ({int(round(np.prod(SHAPE) * 4 / 1048576.0))} MB)') data = np.array(np.random.random(SHAPE), dtype=np.float32) @@ -128,7 +126,6 @@ def fmt_sliceobj(sliceobj): seeds = [np.random.randint(0, 2**32) for s in SLICEOBJS] for ti, test in enumerate(tests): - label = get_test_label(test) have_igzip, keep_open, sliceobj = test seed = seeds[SLICEOBJS.index(sliceobj)] diff --git a/nibabel/cifti2/__init__.py b/nibabel/cifti2/__init__.py index 9c6805f81..4a5cad767 100644 --- a/nibabel/cifti2/__init__.py +++ b/nibabel/cifti2/__init__.py @@ -6,6 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## +# ruff: noqa: F401 """CIFTI-2 format IO .. currentmodule:: nibabel.cifti2 diff --git a/nibabel/cifti2/tests/test_cifti2.py b/nibabel/cifti2/tests/test_cifti2.py index bf287b8e0..d7fd0a0ed 100644 --- a/nibabel/cifti2/tests/test_cifti2.py +++ b/nibabel/cifti2/tests/test_cifti2.py @@ -7,7 +7,7 @@ import pytest from nibabel import cifti2 as ci -from nibabel.cifti2.cifti2 import Cifti2HeaderError, _float_01, _value_if_klass +from nibabel.cifti2.cifti2 import _float_01, _value_if_klass from nibabel.nifti2 import Nifti2Header from nibabel.tests.test_dataobj_images import TestDataobjAPI as _TDA from nibabel.tests.test_image_api import DtypeOverrideMixin, SerializeMixin diff --git a/nibabel/cifti2/tests/test_cifti2io_header.py b/nibabel/cifti2/tests/test_cifti2io_header.py index 8d393686d..92078a26d 100644 --- a/nibabel/cifti2/tests/test_cifti2io_header.py +++ b/nibabel/cifti2/tests/test_cifti2io_header.py @@ -7,7 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -import io from os.path import dirname from os.path import join as pjoin @@ -38,7 +37,7 @@ def test_space_separated_affine(): - img = ci.Cifti2Image.from_filename(pjoin(NIBABEL_TEST_DATA, 'row_major.dconn.nii')) + _ = ci.Cifti2Image.from_filename(pjoin(NIBABEL_TEST_DATA, 'row_major.dconn.nii')) def test_read_nifti2(): diff --git a/nibabel/cmdline/diff.py b/nibabel/cmdline/diff.py index b409c7205..d20a105e7 100755 --- a/nibabel/cmdline/diff.py +++ b/nibabel/cmdline/diff.py @@ -231,7 +231,6 @@ def get_data_diff(files, max_abs=0, max_rel=0, dtype=np.float64): diffs1 = [None] * (i + 1) for j, d2 in enumerate(data[i + 1 :], i + 1): - if d1.shape == d2.shape: abs_diff = np.abs(d1 - d2) 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): max_rel_diff = 0 if np.any(candidates): - diff_rec = OrderedDict() # so that abs goes before relative 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): diffs1.append({'CMP': 'incompat'}) if any(diffs1): - diffs['DATA(diff %d:)' % (i + 1)] = diffs1 return diffs diff --git a/nibabel/cmdline/tests/test_convert.py b/nibabel/cmdline/tests/test_convert.py index 4605bc810..021e6ea8e 100644 --- a/nibabel/cmdline/tests/test_convert.py +++ b/nibabel/cmdline/tests/test_convert.py @@ -119,7 +119,7 @@ def test_convert_imgtype(tmp_path, ext, img_class): def test_convert_nifti_int_fail(tmp_path): infile = get_test_data(fname='anatomical.nii') - outfile = tmp_path / f'output.nii' + outfile = tmp_path / 'output.nii' orig = nib.load(infile) assert not outfile.exists() diff --git a/nibabel/cmdline/tests/test_roi.py b/nibabel/cmdline/tests/test_roi.py index ea3852b4d..d2baa80ee 100644 --- a/nibabel/cmdline/tests/test_roi.py +++ b/nibabel/cmdline/tests/test_roi.py @@ -1,5 +1,4 @@ import os -import unittest from unittest import mock import numpy as np @@ -140,7 +139,7 @@ def test_entrypoint(capsys): # Check that we handle missing args as expected with mock.patch('sys.argv', ['nib-roi', '--help']): try: - retval = main() + main() except SystemExit: pass else: diff --git a/nibabel/cmdline/tests/test_stats.py b/nibabel/cmdline/tests/test_stats.py index 576a408bc..905114e31 100644 --- a/nibabel/cmdline/tests/test_stats.py +++ b/nibabel/cmdline/tests/test_stats.py @@ -8,9 +8,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -import sys -from io import StringIO - import numpy as np from nibabel import Nifti1Image diff --git a/nibabel/cmdline/tests/test_utils.py b/nibabel/cmdline/tests/test_utils.py index 8143d648d..0efb5ee0b 100644 --- a/nibabel/cmdline/tests/test_utils.py +++ b/nibabel/cmdline/tests/test_utils.py @@ -12,8 +12,18 @@ import pytest import nibabel as nib -from nibabel.cmdline.diff import * -from nibabel.cmdline.utils import * +from nibabel.cmdline.diff import ( + display_diff, + get_data_diff, + get_data_hash_diff, + get_headers_diff, + main, +) +from nibabel.cmdline.utils import ( + ap, + safe_get, + table2string, +) from nibabel.testing import data_path diff --git a/nibabel/conftest.py b/nibabel/conftest.py index 5eba256fa..a4f8b6de9 100644 --- a/nibabel/conftest.py +++ b/nibabel/conftest.py @@ -5,7 +5,7 @@ # Ignore warning requesting help with nicom with pytest.warns(UserWarning): - import nibabel.nicom + import nibabel.nicom # noqa :401 @pytest.fixture(scope='session', autouse=True) diff --git a/nibabel/dft.py b/nibabel/dft.py index ee34595b3..aeb8accbb 100644 --- a/nibabel/dft.py +++ b/nibabel/dft.py @@ -161,7 +161,7 @@ def as_nifti(self): data = numpy.ndarray( (len(self.storage_instances), self.rows, self.columns), dtype=numpy.int16 ) - for (i, si) in enumerate(self.storage_instances): + for i, si in enumerate(self.storage_instances): if i + 1 != si.instance_number: raise InstanceStackError(self, i, si) logger.info('reading %d/%d' % (i + 1, len(self.storage_instances))) @@ -243,7 +243,7 @@ def dicom(self): def _get_subdirs(base_dir, files_dict=None, followlinks=False): dirs = [] - for (dirpath, dirnames, filenames) in os.walk(base_dir, followlinks=followlinks): + for dirpath, dirnames, filenames in os.walk(base_dir, followlinks=followlinks): abs_dir = os.path.realpath(dirpath) if abs_dir in dirs: raise CachingError(f'link cycle detected under {base_dir}') diff --git a/nibabel/ecat.py b/nibabel/ecat.py index 1db902d10..85de9184b 100644 --- a/nibabel/ecat.py +++ b/nibabel/ecat.py @@ -513,7 +513,6 @@ def read_subheaders(fileobj, mlist, endianness): class EcatSubHeader: - _subhdrdtype = subhdr_dtype _data_type_codes = data_type_codes diff --git a/nibabel/freesurfer/__init__.py b/nibabel/freesurfer/__init__.py index 806d19a27..48922285c 100644 --- a/nibabel/freesurfer/__init__.py +++ b/nibabel/freesurfer/__init__.py @@ -1,6 +1,8 @@ """Reading functions for freesurfer files """ +# ruff: noqa: F401 + from .io import ( read_annot, read_geometry, diff --git a/nibabel/freesurfer/tests/test_mghformat.py b/nibabel/freesurfer/tests/test_mghformat.py index 189f1a9dd..d69587811 100644 --- a/nibabel/freesurfer/tests/test_mghformat.py +++ b/nibabel/freesurfer/tests/test_mghformat.py @@ -460,6 +460,7 @@ def test_as_byteswapped(self): for endianness in (None,) + LITTLE_CODES: with pytest.raises(ValueError): hdr.as_byteswapped(endianness) + # Note that contents is not rechecked on swap / copy class DC(self.header_class): def check_fix(self, *args, **kwargs): diff --git a/nibabel/gifti/__init__.py b/nibabel/gifti/__init__.py index f54a1d2e5..d2a1e2da6 100644 --- a/nibabel/gifti/__init__.py +++ b/nibabel/gifti/__init__.py @@ -16,6 +16,8 @@ gifti """ +# ruff: noqa: F401 + from .gifti import ( GiftiCoordSystem, GiftiDataArray, diff --git a/nibabel/gifti/tests/test_gifti.py b/nibabel/gifti/tests/test_gifti.py index 5cc2756c6..7e4c22397 100644 --- a/nibabel/gifti/tests/test_gifti.py +++ b/nibabel/gifti/tests/test_gifti.py @@ -2,12 +2,11 @@ """ import itertools import sys -import warnings from io import BytesIO import numpy as np import pytest -from numpy.testing import assert_array_almost_equal, assert_array_equal +from numpy.testing import assert_array_equal from nibabel.tmpdirs import InTemporaryDirectory @@ -329,7 +328,7 @@ def test_metadata_list_interface(): assert len(md) == 0 # Extension adds multiple keys - with pytest.warns(DeprecationWarning) as w: + with pytest.warns(DeprecationWarning) as _: foobar = GiftiNVPairs('foo', 'bar') mdlist.extend([nvpair, foobar]) assert len(mdlist) == 2 @@ -337,7 +336,7 @@ def test_metadata_list_interface(): assert md == {'key': 'value', 'foo': 'bar'} # Insertion updates list order, though we don't attempt to preserve it in the dict - with pytest.warns(DeprecationWarning) as w: + with pytest.warns(DeprecationWarning) as _: lastone = GiftiNVPairs('last', 'one') mdlist.insert(1, lastone) assert len(mdlist) == 3 @@ -360,14 +359,14 @@ def test_metadata_list_interface(): mypair.value = 'strings' assert 'completelynew' not in md assert md == {'foo': 'bar', 'last': 'one'} - # Check popping from the end (lastone inserted before foobar) - lastpair = mdlist.pop() + # Check popping from the end (last one inserted before foobar) + _ = mdlist.pop() assert len(mdlist) == 1 assert len(md) == 1 assert md == {'last': 'one'} # And let's remove an old pair with a new object - with pytest.warns(DeprecationWarning) as w: + with pytest.warns(DeprecationWarning) as _: lastoneagain = GiftiNVPairs('last', 'one') mdlist.remove(lastoneagain) assert len(mdlist) == 0 diff --git a/nibabel/gifti/tests/test_parse_gifti_fast.py b/nibabel/gifti/tests/test_parse_gifti_fast.py index f97242567..17258fbd3 100644 --- a/nibabel/gifti/tests/test_parse_gifti_fast.py +++ b/nibabel/gifti/tests/test_parse_gifti_fast.py @@ -447,13 +447,13 @@ def test_external_file_failure_cases(): shutil.copy(DATA_FILE7, '.') filename = pjoin(tmpdir, basename(DATA_FILE7)) with pytest.raises(GiftiParseError): - img = load(filename) + _ = load(filename) # load from in-memory xml string (parser requires it as bytes) with open(DATA_FILE7, 'rb') as f: xmldata = f.read() parser = GiftiImageParser() with pytest.raises(GiftiParseError): - img = parser.parse(xmldata) + _ = parser.parse(xmldata) def test_load_compressed(): diff --git a/nibabel/info.py b/nibabel/info.py index a608932fa..d7873de21 100644 --- a/nibabel/info.py +++ b/nibabel/info.py @@ -108,4 +108,4 @@ .. _Digital Object Identifier: https://en.wikipedia.org/wiki/Digital_object_identifier .. _zenodo: https://zenodo.org -""" # noqa: E501 +""" # noqa: E501 diff --git a/nibabel/nicom/tests/test_ascconv.py b/nibabel/nicom/tests/test_ascconv.py index cd27bc319..cf40298c5 100644 --- a/nibabel/nicom/tests/test_ascconv.py +++ b/nibabel/nicom/tests/test_ascconv.py @@ -5,7 +5,6 @@ from os.path import dirname from os.path import join as pjoin -import numpy as np from numpy.testing import assert_array_almost_equal, assert_array_equal from .. import ascconv diff --git a/nibabel/nicom/tests/test_csareader.py b/nibabel/nicom/tests/test_csareader.py index 0fc559c7f..ddb46a942 100644 --- a/nibabel/nicom/tests/test_csareader.py +++ b/nibabel/nicom/tests/test_csareader.py @@ -1,7 +1,6 @@ """Testing Siemens CSA header reader """ import gzip -import sys from copy import deepcopy from os.path import join as pjoin diff --git a/nibabel/nicom/tests/test_dicomwrappers.py b/nibabel/nicom/tests/test_dicomwrappers.py index 5c2934936..fa2dfc07c 100755 --- a/nibabel/nicom/tests/test_dicomwrappers.py +++ b/nibabel/nicom/tests/test_dicomwrappers.py @@ -631,7 +631,7 @@ def test_image_position(self): def test_affine(self): # Make sure we find orientation/position/spacing info dw = didw.wrapper_from_file(DATA_FILE_4D) - aff = dw.affine + _ = dw.affine @dicom_test @pytest.mark.xfail(reason='Not packaged in install', raises=FileNotFoundError) diff --git a/nibabel/openers.py b/nibabel/openers.py index 90c7774d1..d69412fb8 100644 --- a/nibabel/openers.py +++ b/nibabel/openers.py @@ -86,7 +86,6 @@ def _gzip_open( mtime: int = 0, keep_open: bool = False, ) -> gzip.GzipFile: - if not HAVE_INDEXED_GZIP or mode != 'rb': gzip_file = DeterministicGzipFile(filename, mode, compresslevel, mtime=mtime) @@ -129,6 +128,7 @@ class Opener: passed to opening method when `fileish` is str. Change of defaults as for \*args """ + gz_def = (_gzip_open, ('mode', 'compresslevel', 'mtime', 'keep_open')) bz2_def = (BZ2File, ('mode', 'buffering', 'compresslevel')) zstd_def = (_zstd_open, ('mode', 'level_or_option', 'zstd_dict')) diff --git a/nibabel/streamlines/__init__.py b/nibabel/streamlines/__init__.py index f99f80e4e..f3cbd2da5 100644 --- a/nibabel/streamlines/__init__.py +++ b/nibabel/streamlines/__init__.py @@ -1,5 +1,7 @@ """Multiformat-capable streamline format read / write interface """ +# ruff: noqa: F401 + import os import warnings diff --git a/nibabel/streamlines/tck.py b/nibabel/streamlines/tck.py index 43df2f87e..358c57936 100644 --- a/nibabel/streamlines/tck.py +++ b/nibabel/streamlines/tck.py @@ -309,7 +309,6 @@ def _read_header(cls, fileobj): offset_data = 0 with Opener(fileobj) as f: - # Record start position start_position = f.tell() diff --git a/nibabel/streamlines/tests/test_array_sequence.py b/nibabel/streamlines/tests/test_array_sequence.py index 0c8557fe5..a06b2c45d 100644 --- a/nibabel/streamlines/tests/test_array_sequence.py +++ b/nibabel/streamlines/tests/test_array_sequence.py @@ -1,6 +1,5 @@ import itertools import os -import sys import tempfile import unittest @@ -220,7 +219,7 @@ def test_arraysequence_extend(self): seq.extend(data) # Extend after extracting some slice - working_slice = seq[:2] + _ = seq[:2] seq.extend(ArraySequence(new_data)) def test_arraysequence_getitem(self): diff --git a/nibabel/streamlines/tests/test_streamlines.py b/nibabel/streamlines/tests/test_streamlines.py index 300397b2b..f0bd9c7c4 100644 --- a/nibabel/streamlines/tests/test_streamlines.py +++ b/nibabel/streamlines/tests/test_streamlines.py @@ -1,5 +1,4 @@ import os -import tempfile import unittest import warnings from io import BytesIO diff --git a/nibabel/streamlines/tests/test_tck.py b/nibabel/streamlines/tests/test_tck.py index 3df7dd4f2..6b4c163ed 100644 --- a/nibabel/streamlines/tests/test_tck.py +++ b/nibabel/streamlines/tests/test_tck.py @@ -8,7 +8,6 @@ from numpy.testing import assert_array_equal from ...testing import data_path, error_warnings -from .. import tck as tck_module from ..array_sequence import ArraySequence from ..tck import TckFile from ..tractogram import Tractogram @@ -138,7 +137,7 @@ def test_load_file_with_wrong_information(self): # Simulate a TCK file with no `file` field. new_tck_file = tck_file.replace(b'\nfile: . 67', b'') - with pytest.warns(HeaderWarning, match="Missing 'file'") as w: + with pytest.warns(HeaderWarning, match="Missing 'file'") as _: tck = TckFile.load(BytesIO(new_tck_file)) assert_array_equal(tck.header['file'], '. 56') diff --git a/nibabel/streamlines/tests/test_tractogram.py b/nibabel/streamlines/tests/test_tractogram.py index 09e3b910b..915968854 100644 --- a/nibabel/streamlines/tests/test_tractogram.py +++ b/nibabel/streamlines/tests/test_tractogram.py @@ -1,6 +1,5 @@ import copy import operator -import sys import unittest import warnings from collections import defaultdict @@ -172,7 +171,6 @@ def setup_module(): def check_tractogram_item(tractogram_item, streamline, data_for_streamline={}, data_for_points={}): - assert_array_equal(tractogram_item.streamline, streamline) assert len(tractogram_item.data_for_streamline) == len(data_for_streamline) diff --git a/nibabel/streamlines/tests/test_tractogram_file.py b/nibabel/streamlines/tests/test_tractogram_file.py index 53a7fb662..71e2326ec 100644 --- a/nibabel/streamlines/tests/test_tractogram_file.py +++ b/nibabel/streamlines/tests/test_tractogram_file.py @@ -8,7 +8,6 @@ def test_subclassing_tractogram_file(): - # Missing 'save' method class DummyTractogramFile(TractogramFile): @classmethod diff --git a/nibabel/streamlines/tests/test_trk.py b/nibabel/streamlines/tests/test_trk.py index b8ff43620..749bf3ed3 100644 --- a/nibabel/streamlines/tests/test_trk.py +++ b/nibabel/streamlines/tests/test_trk.py @@ -149,7 +149,7 @@ def test_load_file_with_wrong_information(self): # Simulate a TRK where `vox_to_ras` is invalid. trk_struct, trk_bytes = self.trk_with_bytes() trk_struct[Field.VOXEL_TO_RASMM] = np.diag([0, 0, 0, 1]) - with clear_and_catch_warnings(record=True, modules=[trk_module]) as w: + with clear_and_catch_warnings(record=True, modules=[trk_module]) as _: with pytest.raises(HeaderError): TrkFile.load(BytesIO(trk_bytes)) diff --git a/nibabel/streamlines/trk.py b/nibabel/streamlines/trk.py index 966b133d1..0b11f5684 100644 --- a/nibabel/streamlines/trk.py +++ b/nibabel/streamlines/trk.py @@ -366,7 +366,6 @@ def _read(): tractogram = LazyTractogram.from_data_func(_read) else: - # Speed up loading by guessing a suitable buffer size. with Opener(fileobj) as f: old_file_position = f.tell() @@ -773,6 +772,4 @@ def __str__(self): swap_yz: {swap_yz} swap_zx: {swap_zx} n_count: {NB_STREAMLINES} -hdr_size: {hdr_size}""".format( - **vars - ) +hdr_size: {hdr_size}""".format(**vars) diff --git a/nibabel/testing/__init__.py b/nibabel/testing/__init__.py index 21ecadf84..a3e98e064 100644 --- a/nibabel/testing/__init__.py +++ b/nibabel/testing/__init__.py @@ -7,6 +7,9 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Utilities for testing""" + +# ruff: noqa: F401 + from __future__ import annotations import os diff --git a/nibabel/tests/nibabel_data.py b/nibabel/tests/nibabel_data.py index 8d4652d79..1f89c9c1a 100644 --- a/nibabel/tests/nibabel_data.py +++ b/nibabel/tests/nibabel_data.py @@ -3,9 +3,8 @@ import unittest from os import environ, listdir -from os.path import dirname, exists, isdir +from os.path import dirname, exists, isdir, realpath from os.path import join as pjoin -from os.path import realpath def get_nibabel_data(): diff --git a/nibabel/tests/scriptrunner.py b/nibabel/tests/scriptrunner.py index 1ec2fcb48..1e8b1fdda 100644 --- a/nibabel/tests/scriptrunner.py +++ b/nibabel/tests/scriptrunner.py @@ -14,9 +14,8 @@ """ import os import sys -from os.path import dirname, isdir, isfile +from os.path import dirname, isdir, isfile, pathsep, realpath from os.path import join as pjoin -from os.path import pathsep, realpath from subprocess import PIPE, Popen MY_PACKAGE = __package__ diff --git a/nibabel/tests/test_affines.py b/nibabel/tests/test_affines.py index 28f405e56..1d7ef1e6b 100644 --- a/nibabel/tests/test_affines.py +++ b/nibabel/tests/test_affines.py @@ -225,7 +225,7 @@ def test_rescale_affine(): orig_shape = rng.randint(low=20, high=512, size=(3,)) orig_aff = np.eye(4) orig_aff[:3, :] = rng.normal(size=(3, 4)) - orig_zooms = voxel_sizes(orig_aff) + orig_zooms = voxel_sizes(orig_aff) # noqa: F841 orig_axcodes = aff2axcodes(orig_aff) orig_centroid = apply_affine(orig_aff, (orig_shape - 1) // 2) diff --git a/nibabel/tests/test_arraywriters.py b/nibabel/tests/test_arraywriters.py index 89e7ac675..2fc9c3235 100644 --- a/nibabel/tests/test_arraywriters.py +++ b/nibabel/tests/test_arraywriters.py @@ -276,7 +276,7 @@ def test_slope_inter_castable(): for out_dtt in NUMERIC_TYPES: for klass in (ArrayWriter, SlopeArrayWriter, SlopeInterArrayWriter): arr = np.zeros((5,), dtype=in_dtt) - aw = klass(arr, out_dtt) # no error + _ = klass(arr, out_dtt) # no error # Test special case of none finite # This raises error for ArrayWriter, but not for the others arr = np.array([np.inf, np.nan, -np.inf]) @@ -285,8 +285,8 @@ def test_slope_inter_castable(): in_arr = arr.astype(in_dtt) with pytest.raises(WriterError): ArrayWriter(in_arr, out_dtt) - aw = SlopeArrayWriter(arr.astype(in_dtt), out_dtt) # no error - aw = SlopeInterArrayWriter(arr.astype(in_dtt), out_dtt) # no error + _ = SlopeArrayWriter(arr.astype(in_dtt), out_dtt) # no error + _ = SlopeInterArrayWriter(arr.astype(in_dtt), out_dtt) # no error for in_dtt, out_dtt, arr, slope_only, slope_inter, neither in ( (np.float32, np.float32, 1, True, True, True), (np.float64, np.float32, 1, True, True, True), diff --git a/nibabel/tests/test_brikhead.py b/nibabel/tests/test_brikhead.py index 5bf6e79cb..31e0d0d47 100644 --- a/nibabel/tests/test_brikhead.py +++ b/nibabel/tests/test_brikhead.py @@ -13,7 +13,7 @@ import pytest from numpy.testing import assert_array_equal -from .. import Nifti1Image, brikhead, load +from .. import Nifti1Image, brikhead from ..testing import assert_data_similar, data_path from .test_fileslice import slicer_samples diff --git a/nibabel/tests/test_data.py b/nibabel/tests/test_data.py index abcb3caaf..3ccb4963c 100644 --- a/nibabel/tests/test_data.py +++ b/nibabel/tests/test_data.py @@ -22,7 +22,7 @@ get_data_path, make_datasource, ) -from .test_environment import DATA_KEY, USER_KEY, with_environment +from .test_environment import DATA_KEY, USER_KEY, with_environment # noqa: F401 @pytest.fixture diff --git a/nibabel/tests/test_ecat.py b/nibabel/tests/test_ecat.py index 6a076cbc3..702913e14 100644 --- a/nibabel/tests/test_ecat.py +++ b/nibabel/tests/test_ecat.py @@ -8,7 +8,6 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## import os -import warnings from pathlib import Path from unittest import TestCase diff --git a/nibabel/tests/test_ecat_data.py b/nibabel/tests/test_ecat_data.py index b7dbe4750..23485ae92 100644 --- a/nibabel/tests/test_ecat_data.py +++ b/nibabel/tests/test_ecat_data.py @@ -13,7 +13,7 @@ from os.path import join as pjoin import numpy as np -from numpy.testing import assert_almost_equal, assert_array_equal +from numpy.testing import assert_almost_equal from ..ecat import load from .nibabel_data import get_nibabel_data, needs_nibabel_data diff --git a/nibabel/tests/test_floating.py b/nibabel/tests/test_floating.py index 3e6e7f426..c2ccd4403 100644 --- a/nibabel/tests/test_floating.py +++ b/nibabel/tests/test_floating.py @@ -1,10 +1,8 @@ """Test floating point deconstructions and floor methods """ import sys -from contextlib import nullcontext import numpy as np -import pytest from packaging.version import Version from ..casting import ( @@ -13,7 +11,6 @@ _check_nmant, ceil_exact, floor_exact, - floor_log2, have_binary128, longdouble_precision_improved, ok_floats, diff --git a/nibabel/tests/test_funcs.py b/nibabel/tests/test_funcs.py index 10f6e9081..5e59bc63b 100644 --- a/nibabel/tests/test_funcs.py +++ b/nibabel/tests/test_funcs.py @@ -58,7 +58,6 @@ def test_concat(): # Loop over every possible axis, including None (explicit and implied) for axis in list(range(-(dim - 2), (dim - 1))) + [None, '__default__']: - # Allow testing default vs. passing explicit param if axis == '__default__': np_concat_kwargs = dict(axis=-1) diff --git a/nibabel/tests/test_image_load_save.py b/nibabel/tests/test_image_load_save.py index 706a87f10..4e787f0d7 100644 --- a/nibabel/tests/test_image_load_save.py +++ b/nibabel/tests/test_image_load_save.py @@ -24,7 +24,6 @@ MGHImage, Minc1Image, Minc2Image, - Nifti1Header, Nifti1Image, Nifti1Pair, Nifti2Image, @@ -131,7 +130,7 @@ def test_save_load(): affine[:3, 3] = [3, 2, 1] img = ni1.Nifti1Image(data, affine) img.set_data_dtype(npt) - with InTemporaryDirectory() as pth: + with InTemporaryDirectory() as _: nifn = 'an_image.nii' sifn = 'another_image.img' ni1.save(img, nifn) diff --git a/nibabel/tests/test_image_types.py b/nibabel/tests/test_image_types.py index da2f93e21..bc50c8417 100644 --- a/nibabel/tests/test_image_types.py +++ b/nibabel/tests/test_image_types.py @@ -88,7 +88,6 @@ def check_img(img_path, img_klass, sniff_mode, sniff, expect_success, msg): irrelevant=b'a' * (sizeof_hdr - 1), # A too-small sniff, query bad_sniff=b'a' * sizeof_hdr, # Bad sniff, should fail ).items(): - for klass in img_klasses: if klass == expected_img_klass: # Class will load unless you pass a bad sniff, diff --git a/nibabel/tests/test_imageclasses.py b/nibabel/tests/test_imageclasses.py index 74f05dc6e..90424b7d3 100644 --- a/nibabel/tests/test_imageclasses.py +++ b/nibabel/tests/test_imageclasses.py @@ -1,15 +1,13 @@ """Testing imageclasses module """ -import warnings from os.path import dirname from os.path import join as pjoin import numpy as np -import pytest import nibabel as nib -from nibabel import imageclasses +from nibabel import imageclasses # noqa: F401 from nibabel.analyze import AnalyzeImage from nibabel.imageclasses import spatial_axes_first from nibabel.nifti1 import Nifti1Image diff --git a/nibabel/tests/test_init.py b/nibabel/tests/test_init.py index 2317a6397..969b80b6f 100644 --- a/nibabel/tests/test_init.py +++ b/nibabel/tests/test_init.py @@ -1,4 +1,5 @@ import pathlib +import unittest from unittest import mock import pytest diff --git a/nibabel/tests/test_minc1.py b/nibabel/tests/test_minc1.py index be4f0deb0..8f88bf802 100644 --- a/nibabel/tests/test_minc1.py +++ b/nibabel/tests/test_minc1.py @@ -9,8 +9,6 @@ import bz2 import gzip -import types -import warnings from io import BytesIO from os.path import join as pjoin @@ -19,12 +17,10 @@ from numpy.testing import assert_array_equal from .. import Nifti1Image, load, minc1 -from ..deprecated import ModuleProxy -from ..deprecator import ExpiredDeprecationError from ..externals.netcdf import netcdf_file from ..minc1 import Minc1File, Minc1Image, MincHeader from ..optpkg import optional_package -from ..testing import assert_data_similar, clear_and_catch_warnings, data_path +from ..testing import assert_data_similar, data_path from ..tmpdirs import InTemporaryDirectory from . import test_spatialimages as tsi from .test_fileslice import slicer_samples diff --git a/nibabel/tests/test_minc2.py b/nibabel/tests/test_minc2.py index e76cb05ce..7ab29edfd 100644 --- a/nibabel/tests/test_minc2.py +++ b/nibabel/tests/test_minc2.py @@ -129,5 +129,5 @@ def test_bad_diminfo(): # File has a bad spacing field 'xspace' when it should be # `irregular`, `regular__` or absent (default to regular__). # We interpret an invalid spacing as absent, but warn. - with pytest.warns(UserWarning) as w: + with pytest.warns(UserWarning) as _: Minc2Image.from_filename(fname) diff --git a/nibabel/tests/test_nibabel_data.py b/nibabel/tests/test_nibabel_data.py index 168758954..0c7116e9a 100644 --- a/nibabel/tests/test_nibabel_data.py +++ b/nibabel/tests/test_nibabel_data.py @@ -2,9 +2,8 @@ """ import os -from os.path import dirname, isdir +from os.path import dirname, isdir, realpath from os.path import join as pjoin -from os.path import realpath from . import nibabel_data as nibd diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py index c7c4d1d84..a5b9427bc 100644 --- a/nibabel/tests/test_nifti1.py +++ b/nibabel/tests/test_nifti1.py @@ -731,7 +731,6 @@ def unshear_44(affine): class TestNifti1SingleHeader(TestNifti1PairHeader): - header_class = Nifti1Header def test_empty(self): diff --git a/nibabel/tests/test_nifti2.py b/nibabel/tests/test_nifti2.py index 742ef148b..a25e23b49 100644 --- a/nibabel/tests/test_nifti2.py +++ b/nibabel/tests/test_nifti2.py @@ -13,7 +13,7 @@ from numpy.testing import assert_array_equal from .. import nifti2 -from ..nifti1 import Nifti1Extension, Nifti1Extensions, Nifti1Header, Nifti1PairHeader +from ..nifti1 import Nifti1Extension, Nifti1Header, Nifti1PairHeader from ..nifti2 import Nifti2Header, Nifti2Image, Nifti2Pair, Nifti2PairHeader from ..testing import data_path from . import test_nifti1 as tn1 diff --git a/nibabel/tests/test_openers.py b/nibabel/tests/test_openers.py index a228e6613..5c6a1643c 100644 --- a/nibabel/tests/test_openers.py +++ b/nibabel/tests/test_openers.py @@ -19,7 +19,6 @@ import pytest from packaging.version import Version -from ..deprecator import ExpiredDeprecationError from ..openers import HAVE_INDEXED_GZIP, BZ2File, DeterministicGzipFile, ImageOpener, Opener from ..optpkg import optional_package from ..tmpdirs import InTemporaryDirectory diff --git a/nibabel/tests/test_orientations.py b/nibabel/tests/test_orientations.py index 0094711e7..7e4a33e29 100644 --- a/nibabel/tests/test_orientations.py +++ b/nibabel/tests/test_orientations.py @@ -8,7 +8,6 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Testing for orientations module""" -import warnings import numpy as np import pytest @@ -185,7 +184,6 @@ def test_apply(): apply_orientation(a[:, :, 1], ornt) with pytest.raises(OrientationError): apply_orientation(a, [[0, 1], [np.nan, np.nan], [2, 1]]) - shape = np.array(a.shape) for ornt in ALL_ORNTS: t_arr = apply_orientation(a, ornt) assert_array_equal(a.shape, np.array(t_arr.shape)[np.array(ornt)[:, 0]]) diff --git a/nibabel/tests/test_parrec.py b/nibabel/tests/test_parrec.py index 6035d47f8..980a2f403 100644 --- a/nibabel/tests/test_parrec.py +++ b/nibabel/tests/test_parrec.py @@ -285,8 +285,8 @@ def test_affine_regression(): # Test against checked affines from previous runs # Checked against Michael's data using some GUI tools # Data at http://psydata.ovgu.de/philips_achieva_testfiles/conversion2 - for basename, exp_affine in PREVIOUS_AFFINES.items(): - fname = pjoin(DATA_PATH, basename + '.PAR') + for basename_affine, exp_affine in PREVIOUS_AFFINES.items(): + fname = pjoin(DATA_PATH, basename_affine + '.PAR') with open(fname) as fobj: hdr = PARRECHeader.from_fileobj(fobj) assert_almost_equal(hdr.get_affine(), exp_affine) @@ -884,7 +884,6 @@ def test_dualTR(): def test_ADC_map(): # test reading an apparent diffusion coefficient map with open(ADC_PAR) as fobj: - # two truncation warnings expected because general_info indicates: # 1.) multiple directions # 2.) multiple b-values diff --git a/nibabel/tests/test_parrec_data.py b/nibabel/tests/test_parrec_data.py index a437fafed..2a52d9725 100644 --- a/nibabel/tests/test_parrec_data.py +++ b/nibabel/tests/test_parrec_data.py @@ -3,12 +3,10 @@ import unittest from glob import glob -from os.path import basename, exists +from os.path import basename, exists, splitext from os.path import join as pjoin -from os.path import splitext import numpy as np -import pytest from numpy.testing import assert_almost_equal from .. import load as top_load diff --git a/nibabel/tests/test_pkg_info.py b/nibabel/tests/test_pkg_info.py index dfe18c975..1422bb335 100644 --- a/nibabel/tests/test_pkg_info.py +++ b/nibabel/tests/test_pkg_info.py @@ -15,7 +15,7 @@ def test_pkg_info(): - nibabel.pkg_info.get_pkg_info - nibabel.pkg_info.pkg_commit_hash """ - info = nib.get_info() + _ = nib.get_info() def test_version(): diff --git a/nibabel/tests/test_pointset.py b/nibabel/tests/test_pointset.py index fb9a7c5c8..f4f0e4361 100644 --- a/nibabel/tests/test_pointset.py +++ b/nibabel/tests/test_pointset.py @@ -1,15 +1,12 @@ from math import prod from pathlib import Path -from unittest import skipUnless import numpy as np import pytest from nibabel import pointset as ps from nibabel.affines import apply_affine -from nibabel.arrayproxy import ArrayProxy from nibabel.fileslice import strided_scalar -from nibabel.onetime import auto_attr from nibabel.optpkg import optional_package from nibabel.spatialimages import SpatialImage from nibabel.tests.nibabel_data import get_nibabel_data diff --git a/nibabel/tests/test_quaternions.py b/nibabel/tests/test_quaternions.py index fff7c5e04..ec882dd0b 100644 --- a/nibabel/tests/test_quaternions.py +++ b/nibabel/tests/test_quaternions.py @@ -112,7 +112,6 @@ def test_fillpositive_simulated_error(dtype): # Permit 1 epsilon per value (default, but make explicit here) w2_thresh = 3 * np.finfo(dtype).eps - pos_error = neg_error = False for _ in range(50): xyz = norm(gen_vec(dtype)) @@ -186,12 +185,6 @@ def test_inverse(M, q): assert np.allclose(iM, iqM) -def test_eye(): - qi = nq.eye() - assert np.all([1, 0, 0, 0] == qi) - assert np.allclose(nq.quat2mat(qi), np.eye(3)) - - @pytest.mark.parametrize('vec', np.eye(3)) @pytest.mark.parametrize('M, q', eg_pairs) def test_qrotate(vec, M, q): diff --git a/nibabel/tests/test_removalschedule.py b/nibabel/tests/test_removalschedule.py index 772d395fd..7a56f3fb8 100644 --- a/nibabel/tests/test_removalschedule.py +++ b/nibabel/tests/test_removalschedule.py @@ -1,4 +1,3 @@ -import unittest from unittest import mock import pytest diff --git a/nibabel/tests/test_scripts.py b/nibabel/tests/test_scripts.py index cc4bb468a..455a994ae 100644 --- a/nibabel/tests/test_scripts.py +++ b/nibabel/tests/test_scripts.py @@ -11,9 +11,8 @@ import sys import unittest from glob import glob -from os.path import abspath, basename, dirname, exists +from os.path import abspath, basename, dirname, exists, splitext from os.path import join as pjoin -from os.path import splitext import numpy as np import pytest @@ -197,7 +196,7 @@ def test_help(): # needs special treatment since depends on fuse module which # might not be available. try: - import fuse + import fuse # noqa: F401 except Exception: continue # do not test this one code, stdout, stderr = run_command([cmd, '--help']) diff --git a/nibabel/tests/test_spatialimages.py b/nibabel/tests/test_spatialimages.py index 7157d5c45..a5cab9e75 100644 --- a/nibabel/tests/test_spatialimages.py +++ b/nibabel/tests/test_spatialimages.py @@ -399,8 +399,7 @@ def test_slicer(self): img_klass = self.image_class in_data_template = np.arange(240, dtype=np.int16) base_affine = np.eye(4) - t_axis = None - for dshape in ((4, 5, 6, 2), (8, 5, 6)): # Time series # Volume + for dshape in ((4, 5, 6, 2), (8, 5, 6)): # Time series # Volume in_data = in_data_template.copy().reshape(dshape) img = img_klass(in_data, base_affine.copy()) diff --git a/nibabel/tests/test_testing.py b/nibabel/tests/test_testing.py index dee3ea355..1ca1fb9b9 100644 --- a/nibabel/tests/test_testing.py +++ b/nibabel/tests/test_testing.py @@ -114,7 +114,7 @@ def test_warn_error(): with error_warnings(): with pytest.raises(UserWarning): warnings.warn('A test') - with error_warnings() as w: # w not used for anything + with error_warnings() as _: with pytest.raises(UserWarning): warnings.warn('A test') assert n_warns == len(warnings.filters) @@ -134,7 +134,7 @@ def test_warn_ignore(): with suppress_warnings(): warnings.warn('Here is a warning, you will not see it') warnings.warn('Nor this one', DeprecationWarning) - with suppress_warnings() as w: # w not used + with suppress_warnings() as _: warnings.warn('Here is a warning, you will not see it') warnings.warn('Nor this one', DeprecationWarning) assert n_warns == len(warnings.filters) diff --git a/nibabel/tests/test_wrapstruct.py b/nibabel/tests/test_wrapstruct.py index 10b4b3f22..e18fb0210 100644 --- a/nibabel/tests/test_wrapstruct.py +++ b/nibabel/tests/test_wrapstruct.py @@ -435,15 +435,6 @@ def test_copy(self): self._set_something_into_hdr(hdr2) assert hdr == hdr2 - def test_copy(self): - hdr = self.header_class() - hdr2 = hdr.copy() - assert hdr == hdr2 - self._set_something_into_hdr(hdr) - assert hdr != hdr2 - self._set_something_into_hdr(hdr2) - assert hdr == hdr2 - def test_checks(self): # Test header checks hdr_t = self.header_class() diff --git a/tools/make_tarball.py b/tools/make_tarball.py index 3cdad40d0..b49a1f276 100755 --- a/tools/make_tarball.py +++ b/tools/make_tarball.py @@ -5,7 +5,7 @@ import os import commands -from toollib import * +from toollib import c, cd tag = commands.getoutput('git describe') base_name = f'nibabel-{tag}' diff --git a/tools/markdown_release_notes.py b/tools/markdown_release_notes.py index 66e787603..73bdbf775 100644 --- a/tools/markdown_release_notes.py +++ b/tools/markdown_release_notes.py @@ -27,7 +27,7 @@ def main(): if in_release_notes: break in_release_notes = match.group(1) == version - next(f) # Skip the underline + next(f) # Skip the underline continue if in_release_notes: diff --git a/tools/mpkg_wrapper.py b/tools/mpkg_wrapper.py index 0a96156e4..f5f059b28 100644 --- a/tools/mpkg_wrapper.py +++ b/tools/mpkg_wrapper.py @@ -24,7 +24,7 @@ def main(): g = dict(globals()) g['__file__'] = sys.argv[0] g['__name__'] = '__main__' - execfile(sys.argv[0], g, g) + exec(open(sys.argv[0]).read(), g, g) if __name__ == '__main__': From 04dd1f4fd1a7491c91d1c3c1dfadeac8ade5aeaa Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:24:14 +0100 Subject: [PATCH 03/32] =?UTF-8?q?MNT:=20ruff=200.1.9=20=E2=86=92=200.3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef2d891fb..d35d28757 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: check-merge-conflict - id: check-vcs-permalinks - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.9 + rev: v0.3.0 hooks: - id: ruff args: [--fix, --show-fix, --exit-non-zero-on-fix] diff --git a/tox.ini b/tox.ini index 4e9b220ce..53860445a 100644 --- a/tox.ini +++ b/tox.ini @@ -139,7 +139,7 @@ commands = description = Check our style guide labels = check deps = - ruff>=0.1.9 + ruff>=0.3.0 skip_install = true commands = ruff --diff nibabel From 3ee9480d356198167c9c45854ecc489a7c186416 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:51:02 +0100 Subject: [PATCH 04/32] MNT: run `ruff check --fix` and `ruff format` Also fix remaining issues manually. --- nibabel/_compression.py | 1 + nibabel/affines.py | 1 + nibabel/analyze.py | 1 + nibabel/arrayproxy.py | 15 +++++++-------- nibabel/arraywriters.py | 1 + nibabel/benchmarks/butils.py | 3 +-- nibabel/brikhead.py | 1 + nibabel/casting.py | 1 + nibabel/cifti2/cifti2.py | 1 + nibabel/cifti2/cifti2_axes.py | 1 + nibabel/cifti2/tests/test_cifti2.py | 4 ++-- nibabel/cifti2/tests/test_new_cifti2.py | 1 + nibabel/cmdline/__init__.py | 3 +-- nibabel/cmdline/diff.py | 6 +++--- nibabel/cmdline/parrec2nii.py | 3 +-- nibabel/cmdline/tck2trk.py | 1 + nibabel/cmdline/tests/test_parrec2nii.py | 4 ++-- nibabel/cmdline/utils.py | 1 - nibabel/data.py | 1 + nibabel/dataobj_images.py | 1 + nibabel/deprecated.py | 1 + nibabel/deprecator.py | 1 + nibabel/dft.py | 2 -- nibabel/ecat.py | 1 + nibabel/environment.py | 1 + nibabel/eulerangles.py | 1 + nibabel/filebasedimages.py | 1 + nibabel/fileholders.py | 1 + nibabel/filename_parser.py | 1 + nibabel/fileslice.py | 1 + nibabel/freesurfer/__init__.py | 3 +-- nibabel/freesurfer/io.py | 3 +-- nibabel/freesurfer/mghformat.py | 1 + nibabel/funcs.py | 1 + nibabel/gifti/gifti.py | 1 + nibabel/gifti/tests/test_gifti.py | 4 ++-- nibabel/imageclasses.py | 1 + nibabel/imageglobals.py | 1 + nibabel/imagestats.py | 1 + nibabel/loadsave.py | 1 + nibabel/minc1.py | 1 + nibabel/minc2.py | 1 + nibabel/nicom/__init__.py | 1 + nibabel/nicom/ascconv.py | 1 + nibabel/nicom/csareader.py | 4 ++-- nibabel/nicom/dwiparams.py | 1 + nibabel/nicom/tests/test_ascconv.py | 3 +-- nibabel/nicom/tests/test_csareader.py | 4 ++-- nibabel/nicom/tests/test_dicomreaders.py | 3 +-- nibabel/nicom/tests/test_dicomwrappers.py | 3 +-- nibabel/nicom/tests/test_dwiparams.py | 3 +-- nibabel/nicom/tests/test_structreader.py | 4 ++-- nibabel/nicom/tests/test_utils.py | 4 ++-- nibabel/nicom/utils.py | 3 +-- nibabel/nifti1.py | 1 + nibabel/nifti2.py | 1 + nibabel/onetime.py | 9 +++++---- nibabel/openers.py | 7 +++---- nibabel/optpkg.py | 1 + nibabel/orientations.py | 1 + nibabel/parrec.py | 1 + nibabel/pointset.py | 9 +++++---- nibabel/processing.py | 1 + nibabel/pydicom_compat.py | 1 + nibabel/quaternions.py | 1 + nibabel/rstutils.py | 1 + nibabel/spaces.py | 1 + nibabel/spatialimages.py | 16 ++++++---------- nibabel/spm2analyze.py | 1 + nibabel/spm99analyze.py | 1 + nibabel/streamlines/__init__.py | 3 +-- nibabel/streamlines/header.py | 3 +-- .../streamlines/tests/test_tractogram_file.py | 3 +-- nibabel/streamlines/tractogram_file.py | 4 ++-- nibabel/testing/helpers.py | 4 ++-- nibabel/testing/np_features.py | 4 ++-- nibabel/tests/data/check_parrec_reslice.py | 1 + nibabel/tests/data/gen_standard.py | 1 + nibabel/tests/nibabel_data.py | 3 +-- nibabel/tests/scriptrunner.py | 1 + nibabel/tests/test_api_validators.py | 4 ++-- nibabel/tests/test_arrayproxy.py | 3 +-- nibabel/tests/test_batteryrunners.py | 3 +-- nibabel/tests/test_casting.py | 4 ++-- nibabel/tests/test_data.py | 3 ++- nibabel/tests/test_dataobj_images.py | 3 +-- nibabel/tests/test_deprecated.py | 3 +-- nibabel/tests/test_deprecator.py | 3 +-- nibabel/tests/test_dft.py | 3 +-- nibabel/tests/test_diff.py | 3 +-- nibabel/tests/test_ecat_data.py | 3 +-- nibabel/tests/test_environment.py | 3 +-- nibabel/tests/test_filebasedimages.py | 3 +-- nibabel/tests/test_fileholders.py | 3 +-- nibabel/tests/test_filename_parser.py | 1 + nibabel/tests/test_files_interface.py | 3 +-- nibabel/tests/test_fileslice.py | 1 - nibabel/tests/test_fileutils.py | 4 +--- nibabel/tests/test_floating.py | 4 ++-- nibabel/tests/test_image_api.py | 1 - nibabel/tests/test_image_load_save.py | 1 + nibabel/tests/test_imageclasses.py | 3 +-- nibabel/tests/test_imageglobals.py | 4 ++-- nibabel/tests/test_loadsave.py | 3 +-- nibabel/tests/test_minc2_data.py | 3 +-- nibabel/tests/test_mriutils.py | 4 +--- nibabel/tests/test_nibabel_data.py | 3 +-- nibabel/tests/test_nifti1.py | 1 + nibabel/tests/test_nifti2.py | 1 + nibabel/tests/test_onetime.py | 2 -- nibabel/tests/test_openers.py | 1 + nibabel/tests/test_optpkg.py | 3 +-- nibabel/tests/test_orientations.py | 1 - nibabel/tests/test_parrec.py | 3 +-- nibabel/tests/test_parrec_data.py | 3 +-- nibabel/tests/test_pkg_info.py | 3 +-- nibabel/tests/test_processing.py | 3 +-- nibabel/tests/test_rstutils.py | 3 +-- nibabel/tests/test_spaces.py | 3 +-- nibabel/tests/test_spatialimages.py | 3 +-- nibabel/tests/test_testing.py | 3 +-- nibabel/tests/test_tripwire.py | 3 +-- nibabel/tests/test_wrapstruct.py | 1 + nibabel/tmpdirs.py | 1 + nibabel/tripwire.py | 1 + nibabel/viewers.py | 1 + nibabel/volumeutils.py | 9 +++++---- nibabel/wrapstruct.py | 1 + nibabel/xmlutils.py | 1 + tox.ini | 2 +- 130 files changed, 166 insertions(+), 161 deletions(-) diff --git a/nibabel/_compression.py b/nibabel/_compression.py index b7cfc8f49..eeb66f36b 100644 --- a/nibabel/_compression.py +++ b/nibabel/_compression.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Constants and types for dealing transparently with compression""" + from __future__ import annotations import bz2 diff --git a/nibabel/affines.py b/nibabel/affines.py index 1478fd2dc..4b6001dec 100644 --- a/nibabel/affines.py +++ b/nibabel/affines.py @@ -1,6 +1,7 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: """Utility routines for working with points and affine transforms""" + from functools import reduce import numpy as np diff --git a/nibabel/analyze.py b/nibabel/analyze.py index 20fdac055..189f2e0a1 100644 --- a/nibabel/analyze.py +++ b/nibabel/analyze.py @@ -81,6 +81,7 @@ can be loaded with and without a default flip, so the saved zoom will not constrain the affine. """ + from __future__ import annotations import numpy as np diff --git a/nibabel/arrayproxy.py b/nibabel/arrayproxy.py index 57d8aa0f8..4bf5bd470 100644 --- a/nibabel/arrayproxy.py +++ b/nibabel/arrayproxy.py @@ -25,6 +25,7 @@ See :mod:`nibabel.tests.test_proxy_api` for proxy API conformance checks. """ + from __future__ import annotations import typing as ty @@ -74,21 +75,19 @@ class ArrayLike(ty.Protocol): shape: tuple[int, ...] @property - def ndim(self) -> int: - ... # pragma: no cover + def ndim(self) -> int: ... # pragma: no cover # If no dtype is passed, any dtype might be returned, depending on the array-like @ty.overload - def __array__(self, dtype: None = ..., /) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: - ... # pragma: no cover + def __array__( + self, dtype: None = ..., / + ) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: ... # pragma: no cover # Any dtype might be passed, and *that* dtype must be returned @ty.overload - def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: - ... # pragma: no cover + def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: ... # pragma: no cover - def __getitem__(self, key, /) -> npt.NDArray: - ... # pragma: no cover + def __getitem__(self, key, /) -> npt.NDArray: ... # pragma: no cover class ArrayProxy(ArrayLike): diff --git a/nibabel/arraywriters.py b/nibabel/arraywriters.py index 751eb6ad1..1f55263fc 100644 --- a/nibabel/arraywriters.py +++ b/nibabel/arraywriters.py @@ -28,6 +28,7 @@ def __init__(self, array, out_dtype=None) something else to make sense of conversions between float and int, or between larger ints and smaller. """ + import numpy as np from .casting import best_float, floor_exact, int_abs, shared_range, type_info diff --git a/nibabel/benchmarks/butils.py b/nibabel/benchmarks/butils.py index 01d6931eb..13c255d1c 100644 --- a/nibabel/benchmarks/butils.py +++ b/nibabel/benchmarks/butils.py @@ -1,5 +1,4 @@ -"""Benchmarking utilities -""" +"""Benchmarking utilities""" from .. import get_info diff --git a/nibabel/brikhead.py b/nibabel/brikhead.py index 6694ff08a..3a3cfd087 100644 --- a/nibabel/brikhead.py +++ b/nibabel/brikhead.py @@ -26,6 +26,7 @@ am aware) always be >= 1. This permits sub-brick indexing common in AFNI programs (e.g., example4d+orig'[0]'). """ + import os import re from copy import deepcopy diff --git a/nibabel/casting.py b/nibabel/casting.py index 77da57e40..31e27d0e8 100644 --- a/nibabel/casting.py +++ b/nibabel/casting.py @@ -3,6 +3,7 @@ Most routines work round some numpy oddities in floating point precision and casting. Others work round numpy casting to and from python ints """ + from __future__ import annotations import warnings diff --git a/nibabel/cifti2/cifti2.py b/nibabel/cifti2/cifti2.py index 452bceb7e..cb2e0cfaf 100644 --- a/nibabel/cifti2/cifti2.py +++ b/nibabel/cifti2/cifti2.py @@ -16,6 +16,7 @@ http://www.nitrc.org/projects/cifti """ + import re from collections import OrderedDict from collections.abc import Iterable, MutableMapping, MutableSequence diff --git a/nibabel/cifti2/cifti2_axes.py b/nibabel/cifti2/cifti2_axes.py index 6443a34fb..af7c63bea 100644 --- a/nibabel/cifti2/cifti2_axes.py +++ b/nibabel/cifti2/cifti2_axes.py @@ -118,6 +118,7 @@ ... bm_cortex))) """ + import abc from operator import xor diff --git a/nibabel/cifti2/tests/test_cifti2.py b/nibabel/cifti2/tests/test_cifti2.py index d7fd0a0ed..895b8f959 100644 --- a/nibabel/cifti2/tests/test_cifti2.py +++ b/nibabel/cifti2/tests/test_cifti2.py @@ -1,5 +1,5 @@ -"""Testing CIFTI-2 objects -""" +"""Testing CIFTI-2 objects""" + import collections from xml.etree import ElementTree diff --git a/nibabel/cifti2/tests/test_new_cifti2.py b/nibabel/cifti2/tests/test_new_cifti2.py index 0f90b822d..4cf5502ad 100644 --- a/nibabel/cifti2/tests/test_new_cifti2.py +++ b/nibabel/cifti2/tests/test_new_cifti2.py @@ -6,6 +6,7 @@ These functions are used in the tests to generate most CIFTI file types from scratch. """ + import numpy as np import pytest diff --git a/nibabel/cmdline/__init__.py b/nibabel/cmdline/__init__.py index 6478e5f26..f0744521b 100644 --- a/nibabel/cmdline/__init__.py +++ b/nibabel/cmdline/__init__.py @@ -6,5 +6,4 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Functionality to be exposed in the command line -""" +"""Functionality to be exposed in the command line""" diff --git a/nibabel/cmdline/diff.py b/nibabel/cmdline/diff.py index d20a105e7..1231a778f 100755 --- a/nibabel/cmdline/diff.py +++ b/nibabel/cmdline/diff.py @@ -246,9 +246,9 @@ def get_data_diff(files, max_abs=0, max_rel=0, dtype=np.float64): sub_thr = rel_diff <= max_rel # Since we operated on sub-selected values already, we need # to plug them back in - candidates[ - tuple(indexes[sub_thr] for indexes in np.where(candidates)) - ] = False + candidates[tuple(indexes[sub_thr] for indexes in np.where(candidates))] = ( + False + ) max_rel_diff = np.max(rel_diff) else: max_rel_diff = 0 diff --git a/nibabel/cmdline/parrec2nii.py b/nibabel/cmdline/parrec2nii.py index 934062639..0ae6b3fb4 100644 --- a/nibabel/cmdline/parrec2nii.py +++ b/nibabel/cmdline/parrec2nii.py @@ -1,5 +1,4 @@ -"""Code for PAR/REC to NIfTI converter command -""" +"""Code for PAR/REC to NIfTI converter command""" import csv import os diff --git a/nibabel/cmdline/tck2trk.py b/nibabel/cmdline/tck2trk.py index d5d29ba43..a73540c44 100644 --- a/nibabel/cmdline/tck2trk.py +++ b/nibabel/cmdline/tck2trk.py @@ -1,6 +1,7 @@ """ Convert tractograms (TCK -> TRK). """ + import argparse import os diff --git a/nibabel/cmdline/tests/test_parrec2nii.py b/nibabel/cmdline/tests/test_parrec2nii.py index 017df9813..ccedafb74 100644 --- a/nibabel/cmdline/tests/test_parrec2nii.py +++ b/nibabel/cmdline/tests/test_parrec2nii.py @@ -1,5 +1,5 @@ -"""Tests for the parrec2nii exe code -""" +"""Tests for the parrec2nii exe code""" + from os.path import basename, isfile, join from unittest.mock import MagicMock, Mock, patch diff --git a/nibabel/cmdline/utils.py b/nibabel/cmdline/utils.py index 214923570..d89cc5c96 100644 --- a/nibabel/cmdline/utils.py +++ b/nibabel/cmdline/utils.py @@ -10,7 +10,6 @@ Helper utilities to be used in cmdline applications """ - # global verbosity switch import re from io import StringIO diff --git a/nibabel/data.py b/nibabel/data.py index 7e2fe2af7..c49580d09 100644 --- a/nibabel/data.py +++ b/nibabel/data.py @@ -1,6 +1,7 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: """Utilities to find files from NIPY data packages""" + import configparser import glob import os diff --git a/nibabel/dataobj_images.py b/nibabel/dataobj_images.py index eaf341271..a2ee691a1 100644 --- a/nibabel/dataobj_images.py +++ b/nibabel/dataobj_images.py @@ -7,6 +7,7 @@ * returns an array from ``numpy.asanyarray(obj)``; * has an attribute or property ``shape``. """ + from __future__ import annotations import typing as ty diff --git a/nibabel/deprecated.py b/nibabel/deprecated.py index 092370106..b8c378cee 100644 --- a/nibabel/deprecated.py +++ b/nibabel/deprecated.py @@ -1,4 +1,5 @@ """Module to help with deprecating objects and classes""" + from __future__ import annotations import typing as ty diff --git a/nibabel/deprecator.py b/nibabel/deprecator.py index 779fdb462..b9912534d 100644 --- a/nibabel/deprecator.py +++ b/nibabel/deprecator.py @@ -1,4 +1,5 @@ """Class for recording and reporting deprecations""" + from __future__ import annotations import functools diff --git a/nibabel/dft.py b/nibabel/dft.py index aeb8accbb..d9e335999 100644 --- a/nibabel/dft.py +++ b/nibabel/dft.py @@ -9,7 +9,6 @@ # Copyright (C) 2011 Christian Haselgrove """DICOM filesystem tools""" - import contextlib import getpass import logging @@ -44,7 +43,6 @@ class VolumeError(DFTError): class InstanceStackError(DFTError): - """bad series of instance numbers""" def __init__(self, series, i, si): diff --git a/nibabel/ecat.py b/nibabel/ecat.py index 85de9184b..03a4c72b9 100644 --- a/nibabel/ecat.py +++ b/nibabel/ecat.py @@ -42,6 +42,7 @@ GPL and some of the header files are adapted from CTI files (called CTI code below). It's not clear what the licenses are for these files. """ + import warnings from numbers import Integral diff --git a/nibabel/environment.py b/nibabel/environment.py index 09aaa6320..a828ccb86 100644 --- a/nibabel/environment.py +++ b/nibabel/environment.py @@ -1,6 +1,7 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: """Settings from the system environment relevant to NIPY""" + import os from os.path import join as pjoin diff --git a/nibabel/eulerangles.py b/nibabel/eulerangles.py index 13dc05964..b1d187e8c 100644 --- a/nibabel/eulerangles.py +++ b/nibabel/eulerangles.py @@ -82,6 +82,7 @@ ``y``, followed by rotation around ``x``, is known (confusingly) as "xyz", pitch-roll-yaw, Cardan angles, or Tait-Bryan angles. """ + import math from functools import reduce diff --git a/nibabel/filebasedimages.py b/nibabel/filebasedimages.py index 42760cccd..4e0d06b64 100644 --- a/nibabel/filebasedimages.py +++ b/nibabel/filebasedimages.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Common interface for any image format--volume or surface, binary or xml""" + from __future__ import annotations import io diff --git a/nibabel/fileholders.py b/nibabel/fileholders.py index a27715350..3db4c62a9 100644 --- a/nibabel/fileholders.py +++ b/nibabel/fileholders.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Fileholder class""" + from __future__ import annotations import io diff --git a/nibabel/filename_parser.py b/nibabel/filename_parser.py index 92a2f4b1f..bdbca6a38 100644 --- a/nibabel/filename_parser.py +++ b/nibabel/filename_parser.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Create filename pairs, triplets etc, with expected extensions""" + from __future__ import annotations import os diff --git a/nibabel/fileslice.py b/nibabel/fileslice.py index fe7d6bba5..816f1cdaf 100644 --- a/nibabel/fileslice.py +++ b/nibabel/fileslice.py @@ -1,4 +1,5 @@ """Utilities for getting array slices out of file-like objects""" + import operator from functools import reduce from mmap import mmap diff --git a/nibabel/freesurfer/__init__.py b/nibabel/freesurfer/__init__.py index 48922285c..aa76eb2e8 100644 --- a/nibabel/freesurfer/__init__.py +++ b/nibabel/freesurfer/__init__.py @@ -1,5 +1,4 @@ -"""Reading functions for freesurfer files -""" +"""Reading functions for freesurfer files""" # ruff: noqa: F401 diff --git a/nibabel/freesurfer/io.py b/nibabel/freesurfer/io.py index b4d6ef2a3..74bc05fc3 100644 --- a/nibabel/freesurfer/io.py +++ b/nibabel/freesurfer/io.py @@ -1,5 +1,4 @@ -"""Read / write FreeSurfer geometry, morphometry, label, annotation formats -""" +"""Read / write FreeSurfer geometry, morphometry, label, annotation formats""" import getpass import time diff --git a/nibabel/freesurfer/mghformat.py b/nibabel/freesurfer/mghformat.py index 5dd266034..93abf7b40 100644 --- a/nibabel/freesurfer/mghformat.py +++ b/nibabel/freesurfer/mghformat.py @@ -10,6 +10,7 @@ Author: Krish Subramaniam """ + from os.path import splitext import numpy as np diff --git a/nibabel/funcs.py b/nibabel/funcs.py index f83ed6870..cda4a5d2e 100644 --- a/nibabel/funcs.py +++ b/nibabel/funcs.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Processor functions for images""" + import numpy as np from .loadsave import load diff --git a/nibabel/gifti/gifti.py b/nibabel/gifti/gifti.py index 7aba87730..7c5c3c4fb 100644 --- a/nibabel/gifti/gifti.py +++ b/nibabel/gifti/gifti.py @@ -11,6 +11,7 @@ The Gifti specification was (at time of writing) available as a PDF download from http://www.nitrc.org/projects/gifti/ """ + from __future__ import annotations import base64 diff --git a/nibabel/gifti/tests/test_gifti.py b/nibabel/gifti/tests/test_gifti.py index 7e4c22397..f27546afe 100644 --- a/nibabel/gifti/tests/test_gifti.py +++ b/nibabel/gifti/tests/test_gifti.py @@ -1,5 +1,5 @@ -"""Testing gifti objects -""" +"""Testing gifti objects""" + import itertools import sys from io import BytesIO diff --git a/nibabel/imageclasses.py b/nibabel/imageclasses.py index b36131ed9..20cf1cac9 100644 --- a/nibabel/imageclasses.py +++ b/nibabel/imageclasses.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Define supported image classes and names""" + from __future__ import annotations from .analyze import AnalyzeImage diff --git a/nibabel/imageglobals.py b/nibabel/imageglobals.py index 551719a7e..81a174280 100644 --- a/nibabel/imageglobals.py +++ b/nibabel/imageglobals.py @@ -23,6 +23,7 @@ Use ``logger.level = 1`` to see all messages. """ + import logging error_level = 40 diff --git a/nibabel/imagestats.py b/nibabel/imagestats.py index 38dc9d3f1..36fbddee0 100644 --- a/nibabel/imagestats.py +++ b/nibabel/imagestats.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Functions for computing image statistics""" + import numpy as np from nibabel.imageclasses import spatial_axes_first diff --git a/nibabel/loadsave.py b/nibabel/loadsave.py index 463a68797..159d9bae8 100644 --- a/nibabel/loadsave.py +++ b/nibabel/loadsave.py @@ -8,6 +8,7 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## # module imports """Utilities to load and save image objects""" + from __future__ import annotations import os diff --git a/nibabel/minc1.py b/nibabel/minc1.py index 5f8422bc2..d0b9fd537 100644 --- a/nibabel/minc1.py +++ b/nibabel/minc1.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Read MINC1 format images""" + from __future__ import annotations from numbers import Integral diff --git a/nibabel/minc2.py b/nibabel/minc2.py index 912b5d28a..161be5c11 100644 --- a/nibabel/minc2.py +++ b/nibabel/minc2.py @@ -25,6 +25,7 @@ mincstats my_funny.mnc """ + import warnings import numpy as np diff --git a/nibabel/nicom/__init__.py b/nibabel/nicom/__init__.py index 3a389db17..d15e0846f 100644 --- a/nibabel/nicom/__init__.py +++ b/nibabel/nicom/__init__.py @@ -19,6 +19,7 @@ dwiparams structreader """ + import warnings warnings.warn( diff --git a/nibabel/nicom/ascconv.py b/nibabel/nicom/ascconv.py index be6da9786..0966de2a9 100644 --- a/nibabel/nicom/ascconv.py +++ b/nibabel/nicom/ascconv.py @@ -3,6 +3,7 @@ """ Parse the "ASCCONV" meta data format found in a variety of Siemens MR files. """ + import ast import re from collections import OrderedDict diff --git a/nibabel/nicom/csareader.py b/nibabel/nicom/csareader.py index 40f3f852d..df379e0be 100644 --- a/nibabel/nicom/csareader.py +++ b/nibabel/nicom/csareader.py @@ -1,5 +1,5 @@ -"""CSA header reader from SPM spec -""" +"""CSA header reader from SPM spec""" + import numpy as np from .structreader import Unpacker diff --git a/nibabel/nicom/dwiparams.py b/nibabel/nicom/dwiparams.py index cb0e50120..5930e96f9 100644 --- a/nibabel/nicom/dwiparams.py +++ b/nibabel/nicom/dwiparams.py @@ -18,6 +18,7 @@ B ~ (q_est . q_est.T) / norm(q_est) """ + import numpy as np import numpy.linalg as npl diff --git a/nibabel/nicom/tests/test_ascconv.py b/nibabel/nicom/tests/test_ascconv.py index cf40298c5..afe5f05e1 100644 --- a/nibabel/nicom/tests/test_ascconv.py +++ b/nibabel/nicom/tests/test_ascconv.py @@ -1,5 +1,4 @@ -"""Testing Siemens "ASCCONV" parser -""" +"""Testing Siemens "ASCCONV" parser""" from collections import OrderedDict from os.path import dirname diff --git a/nibabel/nicom/tests/test_csareader.py b/nibabel/nicom/tests/test_csareader.py index ddb46a942..f31f4a393 100644 --- a/nibabel/nicom/tests/test_csareader.py +++ b/nibabel/nicom/tests/test_csareader.py @@ -1,5 +1,5 @@ -"""Testing Siemens CSA header reader -""" +"""Testing Siemens CSA header reader""" + import gzip from copy import deepcopy from os.path import join as pjoin diff --git a/nibabel/nicom/tests/test_dicomreaders.py b/nibabel/nicom/tests/test_dicomreaders.py index 17ea7430f..d508343be 100644 --- a/nibabel/nicom/tests/test_dicomreaders.py +++ b/nibabel/nicom/tests/test_dicomreaders.py @@ -1,5 +1,4 @@ -"""Testing reading DICOM files -""" +"""Testing reading DICOM files""" from os.path import join as pjoin diff --git a/nibabel/nicom/tests/test_dicomwrappers.py b/nibabel/nicom/tests/test_dicomwrappers.py index fa2dfc07c..e96607df9 100755 --- a/nibabel/nicom/tests/test_dicomwrappers.py +++ b/nibabel/nicom/tests/test_dicomwrappers.py @@ -1,5 +1,4 @@ -"""Testing DICOM wrappers -""" +"""Testing DICOM wrappers""" import gzip from copy import copy diff --git a/nibabel/nicom/tests/test_dwiparams.py b/nibabel/nicom/tests/test_dwiparams.py index 6e98b4af6..559c0a214 100644 --- a/nibabel/nicom/tests/test_dwiparams.py +++ b/nibabel/nicom/tests/test_dwiparams.py @@ -1,5 +1,4 @@ -"""Testing diffusion parameter processing -""" +"""Testing diffusion parameter processing""" import numpy as np import pytest diff --git a/nibabel/nicom/tests/test_structreader.py b/nibabel/nicom/tests/test_structreader.py index 2d37bbc3e..ccd2dd4f8 100644 --- a/nibabel/nicom/tests/test_structreader.py +++ b/nibabel/nicom/tests/test_structreader.py @@ -1,5 +1,5 @@ -"""Testing Siemens CSA header reader -""" +"""Testing Siemens CSA header reader""" + import struct import sys diff --git a/nibabel/nicom/tests/test_utils.py b/nibabel/nicom/tests/test_utils.py index ea3b999fa..4f0d7e68d 100644 --- a/nibabel/nicom/tests/test_utils.py +++ b/nibabel/nicom/tests/test_utils.py @@ -1,5 +1,5 @@ -"""Testing nicom.utils module -""" +"""Testing nicom.utils module""" + import re from nibabel.optpkg import optional_package diff --git a/nibabel/nicom/utils.py b/nibabel/nicom/utils.py index 617ff2a28..24f4afc2f 100644 --- a/nibabel/nicom/utils.py +++ b/nibabel/nicom/utils.py @@ -1,5 +1,4 @@ -"""Utilities for working with DICOM datasets -""" +"""Utilities for working with DICOM datasets""" def find_private_section(dcm_data, group_no, creator): diff --git a/nibabel/nifti1.py b/nibabel/nifti1.py index 4cf1e5274..d07e54de1 100644 --- a/nibabel/nifti1.py +++ b/nibabel/nifti1.py @@ -10,6 +10,7 @@ NIfTI1 format defined at http://nifti.nimh.nih.gov/nifti-1/ """ + from __future__ import annotations import warnings diff --git a/nibabel/nifti2.py b/nibabel/nifti2.py index 8d9b81e1f..9c898b47b 100644 --- a/nibabel/nifti2.py +++ b/nibabel/nifti2.py @@ -12,6 +12,7 @@ https://www.nitrc.org/forum/message.php?msg_id=3738 """ + import numpy as np from .analyze import AnalyzeHeader diff --git a/nibabel/onetime.py b/nibabel/onetime.py index e365e81f7..fa1b2f992 100644 --- a/nibabel/onetime.py +++ b/nibabel/onetime.py @@ -18,6 +18,7 @@ [2] Python data model, https://docs.python.org/reference/datamodel.html """ + from __future__ import annotations import typing as ty @@ -136,12 +137,12 @@ def __init__(self, func: ty.Callable[[InstanceT], T]) -> None: @ty.overload def __get__( self, obj: None, objtype: type[InstanceT] | None = None - ) -> ty.Callable[[InstanceT], T]: - ... # pragma: no cover + ) -> ty.Callable[[InstanceT], T]: ... # pragma: no cover @ty.overload - def __get__(self, obj: InstanceT, objtype: type[InstanceT] | None = None) -> T: - ... # pragma: no cover + def __get__( + self, obj: InstanceT, objtype: type[InstanceT] | None = None + ) -> T: ... # pragma: no cover def __get__( self, obj: InstanceT | None, objtype: type[InstanceT] | None = None diff --git a/nibabel/openers.py b/nibabel/openers.py index d69412fb8..f84ccb706 100644 --- a/nibabel/openers.py +++ b/nibabel/openers.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Context manager openers for various fileobject types""" + from __future__ import annotations import gzip @@ -35,11 +36,9 @@ @ty.runtime_checkable class Fileish(ty.Protocol): - def read(self, size: int = -1, /) -> bytes: - ... # pragma: no cover + def read(self, size: int = -1, /) -> bytes: ... # pragma: no cover - def write(self, b: bytes, /) -> int | None: - ... # pragma: no cover + def write(self, b: bytes, /) -> int | None: ... # pragma: no cover class DeterministicGzipFile(gzip.GzipFile): diff --git a/nibabel/optpkg.py b/nibabel/optpkg.py index b59a89bb3..bfe6a629c 100644 --- a/nibabel/optpkg.py +++ b/nibabel/optpkg.py @@ -1,4 +1,5 @@ """Routines to support optional packages""" + from __future__ import annotations import typing as ty diff --git a/nibabel/orientations.py b/nibabel/orientations.py index 075cbd4ff..7265bf56f 100644 --- a/nibabel/orientations.py +++ b/nibabel/orientations.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Utilities for calculating and applying affine orientations""" + import numpy as np import numpy.linalg as npl diff --git a/nibabel/parrec.py b/nibabel/parrec.py index 3a8a6030d..d04f683d1 100644 --- a/nibabel/parrec.py +++ b/nibabel/parrec.py @@ -121,6 +121,7 @@ utility via the option "--strict-sort". The dimension info can be exported to a CSV file by adding the option "--volume-info". """ + import re import warnings from collections import OrderedDict diff --git a/nibabel/pointset.py b/nibabel/pointset.py index 58fca148a..e39a4d418 100644 --- a/nibabel/pointset.py +++ b/nibabel/pointset.py @@ -17,6 +17,7 @@ adjacent points to be identified. A *triangular mesh* in particular uses triplets of adjacent vertices to describe faces. """ + from __future__ import annotations import math @@ -40,12 +41,12 @@ class CoordinateArray(ty.Protocol): shape: tuple[int, int] @ty.overload - def __array__(self, dtype: None = ..., /) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: - ... # pragma: no cover + def __array__( + self, dtype: None = ..., / + ) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: ... # pragma: no cover @ty.overload - def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: - ... # pragma: no cover + def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: ... # pragma: no cover @dataclass diff --git a/nibabel/processing.py b/nibabel/processing.py index d634ce708..6027575d4 100644 --- a/nibabel/processing.py +++ b/nibabel/processing.py @@ -16,6 +16,7 @@ Smoothing and resampling routines need scipy. """ + import numpy as np import numpy.linalg as npl diff --git a/nibabel/pydicom_compat.py b/nibabel/pydicom_compat.py index d61c88011..76423b40a 100644 --- a/nibabel/pydicom_compat.py +++ b/nibabel/pydicom_compat.py @@ -19,6 +19,7 @@ A deprecated copy is available here for backward compatibility. """ + from __future__ import annotations import warnings diff --git a/nibabel/quaternions.py b/nibabel/quaternions.py index d2fc3ac4c..77cf8d2d3 100644 --- a/nibabel/quaternions.py +++ b/nibabel/quaternions.py @@ -25,6 +25,7 @@ >>> vec = np.array([1, 2, 3]).reshape((3,1)) # column vector >>> tvec = np.dot(M, vec) """ + import math import numpy as np diff --git a/nibabel/rstutils.py b/nibabel/rstutils.py index 625a2af47..cb40633e5 100644 --- a/nibabel/rstutils.py +++ b/nibabel/rstutils.py @@ -2,6 +2,7 @@ * Make ReST table given array of values """ + import numpy as np diff --git a/nibabel/spaces.py b/nibabel/spaces.py index e5b87171d..d06a39b0e 100644 --- a/nibabel/spaces.py +++ b/nibabel/spaces.py @@ -19,6 +19,7 @@ mapping), or * a length 2 sequence with the same information (shape, affine). """ + from itertools import product import numpy as np diff --git a/nibabel/spatialimages.py b/nibabel/spatialimages.py index bcc4336f7..185694cd7 100644 --- a/nibabel/spatialimages.py +++ b/nibabel/spatialimages.py @@ -129,6 +129,7 @@ >>> np.all(img3.get_fdata(dtype=np.float32) == data) True """ + from __future__ import annotations import io @@ -161,23 +162,18 @@ class HasDtype(ty.Protocol): - def get_data_dtype(self) -> np.dtype: - ... # pragma: no cover + def get_data_dtype(self) -> np.dtype: ... # pragma: no cover - def set_data_dtype(self, dtype: npt.DTypeLike) -> None: - ... # pragma: no cover + def set_data_dtype(self, dtype: npt.DTypeLike) -> None: ... # pragma: no cover @ty.runtime_checkable class SpatialProtocol(ty.Protocol): - def get_data_dtype(self) -> np.dtype: - ... # pragma: no cover + def get_data_dtype(self) -> np.dtype: ... # pragma: no cover - def get_data_shape(self) -> ty.Tuple[int, ...]: - ... # pragma: no cover + def get_data_shape(self) -> ty.Tuple[int, ...]: ... # pragma: no cover - def get_zooms(self) -> ty.Tuple[float, ...]: - ... # pragma: no cover + def get_zooms(self) -> ty.Tuple[float, ...]: ... # pragma: no cover class HeaderDataError(Exception): diff --git a/nibabel/spm2analyze.py b/nibabel/spm2analyze.py index f63785807..9c4c544cf 100644 --- a/nibabel/spm2analyze.py +++ b/nibabel/spm2analyze.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Read / write access to SPM2 version of analyze image format""" + import numpy as np from . import spm99analyze as spm99 # module import diff --git a/nibabel/spm99analyze.py b/nibabel/spm99analyze.py index 3465c5719..7be6c240d 100644 --- a/nibabel/spm99analyze.py +++ b/nibabel/spm99analyze.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Read / write access to SPM99 version of analyze image format""" + import warnings from io import BytesIO diff --git a/nibabel/streamlines/__init__.py b/nibabel/streamlines/__init__.py index f3cbd2da5..24a7e0146 100644 --- a/nibabel/streamlines/__init__.py +++ b/nibabel/streamlines/__init__.py @@ -1,5 +1,4 @@ -"""Multiformat-capable streamline format read / write interface -""" +"""Multiformat-capable streamline format read / write interface""" # ruff: noqa: F401 import os diff --git a/nibabel/streamlines/header.py b/nibabel/streamlines/header.py index 2aed10c62..a3b52b074 100644 --- a/nibabel/streamlines/header.py +++ b/nibabel/streamlines/header.py @@ -1,5 +1,4 @@ -"""Field class defining common header fields in tractogram files -""" +"""Field class defining common header fields in tractogram files""" class Field: diff --git a/nibabel/streamlines/tests/test_tractogram_file.py b/nibabel/streamlines/tests/test_tractogram_file.py index 71e2326ec..6f764009f 100644 --- a/nibabel/streamlines/tests/test_tractogram_file.py +++ b/nibabel/streamlines/tests/test_tractogram_file.py @@ -1,5 +1,4 @@ -"""Test tractogramFile base class -""" +"""Test tractogramFile base class""" import pytest diff --git a/nibabel/streamlines/tractogram_file.py b/nibabel/streamlines/tractogram_file.py index 2cec1ea9c..557261e9a 100644 --- a/nibabel/streamlines/tractogram_file.py +++ b/nibabel/streamlines/tractogram_file.py @@ -1,5 +1,5 @@ -"""Define abstract interface for Tractogram file classes -""" +"""Define abstract interface for Tractogram file classes""" + from abc import ABC, abstractmethod from .header import Field diff --git a/nibabel/testing/helpers.py b/nibabel/testing/helpers.py index 2f25a354d..ae859d657 100644 --- a/nibabel/testing/helpers.py +++ b/nibabel/testing/helpers.py @@ -1,5 +1,5 @@ -"""Helper functions for tests -""" +"""Helper functions for tests""" + from io import BytesIO import numpy as np diff --git a/nibabel/testing/np_features.py b/nibabel/testing/np_features.py index eeb783900..226df6484 100644 --- a/nibabel/testing/np_features.py +++ b/nibabel/testing/np_features.py @@ -1,5 +1,5 @@ -"""Look for changes in numpy behavior over versions -""" +"""Look for changes in numpy behavior over versions""" + from functools import lru_cache import numpy as np diff --git a/nibabel/tests/data/check_parrec_reslice.py b/nibabel/tests/data/check_parrec_reslice.py index 8ade7f539..244b4c3a6 100644 --- a/nibabel/tests/data/check_parrec_reslice.py +++ b/nibabel/tests/data/check_parrec_reslice.py @@ -21,6 +21,7 @@ The *_cor_SENSE* image has a higher RMS because the back of the phantom is out of the field of view. """ + import glob import numpy as np diff --git a/nibabel/tests/data/gen_standard.py b/nibabel/tests/data/gen_standard.py index 598726fe7..7fd05d936 100644 --- a/nibabel/tests/data/gen_standard.py +++ b/nibabel/tests/data/gen_standard.py @@ -5,6 +5,7 @@ * standard.trk """ + import numpy as np import nibabel as nib diff --git a/nibabel/tests/nibabel_data.py b/nibabel/tests/nibabel_data.py index 1f89c9c1a..5919eba92 100644 --- a/nibabel/tests/nibabel_data.py +++ b/nibabel/tests/nibabel_data.py @@ -1,5 +1,4 @@ -"""Functions / decorators for finding / requiring nibabel-data directory -""" +"""Functions / decorators for finding / requiring nibabel-data directory""" import unittest from os import environ, listdir diff --git a/nibabel/tests/scriptrunner.py b/nibabel/tests/scriptrunner.py index 1e8b1fdda..2f3de5079 100644 --- a/nibabel/tests/scriptrunner.py +++ b/nibabel/tests/scriptrunner.py @@ -12,6 +12,7 @@ assert_equal(code, 0) assert_equal(stdout, b'This script ran OK') """ + import os import sys from os.path import dirname, isdir, isfile, pathsep, realpath diff --git a/nibabel/tests/test_api_validators.py b/nibabel/tests/test_api_validators.py index 1d21092ee..a4e787465 100644 --- a/nibabel/tests/test_api_validators.py +++ b/nibabel/tests/test_api_validators.py @@ -1,5 +1,5 @@ -"""Metaclass and class for validating instance APIs -""" +"""Metaclass and class for validating instance APIs""" + import os import pytest diff --git a/nibabel/tests/test_arrayproxy.py b/nibabel/tests/test_arrayproxy.py index a207e4ed6..a79f63bc7 100644 --- a/nibabel/tests/test_arrayproxy.py +++ b/nibabel/tests/test_arrayproxy.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Tests for arrayproxy module -""" +"""Tests for arrayproxy module""" import contextlib import gzip diff --git a/nibabel/tests/test_batteryrunners.py b/nibabel/tests/test_batteryrunners.py index 84590452e..5cae764c8 100644 --- a/nibabel/tests/test_batteryrunners.py +++ b/nibabel/tests/test_batteryrunners.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Tests for BatteryRunner and Report objects -""" +"""Tests for BatteryRunner and Report objects""" import logging from io import StringIO diff --git a/nibabel/tests/test_casting.py b/nibabel/tests/test_casting.py index f345952aa..d4cf81515 100644 --- a/nibabel/tests/test_casting.py +++ b/nibabel/tests/test_casting.py @@ -1,5 +1,5 @@ -"""Test casting utilities -""" +"""Test casting utilities""" + import os from platform import machine diff --git a/nibabel/tests/test_data.py b/nibabel/tests/test_data.py index 3ccb4963c..cca8d0ba8 100644 --- a/nibabel/tests/test_data.py +++ b/nibabel/tests/test_data.py @@ -1,6 +1,7 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: """Tests for data module""" + import os import sys import tempfile @@ -26,7 +27,7 @@ @pytest.fixture -def with_nimd_env(request, with_environment): +def with_nimd_env(request): DATA_FUNCS = {} DATA_FUNCS['home_dir_func'] = nibd.get_nipy_user_dir DATA_FUNCS['sys_dir_func'] = nibd.get_nipy_system_dir diff --git a/nibabel/tests/test_dataobj_images.py b/nibabel/tests/test_dataobj_images.py index a1d2dbc9f..877e40781 100644 --- a/nibabel/tests/test_dataobj_images.py +++ b/nibabel/tests/test_dataobj_images.py @@ -1,5 +1,4 @@ -"""Testing dataobj_images module -""" +"""Testing dataobj_images module""" import numpy as np diff --git a/nibabel/tests/test_deprecated.py b/nibabel/tests/test_deprecated.py index 2576eca3d..f1c3d517c 100644 --- a/nibabel/tests/test_deprecated.py +++ b/nibabel/tests/test_deprecated.py @@ -1,5 +1,4 @@ -"""Testing `deprecated` module -""" +"""Testing `deprecated` module""" import warnings diff --git a/nibabel/tests/test_deprecator.py b/nibabel/tests/test_deprecator.py index 833908af9..eedeec485 100644 --- a/nibabel/tests/test_deprecator.py +++ b/nibabel/tests/test_deprecator.py @@ -1,5 +1,4 @@ -"""Testing deprecator module / Deprecator class -""" +"""Testing deprecator module / Deprecator class""" import sys import warnings diff --git a/nibabel/tests/test_dft.py b/nibabel/tests/test_dft.py index f756600fd..654af9827 100644 --- a/nibabel/tests/test_dft.py +++ b/nibabel/tests/test_dft.py @@ -1,5 +1,4 @@ -"""Testing dft -""" +"""Testing dft""" import os import sqlite3 diff --git a/nibabel/tests/test_diff.py b/nibabel/tests/test_diff.py index fee71d628..798a7f7b3 100644 --- a/nibabel/tests/test_diff.py +++ b/nibabel/tests/test_diff.py @@ -1,7 +1,6 @@ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: -"""Test diff -""" +"""Test diff""" from os.path import abspath, dirname from os.path import join as pjoin diff --git a/nibabel/tests/test_ecat_data.py b/nibabel/tests/test_ecat_data.py index 23485ae92..427645b92 100644 --- a/nibabel/tests/test_ecat_data.py +++ b/nibabel/tests/test_ecat_data.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Test we can correctly import example ECAT files -""" +"""Test we can correctly import example ECAT files""" import os from os.path import join as pjoin diff --git a/nibabel/tests/test_environment.py b/nibabel/tests/test_environment.py index afb6d36f8..aa58d9b8e 100644 --- a/nibabel/tests/test_environment.py +++ b/nibabel/tests/test_environment.py @@ -1,5 +1,4 @@ -"""Testing environment settings -""" +"""Testing environment settings""" import os from os import environ as env diff --git a/nibabel/tests/test_filebasedimages.py b/nibabel/tests/test_filebasedimages.py index 3aa1ae78c..7d162c091 100644 --- a/nibabel/tests/test_filebasedimages.py +++ b/nibabel/tests/test_filebasedimages.py @@ -1,5 +1,4 @@ -"""Testing filebasedimages module -""" +"""Testing filebasedimages module""" import warnings from itertools import product diff --git a/nibabel/tests/test_fileholders.py b/nibabel/tests/test_fileholders.py index 33b3f76e6..83fe75aec 100644 --- a/nibabel/tests/test_fileholders.py +++ b/nibabel/tests/test_fileholders.py @@ -1,5 +1,4 @@ -"""Testing fileholders -""" +"""Testing fileholders""" from io import BytesIO diff --git a/nibabel/tests/test_filename_parser.py b/nibabel/tests/test_filename_parser.py index 5d352f72d..4e53cb2e5 100644 --- a/nibabel/tests/test_filename_parser.py +++ b/nibabel/tests/test_filename_parser.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Tests for filename container""" + import pathlib import pytest diff --git a/nibabel/tests/test_files_interface.py b/nibabel/tests/test_files_interface.py index 52557d353..07e394eca 100644 --- a/nibabel/tests/test_files_interface.py +++ b/nibabel/tests/test_files_interface.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Testing filesets - a draft -""" +"""Testing filesets - a draft""" from io import BytesIO diff --git a/nibabel/tests/test_fileslice.py b/nibabel/tests/test_fileslice.py index e9f65e45a..355743b04 100644 --- a/nibabel/tests/test_fileslice.py +++ b/nibabel/tests/test_fileslice.py @@ -1,6 +1,5 @@ """Test slicing of file-like objects""" - import time from functools import partial from io import BytesIO diff --git a/nibabel/tests/test_fileutils.py b/nibabel/tests/test_fileutils.py index 21c7676fc..bc202c668 100644 --- a/nibabel/tests/test_fileutils.py +++ b/nibabel/tests/test_fileutils.py @@ -6,9 +6,7 @@ # copyright and license terms. # # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Testing fileutils module -""" - +"""Testing fileutils module""" import pytest diff --git a/nibabel/tests/test_floating.py b/nibabel/tests/test_floating.py index c2ccd4403..82c8e667a 100644 --- a/nibabel/tests/test_floating.py +++ b/nibabel/tests/test_floating.py @@ -1,5 +1,5 @@ -"""Test floating point deconstructions and floor methods -""" +"""Test floating point deconstructions and floor methods""" + import sys import numpy as np diff --git a/nibabel/tests/test_image_api.py b/nibabel/tests/test_image_api.py index 86c04985f..589876232 100644 --- a/nibabel/tests/test_image_api.py +++ b/nibabel/tests/test_image_api.py @@ -50,7 +50,6 @@ clear_and_catch_warnings, deprecated_to, expires, - nullcontext, ) from .. import ( diff --git a/nibabel/tests/test_image_load_save.py b/nibabel/tests/test_image_load_save.py index 4e787f0d7..934698d9e 100644 --- a/nibabel/tests/test_image_load_save.py +++ b/nibabel/tests/test_image_load_save.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Tests for loader function""" + import logging import pathlib import shutil diff --git a/nibabel/tests/test_imageclasses.py b/nibabel/tests/test_imageclasses.py index 90424b7d3..7b3add6cd 100644 --- a/nibabel/tests/test_imageclasses.py +++ b/nibabel/tests/test_imageclasses.py @@ -1,5 +1,4 @@ -"""Testing imageclasses module -""" +"""Testing imageclasses module""" from os.path import dirname from os.path import join as pjoin diff --git a/nibabel/tests/test_imageglobals.py b/nibabel/tests/test_imageglobals.py index ac043d192..9de72e87c 100644 --- a/nibabel/tests/test_imageglobals.py +++ b/nibabel/tests/test_imageglobals.py @@ -6,8 +6,8 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Tests for imageglobals module -""" +"""Tests for imageglobals module""" + from .. import imageglobals as igs diff --git a/nibabel/tests/test_loadsave.py b/nibabel/tests/test_loadsave.py index 401ed0453..d039263bd 100644 --- a/nibabel/tests/test_loadsave.py +++ b/nibabel/tests/test_loadsave.py @@ -1,5 +1,4 @@ -"""Testing loadsave module -""" +"""Testing loadsave module""" import pathlib import shutil diff --git a/nibabel/tests/test_minc2_data.py b/nibabel/tests/test_minc2_data.py index e96e71669..a5ea38a8a 100644 --- a/nibabel/tests/test_minc2_data.py +++ b/nibabel/tests/test_minc2_data.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Test we can correctly import example MINC2_PATH files -""" +"""Test we can correctly import example MINC2_PATH files""" import os from os.path import join as pjoin diff --git a/nibabel/tests/test_mriutils.py b/nibabel/tests/test_mriutils.py index 848579cee..02b9da548 100644 --- a/nibabel/tests/test_mriutils.py +++ b/nibabel/tests/test_mriutils.py @@ -6,9 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Testing mriutils module -""" - +"""Testing mriutils module""" import pytest from numpy.testing import assert_almost_equal diff --git a/nibabel/tests/test_nibabel_data.py b/nibabel/tests/test_nibabel_data.py index 0c7116e9a..7e319ac3f 100644 --- a/nibabel/tests/test_nibabel_data.py +++ b/nibabel/tests/test_nibabel_data.py @@ -1,5 +1,4 @@ -"""Tests for ``get_nibabel_data`` -""" +"""Tests for ``get_nibabel_data``""" import os from os.path import dirname, isdir, realpath diff --git a/nibabel/tests/test_nifti1.py b/nibabel/tests/test_nifti1.py index a5b9427bc..5ee4fb3c1 100644 --- a/nibabel/tests/test_nifti1.py +++ b/nibabel/tests/test_nifti1.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Tests for nifti reading package""" + import os import struct import unittest diff --git a/nibabel/tests/test_nifti2.py b/nibabel/tests/test_nifti2.py index a25e23b49..01d44c159 100644 --- a/nibabel/tests/test_nifti2.py +++ b/nibabel/tests/test_nifti2.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Tests for nifti2 reading package""" + import os import numpy as np diff --git a/nibabel/tests/test_onetime.py b/nibabel/tests/test_onetime.py index b22a4ef3e..4d7294927 100644 --- a/nibabel/tests/test_onetime.py +++ b/nibabel/tests/test_onetime.py @@ -1,5 +1,3 @@ -import pytest - from nibabel.onetime import auto_attr, setattr_on_read from nibabel.testing import deprecated_to, expires diff --git a/nibabel/tests/test_openers.py b/nibabel/tests/test_openers.py index 5c6a1643c..15290d5ef 100644 --- a/nibabel/tests/test_openers.py +++ b/nibabel/tests/test_openers.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Test for openers module""" + import contextlib import hashlib import os diff --git a/nibabel/tests/test_optpkg.py b/nibabel/tests/test_optpkg.py index 7ffaa2f85..c243633a0 100644 --- a/nibabel/tests/test_optpkg.py +++ b/nibabel/tests/test_optpkg.py @@ -1,5 +1,4 @@ -"""Testing optpkg module -""" +"""Testing optpkg module""" import builtins import sys diff --git a/nibabel/tests/test_orientations.py b/nibabel/tests/test_orientations.py index 7e4a33e29..e7c32d786 100644 --- a/nibabel/tests/test_orientations.py +++ b/nibabel/tests/test_orientations.py @@ -8,7 +8,6 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Testing for orientations module""" - import numpy as np import pytest from numpy.testing import assert_array_equal diff --git a/nibabel/tests/test_parrec.py b/nibabel/tests/test_parrec.py index 980a2f403..a312c558a 100644 --- a/nibabel/tests/test_parrec.py +++ b/nibabel/tests/test_parrec.py @@ -1,5 +1,4 @@ -"""Testing parrec module -""" +"""Testing parrec module""" from glob import glob from os.path import basename, dirname diff --git a/nibabel/tests/test_parrec_data.py b/nibabel/tests/test_parrec_data.py index 2a52d9725..02a1d5733 100644 --- a/nibabel/tests/test_parrec_data.py +++ b/nibabel/tests/test_parrec_data.py @@ -1,5 +1,4 @@ -"""Test we can correctly import example PARREC files -""" +"""Test we can correctly import example PARREC files""" import unittest from glob import glob diff --git a/nibabel/tests/test_pkg_info.py b/nibabel/tests/test_pkg_info.py index 1422bb335..c927b0fb9 100644 --- a/nibabel/tests/test_pkg_info.py +++ b/nibabel/tests/test_pkg_info.py @@ -1,5 +1,4 @@ -"""Testing package info -""" +"""Testing package info""" import pytest diff --git a/nibabel/tests/test_processing.py b/nibabel/tests/test_processing.py index 27da6639c..f1a4f0a90 100644 --- a/nibabel/tests/test_processing.py +++ b/nibabel/tests/test_processing.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Testing processing module -""" +"""Testing processing module""" import logging from os.path import dirname diff --git a/nibabel/tests/test_rstutils.py b/nibabel/tests/test_rstutils.py index 847b7a4ee..eab196985 100644 --- a/nibabel/tests/test_rstutils.py +++ b/nibabel/tests/test_rstutils.py @@ -1,5 +1,4 @@ -"""Test printable table -""" +"""Test printable table""" import numpy as np import pytest diff --git a/nibabel/tests/test_spaces.py b/nibabel/tests/test_spaces.py index dbfe53389..f5e467b2c 100644 --- a/nibabel/tests/test_spaces.py +++ b/nibabel/tests/test_spaces.py @@ -1,5 +1,4 @@ -"""Tests for spaces module -""" +"""Tests for spaces module""" import numpy as np import numpy.linalg as npl diff --git a/nibabel/tests/test_spatialimages.py b/nibabel/tests/test_spatialimages.py index a5cab9e75..3d14dac18 100644 --- a/nibabel/tests/test_spatialimages.py +++ b/nibabel/tests/test_spatialimages.py @@ -6,8 +6,7 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -"""Testing spatialimages -""" +"""Testing spatialimages""" from io import BytesIO diff --git a/nibabel/tests/test_testing.py b/nibabel/tests/test_testing.py index 1ca1fb9b9..6b8472521 100644 --- a/nibabel/tests/test_testing.py +++ b/nibabel/tests/test_testing.py @@ -1,5 +1,4 @@ -"""Tests for warnings context managers -""" +"""Tests for warnings context managers""" import os import sys diff --git a/nibabel/tests/test_tripwire.py b/nibabel/tests/test_tripwire.py index f172d5c57..bcc81b5f5 100644 --- a/nibabel/tests/test_tripwire.py +++ b/nibabel/tests/test_tripwire.py @@ -1,5 +1,4 @@ -"""Testing tripwire module -""" +"""Testing tripwire module""" import pytest diff --git a/nibabel/tests/test_wrapstruct.py b/nibabel/tests/test_wrapstruct.py index e18fb0210..0eb906fee 100644 --- a/nibabel/tests/test_wrapstruct.py +++ b/nibabel/tests/test_wrapstruct.py @@ -23,6 +23,7 @@ _field_recoders -> field_recoders """ + import logging from io import BytesIO, StringIO diff --git a/nibabel/tmpdirs.py b/nibabel/tmpdirs.py index 49d69d2bf..9d67f6acb 100644 --- a/nibabel/tmpdirs.py +++ b/nibabel/tmpdirs.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Contexts for *with* statement providing temporary directories""" + import os import tempfile from contextlib import contextmanager diff --git a/nibabel/tripwire.py b/nibabel/tripwire.py index fa45e7338..efe651fd9 100644 --- a/nibabel/tripwire.py +++ b/nibabel/tripwire.py @@ -1,4 +1,5 @@ """Class to raise error for missing modules or other misfortunes""" + from typing import Any diff --git a/nibabel/viewers.py b/nibabel/viewers.py index 60ebd3a25..1e927544b 100644 --- a/nibabel/viewers.py +++ b/nibabel/viewers.py @@ -3,6 +3,7 @@ Includes version of OrthoSlicer3D code originally written by our own Paul Ivanov. """ + import weakref import numpy as np diff --git a/nibabel/volumeutils.py b/nibabel/volumeutils.py index 90e5e5ff3..cf2437e62 100644 --- a/nibabel/volumeutils.py +++ b/nibabel/volumeutils.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Utility functions for analyze-like formats""" + from __future__ import annotations import io @@ -1190,13 +1191,13 @@ def _ftype4scaled_finite( @ty.overload def finite_range( arr: npt.ArrayLike, check_nan: ty.Literal[False] = False -) -> tuple[Scalar, Scalar]: - ... # pragma: no cover +) -> tuple[Scalar, Scalar]: ... # pragma: no cover @ty.overload -def finite_range(arr: npt.ArrayLike, check_nan: ty.Literal[True]) -> tuple[Scalar, Scalar, bool]: - ... # pragma: no cover +def finite_range( + arr: npt.ArrayLike, check_nan: ty.Literal[True] +) -> tuple[Scalar, Scalar, bool]: ... # pragma: no cover def finite_range( diff --git a/nibabel/wrapstruct.py b/nibabel/wrapstruct.py index 6e236d735..5ffe04bc7 100644 --- a/nibabel/wrapstruct.py +++ b/nibabel/wrapstruct.py @@ -109,6 +109,7 @@ nib.imageglobals.logger = logger """ + from __future__ import annotations import numpy as np diff --git a/nibabel/xmlutils.py b/nibabel/xmlutils.py index d3a7a0830..5049a7641 100644 --- a/nibabel/xmlutils.py +++ b/nibabel/xmlutils.py @@ -7,6 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Thin layer around xml.etree.ElementTree, to abstract nibabel xml support""" + from io import BytesIO from xml.etree.ElementTree import Element, SubElement, tostring # noqa from xml.parsers.expat import ParserCreate diff --git a/tox.ini b/tox.ini index 53860445a..2e6a2449e 100644 --- a/tox.ini +++ b/tox.ini @@ -142,7 +142,7 @@ deps = ruff>=0.3.0 skip_install = true commands = - ruff --diff nibabel + ruff check --diff nibabel ruff format --diff nibabel [testenv:style-fix] From a6f2a61f16308d7a3dcb968e60b2ffce1f7cbc53 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:14:21 +0100 Subject: [PATCH 05/32] MNT: get rid of .flake8/.pep8speaks.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are made obsolete by teh flake8 → ruff shift. --- .flake8 | 9 --------- .pep8speaks.yml | 12 ------------ 2 files changed, 21 deletions(-) delete mode 100644 .flake8 delete mode 100644 .pep8speaks.yml diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 9fe631ac8..000000000 --- a/.flake8 +++ /dev/null @@ -1,9 +0,0 @@ -[flake8] -max-line-length = 100 -extend-ignore = E203,E266,E402,E731 -exclude = - *test* - *sphinx* - nibabel/externals/* -per-file-ignores = - */__init__.py: F401 diff --git a/.pep8speaks.yml b/.pep8speaks.yml deleted file mode 100644 index 0a0d8c619..000000000 --- a/.pep8speaks.yml +++ /dev/null @@ -1,12 +0,0 @@ -scanner: - diff_only: True # Only show errors caused by the patch - linter: flake8 - -message: # Customize the comment made by the bot - opened: # Messages when a new PR is submitted - header: "Hello @{name}, thank you for submitting the Pull Request!" - footer: "To test for issues locally, `pip install flake8` and then run `flake8 nibabel`." - updated: # Messages when new commits are added to the PR - header: "Hello @{name}, Thank you for updating!" - footer: "To test for issues locally, `pip install flake8` and then run `flake8 nibabel`." - no_errors: "Cheers! There are no style issues detected in this Pull Request. :beers: " From ac29ed26d403791f5868ac10056136a5ce66ddd7 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:25:11 +0100 Subject: [PATCH 06/32] MNT: ignore F401 in __init__.py Enforce that in pyproject.toml instead of __init__.py itself. --- nibabel/__init__.py | 2 -- nibabel/cifti2/__init__.py | 1 - nibabel/freesurfer/__init__.py | 2 -- nibabel/gifti/__init__.py | 2 -- nibabel/parrec.py | 2 +- nibabel/streamlines/__init__.py | 1 - nibabel/testing/__init__.py | 2 -- pyproject.toml | 3 +++ 8 files changed, 4 insertions(+), 11 deletions(-) diff --git a/nibabel/__init__.py b/nibabel/__init__.py index 1cb7abf53..aa90540b8 100644 --- a/nibabel/__init__.py +++ b/nibabel/__init__.py @@ -7,8 +7,6 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -# ruff: noqa: F401 - import os from .info import long_description as __doc__ diff --git a/nibabel/cifti2/__init__.py b/nibabel/cifti2/__init__.py index 4a5cad767..9c6805f81 100644 --- a/nibabel/cifti2/__init__.py +++ b/nibabel/cifti2/__init__.py @@ -6,7 +6,6 @@ # copyright and license terms. # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## -# ruff: noqa: F401 """CIFTI-2 format IO .. currentmodule:: nibabel.cifti2 diff --git a/nibabel/freesurfer/__init__.py b/nibabel/freesurfer/__init__.py index aa76eb2e8..1ab385975 100644 --- a/nibabel/freesurfer/__init__.py +++ b/nibabel/freesurfer/__init__.py @@ -1,7 +1,5 @@ """Reading functions for freesurfer files""" -# ruff: noqa: F401 - from .io import ( read_annot, read_geometry, diff --git a/nibabel/gifti/__init__.py b/nibabel/gifti/__init__.py index d2a1e2da6..f54a1d2e5 100644 --- a/nibabel/gifti/__init__.py +++ b/nibabel/gifti/__init__.py @@ -16,8 +16,6 @@ gifti """ -# ruff: noqa: F401 - from .gifti import ( GiftiCoordSystem, GiftiDataArray, diff --git a/nibabel/parrec.py b/nibabel/parrec.py index d04f683d1..8b3ffb34a 100644 --- a/nibabel/parrec.py +++ b/nibabel/parrec.py @@ -7,7 +7,7 @@ # ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## # Disable line length checking for PAR fragments in module docstring -# flake8: noqa E501 +# noqa: E501 """Read images in PAR/REC format This is yet another MRI image format generated by Philips scanners. It is an diff --git a/nibabel/streamlines/__init__.py b/nibabel/streamlines/__init__.py index 24a7e0146..dd00a1e84 100644 --- a/nibabel/streamlines/__init__.py +++ b/nibabel/streamlines/__init__.py @@ -1,5 +1,4 @@ """Multiformat-capable streamline format read / write interface""" -# ruff: noqa: F401 import os import warnings diff --git a/nibabel/testing/__init__.py b/nibabel/testing/__init__.py index a3e98e064..d335c9a8c 100644 --- a/nibabel/testing/__init__.py +++ b/nibabel/testing/__init__.py @@ -8,8 +8,6 @@ ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## """Utilities for testing""" -# ruff: noqa: F401 - from __future__ import annotations import os diff --git a/pyproject.toml b/pyproject.toml index 515c35850..5df6d0189 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,6 +133,9 @@ ignore = [ "ISC002", ] +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["F401"] + [tool.ruff.format] quote-style = "single" From d3352aef6991f1df8013d6bdc67aca56288dd346 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:27:28 +0100 Subject: [PATCH 07/32] =?UTF-8?q?MNT:=20ruff=200.3.0=20=E2=86=92=200.3.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d35d28757..354bd3da1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: check-merge-conflict - id: check-vcs-permalinks - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.0 + rev: v0.3.4 hooks: - id: ruff args: [--fix, --show-fix, --exit-non-zero-on-fix] From f57f5cbc4bb8d62861ee0c00931c134e4a66e0d7 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:29:51 +0100 Subject: [PATCH 08/32] Update doc/tools/apigen.py Co-authored-by: Chris Markiewicz --- doc/tools/apigen.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/tools/apigen.py b/doc/tools/apigen.py index a1279a3e9..336c81d8d 100644 --- a/doc/tools/apigen.py +++ b/doc/tools/apigen.py @@ -405,9 +405,7 @@ def discover_modules(self): def write_modules_api(self, modules, outdir): # upper-level modules - ulms = [ - '.'.join(m.split('.')[:2]) if m.count('.') >= 1 else m.split('.')[0] for m in modules - ] + ulms = ['.'.join(m.split('.')[:2]) for m in modules] from collections import OrderedDict From 1684a9dada92558b44ce7995f2050f5111f1ec33 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:30:36 +0100 Subject: [PATCH 09/32] Update nibabel/cifti2/tests/test_cifti2io_header.py Co-authored-by: Chris Markiewicz --- nibabel/cifti2/tests/test_cifti2io_header.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/cifti2/tests/test_cifti2io_header.py b/nibabel/cifti2/tests/test_cifti2io_header.py index 92078a26d..1c37cfe0e 100644 --- a/nibabel/cifti2/tests/test_cifti2io_header.py +++ b/nibabel/cifti2/tests/test_cifti2io_header.py @@ -37,7 +37,7 @@ def test_space_separated_affine(): - _ = ci.Cifti2Image.from_filename(pjoin(NIBABEL_TEST_DATA, 'row_major.dconn.nii')) + ci.Cifti2Image.from_filename(pjoin(NIBABEL_TEST_DATA, 'row_major.dconn.nii')) def test_read_nifti2(): From a8ba819a26a15d6be2ea5c2bb6d6eaaaf89cef93 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:32:21 +0100 Subject: [PATCH 10/32] Update nibabel/gifti/tests/test_gifti.py Co-authored-by: Chris Markiewicz --- nibabel/gifti/tests/test_gifti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/gifti/tests/test_gifti.py b/nibabel/gifti/tests/test_gifti.py index f27546afe..88a2f31f8 100644 --- a/nibabel/gifti/tests/test_gifti.py +++ b/nibabel/gifti/tests/test_gifti.py @@ -328,7 +328,7 @@ def test_metadata_list_interface(): assert len(md) == 0 # Extension adds multiple keys - with pytest.warns(DeprecationWarning) as _: + with deprecated_to('6.0'): foobar = GiftiNVPairs('foo', 'bar') mdlist.extend([nvpair, foobar]) assert len(mdlist) == 2 From d797ffe10431a4c62322d81495873bf01e277e72 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:32:37 +0100 Subject: [PATCH 11/32] Update nibabel/tests/test_pkg_info.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_pkg_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/tests/test_pkg_info.py b/nibabel/tests/test_pkg_info.py index c927b0fb9..a39eac65b 100644 --- a/nibabel/tests/test_pkg_info.py +++ b/nibabel/tests/test_pkg_info.py @@ -14,7 +14,7 @@ def test_pkg_info(): - nibabel.pkg_info.get_pkg_info - nibabel.pkg_info.pkg_commit_hash """ - _ = nib.get_info() + nib.get_info() def test_version(): From 59d6291ac98b1be6784b88291b9826220c1f7241 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:32:54 +0100 Subject: [PATCH 12/32] Update nibabel/gifti/tests/test_gifti.py Co-authored-by: Chris Markiewicz --- nibabel/gifti/tests/test_gifti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/gifti/tests/test_gifti.py b/nibabel/gifti/tests/test_gifti.py index 88a2f31f8..a4cf5bb48 100644 --- a/nibabel/gifti/tests/test_gifti.py +++ b/nibabel/gifti/tests/test_gifti.py @@ -336,7 +336,7 @@ def test_metadata_list_interface(): assert md == {'key': 'value', 'foo': 'bar'} # Insertion updates list order, though we don't attempt to preserve it in the dict - with pytest.warns(DeprecationWarning) as _: + with deprecated_to('6.0'): lastone = GiftiNVPairs('last', 'one') mdlist.insert(1, lastone) assert len(mdlist) == 3 From 6daadc82d4634b7c9d31cc65f7de288ef67328ad Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:33:16 +0100 Subject: [PATCH 13/32] Update nibabel/tests/test_spatialimages.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_spatialimages.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nibabel/tests/test_spatialimages.py b/nibabel/tests/test_spatialimages.py index 3d14dac18..baf470090 100644 --- a/nibabel/tests/test_spatialimages.py +++ b/nibabel/tests/test_spatialimages.py @@ -398,7 +398,10 @@ def test_slicer(self): img_klass = self.image_class in_data_template = np.arange(240, dtype=np.int16) base_affine = np.eye(4) - for dshape in ((4, 5, 6, 2), (8, 5, 6)): # Time series # Volume + for dshape in ( + (4, 5, 6, 2), # Time series + (8, 5, 6), # Volume + ): in_data = in_data_template.copy().reshape(dshape) img = img_klass(in_data, base_affine.copy()) From 32d0109c3a26fed6ac49d91613bef7193f324aac Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:33:29 +0100 Subject: [PATCH 14/32] Update nibabel/tests/test_testing.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/tests/test_testing.py b/nibabel/tests/test_testing.py index 6b8472521..c9f91eb84 100644 --- a/nibabel/tests/test_testing.py +++ b/nibabel/tests/test_testing.py @@ -133,7 +133,7 @@ def test_warn_ignore(): with suppress_warnings(): warnings.warn('Here is a warning, you will not see it') warnings.warn('Nor this one', DeprecationWarning) - with suppress_warnings() as _: + with suppress_warnings(): warnings.warn('Here is a warning, you will not see it') warnings.warn('Nor this one', DeprecationWarning) assert n_warns == len(warnings.filters) From 9104d2fcfbd914494d5d4626c5a5bad0a675d6d0 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:33:38 +0100 Subject: [PATCH 15/32] Update tox.ini Co-authored-by: Chris Markiewicz --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 2e6a2449e..d0b865345 100644 --- a/tox.ini +++ b/tox.ini @@ -152,7 +152,7 @@ deps = ruff skip_install = true commands = - ruff --fix nibabel + ruff check --fix nibabel ruff format nibabel [testenv:spellcheck] From 02918edececbef01d9d536c4452cb17c0fd35955 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 27 Mar 2024 15:34:08 +0100 Subject: [PATCH 16/32] Update nibabel/tests/test_testing.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/tests/test_testing.py b/nibabel/tests/test_testing.py index c9f91eb84..04ba813d8 100644 --- a/nibabel/tests/test_testing.py +++ b/nibabel/tests/test_testing.py @@ -113,7 +113,7 @@ def test_warn_error(): with error_warnings(): with pytest.raises(UserWarning): warnings.warn('A test') - with error_warnings() as _: + with error_warnings(): with pytest.raises(UserWarning): warnings.warn('A test') assert n_warns == len(warnings.filters) From eeab46f658d9cf754ea9aeda5e3836553e6139d3 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:53:36 +0100 Subject: [PATCH 17/32] Update nibabel/gifti/tests/test_gifti.py Co-authored-by: Chris Markiewicz --- nibabel/gifti/tests/test_gifti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/gifti/tests/test_gifti.py b/nibabel/gifti/tests/test_gifti.py index a4cf5bb48..6c867ad25 100644 --- a/nibabel/gifti/tests/test_gifti.py +++ b/nibabel/gifti/tests/test_gifti.py @@ -360,7 +360,7 @@ def test_metadata_list_interface(): assert 'completelynew' not in md assert md == {'foo': 'bar', 'last': 'one'} # Check popping from the end (last one inserted before foobar) - _ = mdlist.pop() + mdlist.pop() assert len(mdlist) == 1 assert len(md) == 1 assert md == {'last': 'one'} From 46c84879dc2952b69508ad489927437ad1e471ab Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:53:51 +0100 Subject: [PATCH 18/32] Update nibabel/gifti/tests/test_gifti.py Co-authored-by: Chris Markiewicz --- nibabel/gifti/tests/test_gifti.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/gifti/tests/test_gifti.py b/nibabel/gifti/tests/test_gifti.py index 6c867ad25..1cead0d92 100644 --- a/nibabel/gifti/tests/test_gifti.py +++ b/nibabel/gifti/tests/test_gifti.py @@ -366,7 +366,7 @@ def test_metadata_list_interface(): assert md == {'last': 'one'} # And let's remove an old pair with a new object - with pytest.warns(DeprecationWarning) as _: + with deprecated_to('6.0'): lastoneagain = GiftiNVPairs('last', 'one') mdlist.remove(lastoneagain) assert len(mdlist) == 0 From dec3a2dba421db615aaa9c85cd53d002b4af5644 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:54:03 +0100 Subject: [PATCH 19/32] Update nibabel/gifti/tests/test_parse_gifti_fast.py Co-authored-by: Chris Markiewicz --- nibabel/gifti/tests/test_parse_gifti_fast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/gifti/tests/test_parse_gifti_fast.py b/nibabel/gifti/tests/test_parse_gifti_fast.py index 17258fbd3..c562b9048 100644 --- a/nibabel/gifti/tests/test_parse_gifti_fast.py +++ b/nibabel/gifti/tests/test_parse_gifti_fast.py @@ -447,7 +447,7 @@ def test_external_file_failure_cases(): shutil.copy(DATA_FILE7, '.') filename = pjoin(tmpdir, basename(DATA_FILE7)) with pytest.raises(GiftiParseError): - _ = load(filename) + load(filename) # load from in-memory xml string (parser requires it as bytes) with open(DATA_FILE7, 'rb') as f: xmldata = f.read() From d8d3a4489c67b84e61b0d2aa190bb2b31b5d3a1e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:54:17 +0100 Subject: [PATCH 20/32] Update nibabel/gifti/tests/test_parse_gifti_fast.py Co-authored-by: Chris Markiewicz --- nibabel/gifti/tests/test_parse_gifti_fast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/gifti/tests/test_parse_gifti_fast.py b/nibabel/gifti/tests/test_parse_gifti_fast.py index c562b9048..8cb7c9679 100644 --- a/nibabel/gifti/tests/test_parse_gifti_fast.py +++ b/nibabel/gifti/tests/test_parse_gifti_fast.py @@ -453,7 +453,7 @@ def test_external_file_failure_cases(): xmldata = f.read() parser = GiftiImageParser() with pytest.raises(GiftiParseError): - _ = parser.parse(xmldata) + parser.parse(xmldata) def test_load_compressed(): From de9f2b0a2a246b60cb6bcae8780df000a70cd59d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:54:29 +0100 Subject: [PATCH 21/32] Update nibabel/nicom/tests/test_dicomwrappers.py Co-authored-by: Chris Markiewicz --- nibabel/nicom/tests/test_dicomwrappers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/nicom/tests/test_dicomwrappers.py b/nibabel/nicom/tests/test_dicomwrappers.py index e96607df9..d14c35dcd 100755 --- a/nibabel/nicom/tests/test_dicomwrappers.py +++ b/nibabel/nicom/tests/test_dicomwrappers.py @@ -630,7 +630,7 @@ def test_image_position(self): def test_affine(self): # Make sure we find orientation/position/spacing info dw = didw.wrapper_from_file(DATA_FILE_4D) - _ = dw.affine + dw.affine @dicom_test @pytest.mark.xfail(reason='Not packaged in install', raises=FileNotFoundError) From b7a5f5aa644ca645499a88438360d814ef377769 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:54:45 +0100 Subject: [PATCH 22/32] Update nibabel/streamlines/tests/test_tck.py Co-authored-by: Chris Markiewicz --- nibabel/streamlines/tests/test_tck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/streamlines/tests/test_tck.py b/nibabel/streamlines/tests/test_tck.py index 6b4c163ed..083ab8e6e 100644 --- a/nibabel/streamlines/tests/test_tck.py +++ b/nibabel/streamlines/tests/test_tck.py @@ -137,7 +137,7 @@ def test_load_file_with_wrong_information(self): # Simulate a TCK file with no `file` field. new_tck_file = tck_file.replace(b'\nfile: . 67', b'') - with pytest.warns(HeaderWarning, match="Missing 'file'") as _: + with pytest.warns(HeaderWarning, match="Missing 'file'"): tck = TckFile.load(BytesIO(new_tck_file)) assert_array_equal(tck.header['file'], '. 56') From a621d41987ae64f964fe71b800a59771981f4130 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:55:04 +0100 Subject: [PATCH 23/32] Update nibabel/streamlines/tests/test_trk.py Co-authored-by: Chris Markiewicz --- nibabel/streamlines/tests/test_trk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/streamlines/tests/test_trk.py b/nibabel/streamlines/tests/test_trk.py index 749bf3ed3..4cb6032c2 100644 --- a/nibabel/streamlines/tests/test_trk.py +++ b/nibabel/streamlines/tests/test_trk.py @@ -149,7 +149,7 @@ def test_load_file_with_wrong_information(self): # Simulate a TRK where `vox_to_ras` is invalid. trk_struct, trk_bytes = self.trk_with_bytes() trk_struct[Field.VOXEL_TO_RASMM] = np.diag([0, 0, 0, 1]) - with clear_and_catch_warnings(record=True, modules=[trk_module]) as _: + with clear_and_catch_warnings(modules=[trk_module]): with pytest.raises(HeaderError): TrkFile.load(BytesIO(trk_bytes)) From 37ff0ebe9dd035f99d28ded561928f58315fdb68 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:55:31 +0100 Subject: [PATCH 24/32] Update nibabel/tests/test_affines.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_affines.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nibabel/tests/test_affines.py b/nibabel/tests/test_affines.py index 1d7ef1e6b..d4ea11821 100644 --- a/nibabel/tests/test_affines.py +++ b/nibabel/tests/test_affines.py @@ -225,7 +225,6 @@ def test_rescale_affine(): orig_shape = rng.randint(low=20, high=512, size=(3,)) orig_aff = np.eye(4) orig_aff[:3, :] = rng.normal(size=(3, 4)) - orig_zooms = voxel_sizes(orig_aff) # noqa: F841 orig_axcodes = aff2axcodes(orig_aff) orig_centroid = apply_affine(orig_aff, (orig_shape - 1) // 2) From 36d36fbddcdb1c0cb4f3fc503452291ba90971a6 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:55:51 +0100 Subject: [PATCH 25/32] Update nibabel/tests/test_arraywriters.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_arraywriters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/tests/test_arraywriters.py b/nibabel/tests/test_arraywriters.py index 2fc9c3235..25040e5ee 100644 --- a/nibabel/tests/test_arraywriters.py +++ b/nibabel/tests/test_arraywriters.py @@ -276,7 +276,7 @@ def test_slope_inter_castable(): for out_dtt in NUMERIC_TYPES: for klass in (ArrayWriter, SlopeArrayWriter, SlopeInterArrayWriter): arr = np.zeros((5,), dtype=in_dtt) - _ = klass(arr, out_dtt) # no error + klass(arr, out_dtt) # no error # Test special case of none finite # This raises error for ArrayWriter, but not for the others arr = np.array([np.inf, np.nan, -np.inf]) From 0922369b170a38215b9cc6d0d2ce69d668f579c1 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:56:13 +0100 Subject: [PATCH 26/32] Update nibabel/tests/test_arraywriters.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_arraywriters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nibabel/tests/test_arraywriters.py b/nibabel/tests/test_arraywriters.py index 25040e5ee..4a853ecf5 100644 --- a/nibabel/tests/test_arraywriters.py +++ b/nibabel/tests/test_arraywriters.py @@ -285,8 +285,8 @@ def test_slope_inter_castable(): in_arr = arr.astype(in_dtt) with pytest.raises(WriterError): ArrayWriter(in_arr, out_dtt) - _ = SlopeArrayWriter(arr.astype(in_dtt), out_dtt) # no error - _ = SlopeInterArrayWriter(arr.astype(in_dtt), out_dtt) # no error + SlopeArrayWriter(arr.astype(in_dtt), out_dtt) # no error + SlopeInterArrayWriter(arr.astype(in_dtt), out_dtt) # no error for in_dtt, out_dtt, arr, slope_only, slope_inter, neither in ( (np.float32, np.float32, 1, True, True, True), (np.float64, np.float32, 1, True, True, True), From 50177cc9e521716234510dab8c4bd48892c40b6a Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:56:53 +0100 Subject: [PATCH 27/32] Update nibabel/tests/test_image_load_save.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_image_load_save.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/tests/test_image_load_save.py b/nibabel/tests/test_image_load_save.py index 934698d9e..0e5fd57d0 100644 --- a/nibabel/tests/test_image_load_save.py +++ b/nibabel/tests/test_image_load_save.py @@ -131,7 +131,7 @@ def test_save_load(): affine[:3, 3] = [3, 2, 1] img = ni1.Nifti1Image(data, affine) img.set_data_dtype(npt) - with InTemporaryDirectory() as _: + with InTemporaryDirectory(): nifn = 'an_image.nii' sifn = 'another_image.img' ni1.save(img, nifn) From 489b9d29795d33c46a4b2e0e079a22bb4a6e9a1e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:57:11 +0100 Subject: [PATCH 28/32] Update nibabel/tests/test_imageclasses.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_imageclasses.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nibabel/tests/test_imageclasses.py b/nibabel/tests/test_imageclasses.py index 7b3add6cd..90ef966d2 100644 --- a/nibabel/tests/test_imageclasses.py +++ b/nibabel/tests/test_imageclasses.py @@ -6,7 +6,6 @@ import numpy as np import nibabel as nib -from nibabel import imageclasses # noqa: F401 from nibabel.analyze import AnalyzeImage from nibabel.imageclasses import spatial_axes_first from nibabel.nifti1 import Nifti1Image From 72c0ebf96f2081eee22bab5b167e12306a4693a3 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:57:41 +0100 Subject: [PATCH 29/32] Update nibabel/tests/test_minc2.py Co-authored-by: Chris Markiewicz --- nibabel/tests/test_minc2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/tests/test_minc2.py b/nibabel/tests/test_minc2.py index 7ab29edfd..4c2973a72 100644 --- a/nibabel/tests/test_minc2.py +++ b/nibabel/tests/test_minc2.py @@ -129,5 +129,5 @@ def test_bad_diminfo(): # File has a bad spacing field 'xspace' when it should be # `irregular`, `regular__` or absent (default to regular__). # We interpret an invalid spacing as absent, but warn. - with pytest.warns(UserWarning) as _: + with pytest.warns(UserWarning): Minc2Image.from_filename(fname) From 223fdc072ee22034c5388a824e350aafb5c8914a Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:05:08 +0100 Subject: [PATCH 30/32] Put back argument, used by @pytest.fixture --- nibabel/tests/test_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/tests/test_data.py b/nibabel/tests/test_data.py index cca8d0ba8..5697752ea 100644 --- a/nibabel/tests/test_data.py +++ b/nibabel/tests/test_data.py @@ -27,7 +27,7 @@ @pytest.fixture -def with_nimd_env(request): +def with_nimd_env(request, with_environment): # noqa: F811 DATA_FUNCS = {} DATA_FUNCS['home_dir_func'] = nibd.get_nipy_user_dir DATA_FUNCS['sys_dir_func'] = nibd.get_nipy_system_dir From 19e4a56f8e4d4f6e6e5460f08389c2ced5e44c16 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:08:24 +0100 Subject: [PATCH 31/32] MNT: ignore F401 in doc/source/conf.py Enforce that in pyproject.toml instead of conf.py itself. --- doc/source/conf.py | 4 ++-- pyproject.toml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index e8999b7d2..175c6340b 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -30,11 +30,11 @@ # Check for external Sphinx extensions we depend on try: - import numpydoc # noqa: F401 + import numpydoc except ImportError: raise RuntimeError('Need to install "numpydoc" package for doc build') try: - import texext # noqa: F401 + import texext except ImportError: raise RuntimeError('Need to install "texext" package for doc build') diff --git a/pyproject.toml b/pyproject.toml index 5df6d0189..bf7b09903 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -135,6 +135,7 @@ ignore = [ [tool.ruff.lint.per-file-ignores] "__init__.py" = ["F401"] +"doc/source/conf.py" = ["F401"] [tool.ruff.format] quote-style = "single" From 066431d9bf5b6843514528ff5a6d81fbef4f8e9d Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:10:55 +0100 Subject: [PATCH 32/32] MNT: Get rid of last `coding: utf-8` --- doc/source/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/conf.py b/doc/source/conf.py index 175c6340b..f4ab16d2d 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- # vi: set ft=python sts=4 ts=4 sw=4 et: ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##