Skip to content
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

[MAINT] run isort and flake8 on the whole nilearn code base in CI #3651

Merged
merged 22 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
exclude =
.git,
__pycache__,
env,
venv,
auto_examples,
build,
dist,
env,
nilearn/externals/tempita
nilearn/externals/
nilearn_cache
venv,
--select = D,E,F,W,C90
docstring-convention = numpy
max-line-length = 79
Expand Down
19 changes: 1 addition & 18 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,4 @@ jobs:

- name: "Run Flake8 on whole file"
shell: bash {0}
run: |
flake8 --verbose \
examples/0[0234567]* \
maint_tools \
nilearn/_utils \
nilearn/connectome \
nilearn/datasets \
nilearn/de* \
nilearn/glm \
nilearn/image \
nilearn/interfaces \
nilearn/input_data \
nilearn/maskers \
nilearn/mass_univariate \
nilearn/regions \
nilearn/reporting \
nilearn/surface \
nilearn/*.py
run: flake8 --verbose .
20 changes: 3 additions & 17 deletions .github/workflows/isort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,8 @@ jobs:
python -m pip install --upgrade pip isort

- name: "Run isort"
run: |
isort --diff --check --settings-path pyproject.toml \
run: isort --diff --check --settings-path pyproject.toml \
examples/0[0234567]* \
maint_tools \
nilearn/_utils \
nilearn/connectome \
nilearn/datasets \
nilearn/de* \
nilearn/glm \
nilearn/image \
nilearn/interfaces \
nilearn/input_data \
nilearn/maskers \
nilearn/mass_univariate \
nilearn/plotting \
nilearn/regions \
nilearn/rerporting \
nilearn/surface \
nilearn/*.py
nilearn \
doc
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys

import sphinx

from nilearn._utils import _compare_version

# ----------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions nilearn/_utils/data_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import scipy.linalg
import scipy.signal
from nibabel import Nifti1Image
from scipy.ndimage import binary_dilation
from sklearn.utils import check_random_state

from nilearn import datasets, image, maskers, masking
from nilearn._utils import as_ndarray, logger
from nilearn.interfaces.bids._utils import _bids_entities, _check_bids_label
from scipy.ndimage import binary_dilation
from sklearn.utils import check_random_state


def generate_mni_space_img(n_scans=1, res=30, random_state=0, mask_dilation=2):
Expand Down
3 changes: 2 additions & 1 deletion nilearn/_utils/niimg_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
# License: simplified BSD
import warnings

import nilearn as ni
import numpy as np
from joblib import Memory

import nilearn as ni

from .cache_mixin import cache
from .exceptions import DimensionError
from .helpers import stringify_path
Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import pytest
import sklearn

from nilearn._utils import _compare_version

# we use memory_profiler library for memory consumption checks
Expand Down
3 changes: 2 additions & 1 deletion nilearn/_utils/tests/test_cache_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import shutil
from pathlib import Path

import nilearn
import pytest
from joblib import Memory

import nilearn
from nilearn._utils import CacheMixin, cache_mixin


Expand Down
3 changes: 2 additions & 1 deletion nilearn/_utils/tests/test_class_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
which we historically used,
ignores modules whose name starts with an underscore.
"""
from nilearn._utils import class_inspect
from sklearn.base import BaseEstimator

from nilearn._utils import class_inspect

##############################################################################
# Helpers for the tests

Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/tests/test_data_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import pytest

from nilearn._utils.data_gen import (
_add_metadata_to_bids_dataset,
create_fake_bids_dataset,
Expand Down
3 changes: 2 additions & 1 deletion nilearn/_utils/tests/test_extmath.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Test the _utils.extmath module."""
import numpy as np
from nilearn._utils.extmath import fast_abs_percentile, is_spd
from sklearn.utils import check_random_state

from nilearn._utils.extmath import fast_abs_percentile, is_spd


def test_fast_abs_percentile():
rng = check_random_state(1)
Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings

import pytest

from nilearn._utils import helpers


Expand Down
3 changes: 2 additions & 1 deletion nilearn/_utils/tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"""
import contextlib

from nilearn._utils.logger import log
from sklearn.base import BaseEstimator

from nilearn._utils.logger import log


@contextlib.contextmanager
def capture_output():
Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/tests/test_ndimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import numpy as np
import pytest

from nilearn._utils import data_gen
from nilearn._utils.ndimage import _peak_local_max, largest_connected_component

Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/tests/test_niimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from nibabel import Nifti1Header, Nifti1Image
from nibabel.tmpdirs import InTemporaryDirectory

from nilearn._utils import load_niimg, niimg, testing
from nilearn.image import get_data, new_img_like

Expand Down
5 changes: 3 additions & 2 deletions nilearn/_utils/tests/test_niimg_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
from pathlib import Path

import nibabel
import nilearn as ni
import numpy as np
import pytest
from nibabel import Nifti1Image
from numpy.testing import assert_array_almost_equal, assert_array_equal

import nilearn as ni
from nilearn import _utils, image
from nilearn._utils import niimg_conversions, testing
from nilearn._utils.exceptions import DimensionError
Expand All @@ -27,7 +29,6 @@
with_memory_profiler,
)
from nilearn.image import get_data
from numpy.testing import assert_array_almost_equal, assert_array_equal


class PhonyNiimage(nibabel.spatialimages.SpatialImage):
Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/tests/test_numpy_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
import pytest

from nilearn._utils.numpy_conversions import as_ndarray, csv_to_array


Expand Down
3 changes: 2 additions & 1 deletion nilearn/_utils/tests/test_param_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import nibabel
import numpy as np
import pytest
from sklearn.base import BaseEstimator

from nilearn._utils.extmath import fast_abs_percentile
from nilearn._utils.param_validation import (
MNI152_BRAIN_VOLUME,
_get_mask_volume,
check_feature_screening,
check_threshold,
)
from sklearn.base import BaseEstimator

mni152_brain_mask = (
"/usr/share/fsl/data/standard/MNI152_T1_1mm_brain_mask.nii.gz"
Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/tests/test_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np
import pytest

from nilearn._utils.segmentation import _random_walker


Expand Down
1 change: 1 addition & 0 deletions nilearn/_utils/tests/test_testing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import nibabel
import numpy as np
import pytest

from nilearn._utils.testing import (
assert_memory_less_than,
with_memory_profiler,
Expand Down
1 change: 1 addition & 0 deletions nilearn/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import pytest
from nibabel import Nifti1Image

from nilearn import image

# we need to import these fixtures even if not used in this module
Expand Down
11 changes: 6 additions & 5 deletions nilearn/connectome/tests/test_connectivity_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

import numpy as np
import pytest
from numpy.testing import assert_array_almost_equal, assert_array_equal
from pandas import DataFrame
from scipy import linalg
from sklearn.covariance import EmpiricalCovariance, LedoitWolf
from sklearn.utils import check_random_state

from nilearn._utils.extmath import is_spd
from nilearn.connectome.connectivity_matrices import (
ConnectivityMeasure,
Expand All @@ -17,11 +23,6 @@
vec_to_sym_matrix,
)
from nilearn.tests.test_signal import generate_signals
from numpy.testing import assert_array_almost_equal, assert_array_equal
from pandas import DataFrame
from scipy import linalg
from sklearn.covariance import EmpiricalCovariance, LedoitWolf
from sklearn.utils import check_random_state

CONNECTIVITY_KINDS = (
"covariance",
Expand Down
1 change: 1 addition & 0 deletions nilearn/connectome/tests/test_group_sparse_cov.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pytest

from nilearn._utils.data_gen import generate_group_sparse_gaussian_graphs
from nilearn.connectome import GroupSparseCovariance, GroupSparseCovarianceCV
from nilearn.connectome.group_sparse_cov import (
Expand Down
3 changes: 2 additions & 1 deletion nilearn/datasets/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
from unittest.mock import MagicMock

import pytest
from nilearn._utils.testing import serialize_niimg
from requests.exceptions import HTTPError

from nilearn._utils.testing import serialize_niimg


@pytest.fixture(autouse=True)
def temp_nilearn_data_dir(tmp_path_factory, monkeypatch):
Expand Down
1 change: 1 addition & 0 deletions nilearn/datasets/data/convert_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import matplotlib.pyplot as plt
import numpy as np

from nilearn.image import get_data, load_img, new_img_like
from nilearn.masking import apply_mask, unmask
from nilearn.plotting import plot_img
Expand Down
3 changes: 2 additions & 1 deletion nilearn/datasets/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
except ImportError: # SciPy < 1.8
from scipy.io.matlab.miobase import MatReadError

from nilearn.image import get_data
from sklearn.utils import Bunch

from nilearn.image import get_data

from .._utils import check_niimg, fill_doc
from .._utils.numpy_conversions import csv_to_array
from .utils import (
Expand Down
3 changes: 2 additions & 1 deletion nilearn/datasets/tests/test_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
import numpy as np
import pandas as pd
import pytest
from numpy.testing import assert_array_equal

from nilearn._utils import data_gen
from nilearn._utils.testing import serialize_niimg
from nilearn.datasets import atlas, utils
from nilearn.datasets._testing import dict_to_archive
from nilearn.image import get_data
from numpy.testing import assert_array_equal


def test_get_dataset_dir(tmp_path):
Expand Down
3 changes: 2 additions & 1 deletion nilearn/datasets/tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
import numpy as np
import pandas as pd
import pytest
from sklearn.utils import check_random_state

from nilearn.datasets import func
from nilearn.datasets._testing import dict_to_archive, list_to_archive
from nilearn.datasets.utils import _get_dataset_dir
from sklearn.utils import check_random_state


def _load_localizer_index():
Expand Down
1 change: 1 addition & 0 deletions nilearn/datasets/tests/test_neurovault.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pandas as pd
import pytest
import requests

from nilearn._utils.data_gen import generate_fake_fmri
from nilearn.datasets import neurovault
from nilearn.image import load_img
Expand Down
1 change: 1 addition & 0 deletions nilearn/datasets/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np
import pandas as pd
import pytest

from nilearn.datasets import struct, utils
from nilearn.datasets._testing import dict_to_archive, list_to_archive

Expand Down
1 change: 1 addition & 0 deletions nilearn/datasets/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
import requests

from nilearn import image
from nilearn._utils.data_gen import generate_fake_fmri
from nilearn.datasets import _testing
Expand Down
1 change: 1 addition & 0 deletions nilearn/datasets/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import numpy as np
import pytest
import requests

from nilearn import datasets
from nilearn.datasets import utils
from nilearn.datasets.utils import _get_dataset_descr
Expand Down