From ead8894ffd47b7070bd8bd0166effeabedb66140 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Mon, 5 Feb 2024 17:55:28 +0100 Subject: [PATCH] [STY] use isort (#191) * use isort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 8 ++++---- bidsmreye/bids_utils.py | 15 ++++++++------- bidsmreye/bidsmreye.py | 15 ++++++++------- bidsmreye/configuration.py | 5 +---- bidsmreye/download.py | 6 ++---- bidsmreye/generalize.py | 28 +++++++++++++++------------- bidsmreye/methods.py | 3 +-- bidsmreye/prepare_data.py | 24 ++++++++++++++---------- bidsmreye/quality_control.py | 16 ++++++++-------- bidsmreye/visualize.py | 7 ++----- tests/test_bids_utils.py | 15 +++++++++------ tests/test_configuration.py | 13 ++++++++----- tests/test_download.py | 3 +-- tests/test_quality_control.py | 32 ++++++++++++++++++-------------- tests/test_utils.py | 15 +++++++++------ tests/test_visualize.py | 7 +++---- tests/utils.py | 3 +-- 17 files changed, 112 insertions(+), 103 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4dc7d35..fde05e2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,11 +31,11 @@ repos: hooks: - id: flynt -- repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.0 +- repo: https://github.com/pycqa/isort + rev: 5.13.2 hooks: - - id: reorder-python-imports - args: [--py37-plus, --add-import, from __future__ import annotations] + - id: isort + args: [--profile, black] - repo: https://github.com/psf/black rev: 24.1.1 diff --git a/bidsmreye/bids_utils.py b/bidsmreye/bids_utils.py index b422026..0fb158b 100644 --- a/bidsmreye/bids_utils.py +++ b/bidsmreye/bids_utils.py @@ -8,15 +8,16 @@ from bids import BIDSLayout # type: ignore from bidsmreye._version import __version__ -from bidsmreye.configuration import Config -from bidsmreye.configuration import config_to_dict -from bidsmreye.configuration import get_bids_filter_config -from bidsmreye.configuration import get_bidsname_config -from bidsmreye.configuration import get_pybids_config +from bidsmreye.configuration import ( + Config, + config_to_dict, + get_bids_filter_config, + get_bidsname_config, + get_pybids_config, +) from bidsmreye.logging import bidsmreye_log from bidsmreye.methods import methods -from bidsmreye.utils import copy_license -from bidsmreye.utils import create_dir_if_absent +from bidsmreye.utils import copy_license, create_dir_if_absent log = bidsmreye_log("bidsmreye") diff --git a/bidsmreye/bidsmreye.py b/bidsmreye/bidsmreye.py index 1b0fd99..6610cea 100755 --- a/bidsmreye/bidsmreye.py +++ b/bidsmreye/bidsmreye.py @@ -6,18 +6,19 @@ import json import sys from pathlib import Path -from typing import Any -from typing import IO +from typing import IO, Any import rich from bidsmreye._version import __version__ from bidsmreye.configuration import Config -from bidsmreye.defaults import allowed_actions -from bidsmreye.defaults import available_models -from bidsmreye.defaults import default_log_level -from bidsmreye.defaults import default_model -from bidsmreye.defaults import log_levels +from bidsmreye.defaults import ( + allowed_actions, + available_models, + default_log_level, + default_model, + log_levels, +) from bidsmreye.download import download from bidsmreye.generalize import generalize from bidsmreye.logging import bidsmreye_log diff --git a/bidsmreye/configuration.py b/bidsmreye/configuration.py index 2ffcd0e..bc4dead 100644 --- a/bidsmreye/configuration.py +++ b/bidsmreye/configuration.py @@ -6,10 +6,7 @@ from pathlib import Path from typing import Any -from attrs import asdict -from attrs import converters -from attrs import define -from attrs import field +from attrs import asdict, converters, define, field from bids import BIDSLayout # type: ignore from bidsmreye.logging import bidsmreye_log diff --git a/bidsmreye/download.py b/bidsmreye/download.py index ab4ec93..31ad572 100644 --- a/bidsmreye/download.py +++ b/bidsmreye/download.py @@ -6,15 +6,13 @@ import sys import warnings from pathlib import Path -from typing import Any -from typing import IO +from typing import IO, Any import pkg_resources import pooch import rich -from bidsmreye.defaults import available_models -from bidsmreye.defaults import default_model +from bidsmreye.defaults import available_models, default_model from bidsmreye.logging import bidsmreye_log log = bidsmreye_log(name="bidsmreye") diff --git a/bidsmreye/generalize.py b/bidsmreye/generalize.py index 5998bba..dfe52bb 100644 --- a/bidsmreye/generalize.py +++ b/bidsmreye/generalize.py @@ -11,24 +11,26 @@ import numpy as np import pandas as pd from bids import BIDSLayout # type: ignore -from deepmreye import analyse -from deepmreye import train -from deepmreye.util import data_generator -from deepmreye.util import model_opts +from deepmreye import analyse, train +from deepmreye.util import data_generator, model_opts from rich import print -from bidsmreye.bids_utils import check_layout -from bidsmreye.bids_utils import create_bidsname -from bidsmreye.bids_utils import get_dataset_layout -from bidsmreye.bids_utils import list_subjects +from bidsmreye.bids_utils import ( + check_layout, + create_bidsname, + get_dataset_layout, + list_subjects, +) from bidsmreye.configuration import Config from bidsmreye.logging import bidsmreye_log from bidsmreye.quality_control import quality_control_output -from bidsmreye.utils import add_sidecar_in_root -from bidsmreye.utils import check_if_file_found -from bidsmreye.utils import create_dir_for_file -from bidsmreye.utils import move_file -from bidsmreye.utils import set_this_filter +from bidsmreye.utils import ( + add_sidecar_in_root, + check_if_file_found, + create_dir_for_file, + move_file, + set_this_filter, +) log = bidsmreye_log(name="bidsmreye") diff --git a/bidsmreye/methods.py b/bidsmreye/methods.py index 861c5c8..a5a264e 100644 --- a/bidsmreye/methods.py +++ b/bidsmreye/methods.py @@ -9,8 +9,7 @@ import chevron from bidsmreye._version import __version__ -from bidsmreye.defaults import available_models -from bidsmreye.defaults import default_model +from bidsmreye.defaults import available_models, default_model from bidsmreye.utils import create_dir_for_file diff --git a/bidsmreye/prepare_data.py b/bidsmreye/prepare_data.py index 3db27cc..452c54d 100644 --- a/bidsmreye/prepare_data.py +++ b/bidsmreye/prepare_data.py @@ -10,18 +10,22 @@ from bids import BIDSLayout # type: ignore from deepmreye import preprocess -from bidsmreye.bids_utils import check_layout -from bidsmreye.bids_utils import create_bidsname -from bidsmreye.bids_utils import get_dataset_layout -from bidsmreye.bids_utils import init_dataset -from bidsmreye.bids_utils import list_subjects -from bidsmreye.bids_utils import save_sampling_frequency_to_json +from bidsmreye.bids_utils import ( + check_layout, + create_bidsname, + get_dataset_layout, + init_dataset, + list_subjects, + save_sampling_frequency_to_json, +) from bidsmreye.configuration import Config from bidsmreye.logging import bidsmreye_log -from bidsmreye.utils import check_if_file_found -from bidsmreye.utils import get_deepmreye_filename -from bidsmreye.utils import move_file -from bidsmreye.utils import set_this_filter +from bidsmreye.utils import ( + check_if_file_found, + get_deepmreye_filename, + move_file, + set_this_filter, +) log = bidsmreye_log(name="bidsmreye") diff --git a/bidsmreye/quality_control.py b/bidsmreye/quality_control.py index 01f074a..1e810da 100644 --- a/bidsmreye/quality_control.py +++ b/bidsmreye/quality_control.py @@ -12,16 +12,16 @@ from bids import BIDSLayout # type: ignore from scipy.stats.distributions import chi2 -from bidsmreye.bids_utils import check_layout -from bidsmreye.bids_utils import create_bidsname -from bidsmreye.bids_utils import get_dataset_layout -from bidsmreye.bids_utils import init_dataset -from bidsmreye.bids_utils import list_subjects +from bidsmreye.bids_utils import ( + check_layout, + create_bidsname, + get_dataset_layout, + init_dataset, + list_subjects, +) from bidsmreye.configuration import Config from bidsmreye.logging import bidsmreye_log -from bidsmreye.utils import check_if_file_found -from bidsmreye.utils import create_dir_for_file -from bidsmreye.utils import set_this_filter +from bidsmreye.utils import check_if_file_found, create_dir_for_file, set_this_filter from bidsmreye.visualize import visualize_eye_gaze_data log = bidsmreye_log("bidsmreye") diff --git a/bidsmreye/visualize.py b/bidsmreye/visualize.py index b6f38e2..cd61000 100644 --- a/bidsmreye/visualize.py +++ b/bidsmreye/visualize.py @@ -11,13 +11,10 @@ from plotly.subplots import make_subplots from bidsmreye._version import __version__ -from bidsmreye.bids_utils import get_dataset_layout -from bidsmreye.bids_utils import list_subjects +from bidsmreye.bids_utils import get_dataset_layout, list_subjects from bidsmreye.configuration import Config from bidsmreye.logging import bidsmreye_log -from bidsmreye.utils import check_if_file_found -from bidsmreye.utils import set_this_filter - +from bidsmreye.utils import check_if_file_found, set_this_filter LINE_WIDTH = 3 FONT_SIZE = dict(size=14) diff --git a/tests/test_bids_utils.py b/tests/test_bids_utils.py index d2fb328..e4b8da5 100644 --- a/tests/test_bids_utils.py +++ b/tests/test_bids_utils.py @@ -4,16 +4,19 @@ import shutil from pathlib import Path -from .utils import pybids_test_dataset -from bidsmreye.bids_utils import check_layout -from bidsmreye.bids_utils import create_bidsname -from bidsmreye.bids_utils import get_dataset_layout -from bidsmreye.bids_utils import init_dataset -from bidsmreye.bids_utils import list_subjects +from bidsmreye.bids_utils import ( + check_layout, + create_bidsname, + get_dataset_layout, + init_dataset, + list_subjects, +) from bidsmreye.configuration import Config from bidsmreye.prepare_data import save_sampling_frequency_to_json from bidsmreye.utils import set_this_filter +from .utils import pybids_test_dataset + def test_create_bidsname(tmp_path): output_dir = tmp_path / "derivatives" diff --git a/tests/test_configuration.py b/tests/test_configuration.py index dca20b4..72b09f7 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -4,12 +4,15 @@ import pytest +from bidsmreye.configuration import ( + Config, + config_to_dict, + get_bidsname_config, + get_config, + get_pybids_config, +) + from .utils import pybids_test_dataset -from bidsmreye.configuration import Config -from bidsmreye.configuration import config_to_dict -from bidsmreye.configuration import get_bidsname_config -from bidsmreye.configuration import get_config -from bidsmreye.configuration import get_pybids_config def test_Config(): diff --git a/tests/test_download.py b/tests/test_download.py index 80db492..574efa7 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -5,8 +5,7 @@ import pytest -from bidsmreye.download import download -from bidsmreye.download import download_parser +from bidsmreye.download import download, download_parser def test_download_parser(): diff --git a/tests/test_quality_control.py b/tests/test_quality_control.py index d74e70f..1063a8d 100644 --- a/tests/test_quality_control.py +++ b/tests/test_quality_control.py @@ -6,21 +6,25 @@ import pandas as pd import pytest -from .utils import create_basic_data -from .utils import create_basic_json -from .utils import create_confounds_tsv -from .utils import return_bidsmreye_eyetrack_tsv -from .utils import rm_dir -from bidsmreye.bids_utils import create_bidsname -from bidsmreye.bids_utils import get_dataset_layout +from bidsmreye.bids_utils import create_bidsname, get_dataset_layout from bidsmreye.configuration import Config -from bidsmreye.quality_control import add_qc_to_sidecar -from bidsmreye.quality_control import compute_displacement_and_outliers -from bidsmreye.quality_control import compute_robust_outliers -from bidsmreye.quality_control import get_sampling_frequency -from bidsmreye.quality_control import perform_quality_control -from bidsmreye.quality_control import quality_control_input -from bidsmreye.quality_control import quality_control_output +from bidsmreye.quality_control import ( + add_qc_to_sidecar, + compute_displacement_and_outliers, + compute_robust_outliers, + get_sampling_frequency, + perform_quality_control, + quality_control_input, + quality_control_output, +) + +from .utils import ( + create_basic_data, + create_basic_json, + create_confounds_tsv, + return_bidsmreye_eyetrack_tsv, + rm_dir, +) def time_series(): diff --git a/tests/test_utils.py b/tests/test_utils.py index d1dde28..bfc357a 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,14 +3,17 @@ import shutil from pathlib import Path -from .utils import pybids_test_dataset from bidsmreye.bids_utils import get_dataset_layout from bidsmreye.configuration import Config -from bidsmreye.utils import copy_license -from bidsmreye.utils import get_deepmreye_filename -from bidsmreye.utils import return_deepmreye_output_filename -from bidsmreye.utils import return_regex -from bidsmreye.utils import set_this_filter +from bidsmreye.utils import ( + copy_license, + get_deepmreye_filename, + return_deepmreye_output_filename, + return_regex, + set_this_filter, +) + +from .utils import pybids_test_dataset def test_copy_license(tmp_path): diff --git a/tests/test_visualize.py b/tests/test_visualize.py index d67ac94..c6d873d 100644 --- a/tests/test_visualize.py +++ b/tests/test_visualize.py @@ -4,12 +4,11 @@ import pandas as pd -from .utils import create_confounds_tsv -from .utils import return_bidsmreye_eyetrack_tsv from bidsmreye.bidsmreye import bidsmreye from bidsmreye.configuration import Config -from bidsmreye.visualize import group_report -from bidsmreye.visualize import visualize_eye_gaze_data +from bidsmreye.visualize import group_report, visualize_eye_gaze_data + +from .utils import create_confounds_tsv, return_bidsmreye_eyetrack_tsv def test_visualize_eye_gaze_data(): diff --git a/tests/utils.py b/tests/utils.py index e95e88d..6cf5db1 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -8,8 +8,7 @@ import pandas as pd from bids.tests import get_test_data_path -from bidsmreye.quality_control import compute_displacement -from bidsmreye.quality_control import compute_robust_outliers +from bidsmreye.quality_control import compute_displacement, compute_robust_outliers def create_basic_data():