8000 MNT: blue/isort/flake8 → ruff by DimitriPapadopoulos · Pull Request #1289 · nipy/nibabel · GitHub
[go: up one dir, main page]

Skip to content

MNT: blue/isort/flake8 → ruff #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
733c0f3
MNT: blue/isort/flake8 → ruff
DimitriPapadopoulos Dec 26, 2023
39429f9
MNT: run `ruff --fix` and `ruf format`
DimitriPapadopoulos Dec 26, 2023
04dd1f4
MNT: ruff 0.1.9 → 0.3.0
DimitriPapadopoulos Mar 5, 2024
3ee9480
MNT: run `ruff check --fix` and `ruff format`
DimitriPapadopoulos Mar 5, 2024
a6f2a61
MNT: get rid of .flake8/.pep8speaks.yml
DimitriPapadopoulos Mar 27, 2024
ac29ed2
MNT: ignore F401 in __init__.py
DimitriPapadopoulos Mar 27, 2024
d3352ae
MNT: ruff 0.3.0 → 0.3.4
DimitriPapadopoulos Mar 27, 2024
f57f5cb
Update doc/tools/apigen.py
DimitriPapadopoulos Mar 27, 2024
1684a9d
Update nibabel/cifti2/tests/test_cifti2io_header.py
DimitriPapadopoulos Mar 27, 2024
a8ba819
Update nibabel/gifti/tests/test_gifti.py
DimitriPapadopoulos Mar 27, 2024
d797ffe
Update nibabel/tests/test_pkg_info.py
DimitriPapadopoulos Mar 27, 2024
59d6291
Update nibabel/gifti/tests/test_gifti.py
DimitriPapadopoulos Mar 27, 2024
6daadc8
Update nibabel/tests/test_spatialimages.py
DimitriPapadopoulos Mar 27, 2024 8000
32d0109
Update nibabel/tests/test_testing.py
DimitriPapadopoulos Mar 27, 2024
9104d2f
Update tox.ini
DimitriPapadopoulos Mar 27, 2024
02918ed
Update nibabel/tests/test_testing.py
DimitriPapadopoulos Mar 27, 2024
eeab46f
Update nibabel/gifti/tests/test_gifti.py
DimitriPapadopoulos Mar 29, 2024
46c8487
Update nibabel/gifti/tests/test_gifti.py
DimitriPapadopoulos Mar 29, 2024
dec3a2d
Update nibabel/gifti/tests/test_parse_gifti_fast.py
DimitriPapadopoulos Mar 29, 2024
d8d3a44
Update nibabel/gifti/tests/test_parse_gifti_fast.py
DimitriPapadopoulos Mar 29, 2024
de9f2b0
Update nibabel/nicom/tests/test_dicomwrappers.py
DimitriPapadopoulos Mar 29, 2024
b7a5f5a
Update nibabel/streamlines/tests/test_tck.py
DimitriPapadopoulos Mar 29, 2024
a621d41
Update nibabel/streamlines/tests/test_trk.py
DimitriPapadopoulos Mar 29, 2024
37ff0eb
Update nibabel/tests/test_affines.py
DimitriPapadopoulos Mar 29, 2024
36d36fb
Update nibabel/tests/test_arraywriters.py
DimitriPapadopoulos Mar 29, 2024
0922369
Update nibabel/tests/test_arraywriters.py
DimitriPapadopoulos Mar 29, 2024
50177cc
Update nibabel/tests/test_image_load_save.py
DimitriPapadopoulos Mar 29, 2024
489b9d2
Update nibabel/tests/test_imageclasses.py
DimitriPapadopoulos Mar 29, 2024
72c0ebf
Update nibabel/tests/test_minc2.py
DimitriPapadopoulos Mar 29, 2024
223fdc0
Put back argument, used by @pytest.fixture
DimitriPapadopoulos Mar 29, 2024
19e4a56
MNT: ignore F401 in doc/source/conf.py
DimitriPapadopoulos Mar 29, 2024
066431d
MNT: Get rid of last `coding: utf-8`
DimitriPapadopoulos Mar 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .flake8

This file was deleted.

12 changes: 0 additions & 12 deletions .pep8speaks.yml

This file was deleted.

19 changes: 7 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.4
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:
Expand Down
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -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:
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
Expand Down
5 changes: 1 addition & 4 deletions doc/tools/apigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,7 @@ 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
]
ulms = ['.'.join(m.split('.')[:2]) for m in modules]

from collections import OrderedDict

Expand Down
2 changes: 1 addition & 1 deletion doc/tools/build_modref_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions nibabel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,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

Expand Down
1 change: 1 addition & 0 deletions nibabel/_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Constants and types for dealing transparently with compression"""

from __future__ import annotations

import bz2
Expand Down
1 change: 1 addition & 0 deletions nibabel/affines.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions nibabel/arrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

See :mod:`nibabel.tests.test_proxy_api` for proxy API conformance checks.
"""

from __future__ import annotations

import typing as ty
Expand Down Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions nibabel/arraywriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions nibabel/benchmarks/bench_arrayproxy_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@


def bench_arrayproxy_slicing():

print_git_title('\nArrayProxy gzip slicing')

# each test is a tuple containing
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 1 addition & 2 deletions nibabel/benchmarks/butils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Benchmarking utilities
"""
"""Benchmarking utilities"""

from .. import get_info

Expand Down
1 change: 1 addition & 0 deletions nibabel/brikhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions nibabel/cifti2/cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

http://www.nitrc.org/projects/cifti
"""

import re
from collections import OrderedDict
from collections.abc import Iterable, MutableMapping, MutableSequence
Expand Down
1 change: 1 addition & 0 deletions nibabel/cifti2/cifti2_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
... bm_cortex)))
<class 'nibabel.cifti2.cifti2.Cifti2Header'>
"""

import abc
from operator import xor

Expand Down
6 changes: 3 additions & 3 deletions nibabel/cifti2/tests/test_cifti2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Testing CIFTI-2 objects
"""
"""Testing CIFTI-2 objects"""

import collections
from xml.etree import ElementTree

import numpy as np
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
Expand Down
3 changes: 1 addition & 2 deletions nibabel/cifti2/tests/test_cifti2io_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##

import io
from os.path import dirname
from os.path import join as pjoin

Expand Down Expand Up @@ -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():
Expand Down
1 change: 1 addition & 0 deletions nibabel/cifti2/tests/test_new_cifti2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions nibabel/cmdline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
# copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Functionality to be exposed in the command line
"""
"""Functionality to be exposed in the command line"""
9 changes: 3 additions & 6 deletions nibabel/cmdline/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -247,15 +246,14 @@ 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

if np.any(candidates):

diff_rec = OrderedDict() # so that abs goes before relative

diff_rec['abs'] = max_abs_diff.astype(dtype)
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions nibabel/cmdline/parrec2nii.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Code for PAR/REC to NIfTI converter command
"""
"""Code for PAR/REC to NIfTI converter command"""

import csv
import os
Expand Down
1 change: 1 addition & 0 deletions nibabel/cmdline/tck2trk.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Convert tractograms (TCK -> TRK).
"""

import argparse
import os

Expand Down
2 changes: 1 addition & 1 deletion nibabel/cmdline/tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions nibabel/cmdline/tests/test_parrec2nii.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 1 addition & 2 deletions nibabel/cmdline/tests/test_roi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import unittest
from unittest import mock

import numpy as np
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions nibabel/cmdline/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##

import sys
from io import StringIO

import numpy as np

from nibabel import Nifti1Image
Expand Down
14 changes: 12 additions & 2 deletions nibabel/cmdline/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 0 additions & 1 deletion nibabel/cmdline/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
Helper utilities to be used in cmdline applications
"""


# global verbosity switch
import re
from io import StringIO
Expand Down
2 changes: 1 addition & 1 deletion nibabel/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
0