Skip to content

Commit

Permalink
More ruff (isort) (#497)
Browse files Browse the repository at this point in the history
* more ruff

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add preferred config

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ben Dichter <[email protected]>
  • Loading branch information
3 people authored Aug 31, 2024
1 parent adf6fe3 commit 67dca89
Show file tree
Hide file tree
Showing 46 changed files with 224 additions and 220 deletions.
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extend-exclude = '''
exclude = ["docs/*"]

[tool.ruff.lint]
select = ["F401", "I002"] # TODO: eventually, expand to other 'I', 'D', and other 'F' linting
select = ["F401", "I"] # TODO: eventually, expand to other 'D', and other 'F' linting
fixable = ["ALL"]

[tool.ruff.lint.per-file-ignores]
Expand All @@ -41,6 +41,11 @@ fixable = ["ALL"]
"src/nwbinspector/version/__init__.py" = ["F401", "I"]
"src/nwbinspector/register_checks/__init__.py" = ["F401", "I"]

[tool.ruff.lint.isort]
relative-imports-order = "closest-to-furthest"
known-first-party = ["nwbinspector"]



[tool.codespell]
skip = '.git*,*.pdf,*.css'
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from setuptools import setup, find_packages
from pathlib import Path
from shutil import copy

from setuptools import find_packages, setup

root = Path(__file__).parent
with open(root / "README.md", "r") as f:
long_description = f.read()
Expand Down
9 changes: 5 additions & 4 deletions src/nwbinspector/_configuration.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"""Primary functions for inspecting NWBFiles."""

import json
import jsonschema
from pathlib import Path
from typing import Optional, List
from types import FunctionType
from typing import List, Optional

import jsonschema
import yaml

from . import available_checks
from ._registration import Importance
from nwbinspector.utils._utils import (
PathType,
)

from . import available_checks
from ._registration import Importance

INTERNAL_CONFIGS = dict(dandi=Path(__file__).parent / "internal_configs" / "dandi.inspector_config.yaml")


Expand Down
14 changes: 7 additions & 7 deletions src/nwbinspector/_formatting.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""Internally used tools specifically for rendering more human-readable output from collected check results."""

import os
import json
import os
import sys
from typing import Dict, List, Optional, Union
from pathlib import Path
from enum import Enum
from collections import defaultdict
from datetime import datetime
from enum import Enum
from pathlib import Path
from platform import platform
from collections import defaultdict
from typing import Dict, List, Optional, Union

import numpy as np

from ._types import InspectorMessage, Importance
from ._organization import organize_messages
from .utils import get_package_version, FilePathType
from ._types import Importance, InspectorMessage
from .utils import FilePathType, get_package_version


class InspectorOutputJSONEncoder(json.JSONEncoder):
Expand Down
18 changes: 9 additions & 9 deletions src/nwbinspector/_inspection.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
"""Primary functions for inspecting NWBFiles."""

import re
import importlib
import re
import traceback
from pathlib import Path
from typing import Union, Optional, List, Iterable
from collections import defaultdict
from concurrent.futures import ProcessPoolExecutor, as_completed
from pathlib import Path
from typing import Iterable, List, Optional, Union
from warnings import filterwarnings, warn
from collections import defaultdict
from packaging.version import Version

import pynwb
from tqdm import tqdm
from natsort import natsorted
from packaging.version import Version
from tqdm import tqdm

from . import available_checks, configure_checks
from ._registration import InspectorMessage, Importance
from ._registration import Importance, InspectorMessage
from .tools import get_s3_urls_and_dandi_paths
from .utils import (
FilePathType,
PathType,
OptionalListOfStrings,
robust_s3_read,
PathType,
calculate_number_of_cpu,
get_package_version,
robust_s3_read,
)


Expand Down
14 changes: 11 additions & 3 deletions src/nwbinspector/_inspection_cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
"""Primary functions for inspecting NWBFiles."""

import json
import os
import re
import json
from pathlib import Path
from typing import Optional
from warnings import warn

import click

from ._formatting import _get_report_header, InspectorOutputJSONEncoder
from . import Importance, inspect_all, format_messages, print_to_console, save_report, __version__, load_config
from . import (
Importance,
__version__,
format_messages,
inspect_all,
load_config,
print_to_console,
save_report,
)
from ._formatting import InspectorOutputJSONEncoder, _get_report_header
from .utils import strtobool


Expand Down
2 changes: 1 addition & 1 deletion src/nwbinspector/_organization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Internally used tools specifically for rendering more human-readable output from collected check results."""

from typing import List, Optional
from enum import Enum
from typing import List, Optional

from natsort import natsorted

Expand Down
5 changes: 2 additions & 3 deletions src/nwbinspector/_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

import h5py
from pynwb import NWBFile
from pynwb.file import Subject
from pynwb.ecephys import Device, ElectrodeGroup
from pynwb.file import Subject

from ._types import Importance, Severity, InspectorMessage

from ._types import Importance, InspectorMessage, Severity

available_checks = list()

Expand Down
2 changes: 1 addition & 1 deletion src/nwbinspector/_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Primary decorator used on a check function to add it to the registry and automatically parse its output."""

from enum import Enum
from dataclasses import dataclass
from enum import Enum
from typing import Optional


Expand Down
68 changes: 34 additions & 34 deletions src/nwbinspector/checks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
from ._behavior import (
check_compass_direction_unit,
check_spatial_series_degrees_magnitude,
check_spatial_series_dims,
check_spatial_series_radians_magnitude,
)
from ._ecephys import (
check_negative_spike_times,
check_electrical_series_dims,
check_electrical_series_reference_electrodes_table,
check_negative_spike_times,
check_spike_times_not_in_unobserved_interval,
)
from ._general import (
check_description,
check_name_slashes,
)
from ._icephys import (
check_intracellular_electrode_cell_id_exists,
)
from ._image_series import (
check_image_series_data_size,
check_image_series_external_file_relative,
check_image_series_external_file_valid,
)
from ._images import (
check_order_of_images_unique,
check_order_of_images_len,
check_index_series_points_to_image,
check_order_of_images_len,
check_order_of_images_unique,
)
from ._nwb_containers import (
check_empty_string_for_optional_attribute,
check_small_dataset_compression,
check_large_dataset_compression,
check_small_dataset_compression,
)
from ._nwbfile_metadata import (
check_keywords,
check_doi_publications,
check_experiment_description,
check_experimenter_exists,
check_experimenter_form,
check_institution,
check_keywords,
check_processing_module_name,
check_session_start_time_future_date,
check_session_start_time_old_date,
check_subject_age,
check_subject_sex,
check_subject_exists,
check_doi_publications,
check_experimenter_form,
check_experimenter_exists,
check_experiment_description,
check_subject_id_exists,
check_subject_proper_age_range,
check_subject_sex,
check_subject_species_exists,
check_subject_species_form,
check_subject_proper_age_range,
check_session_start_time_future_date,
check_processing_module_name,
check_session_start_time_old_date,
)
from ._ogen import (
check_optogenetic_stimulus_site_has_optogenetic_series,
)
from ._ophys import (
check_emission_lambda_in_nm,
check_excitation_lambda_in_nm,
check_plane_segmentation_image_mask_shape_against_ref_images,
check_roi_response_series_dims,
check_emission_lambda_in_nm,
check_roi_response_series_link_to_plane_segmentation,
)
from ._tables import (
check_single_row,
check_ids_unique,
check_empty_table,
check_col_not_nan,
check_column_binary_capability,
check_dynamic_table_region_data_validity,
check_empty_table,
check_ids_unique,
check_single_row,
check_table_time_columns_are_not_negative,
check_table_values_for_dict,
check_time_interval_time_columns,
check_time_intervals_stop_after_start,
check_table_values_for_dict,
check_table_time_columns_are_not_negative,
)
from ._time_series import (
check_resolution,
check_data_orientation,
check_missing_unit,
check_rate_is_not_zero,
check_regular_timestamps,
check_resolution,
check_timestamp_of_the_first_sample_is_not_negative,
check_timestamps_ascending,
check_data_orientation,
check_timestamps_without_nans,
check_timestamps_match_first_dimension,
check_timestamp_of_the_first_sample_is_not_negative,
check_rate_is_not_zero,
)
from ._icephys import (
check_intracellular_electrode_cell_id_exists,
)
from ._behavior import (
check_compass_direction_unit,
check_spatial_series_radians_magnitude,
check_spatial_series_dims,
check_spatial_series_degrees_magnitude,
check_timestamps_without_nans,
)

__all__ = [
Expand Down
4 changes: 2 additions & 2 deletions src/nwbinspector/checks/_behavior.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Checks for types belonging to the pynwb.behavior module."""

import numpy as np
from pynwb.behavior import SpatialSeries, CompassDirection
from pynwb.behavior import CompassDirection, SpatialSeries

from .._registration import register_check, Importance, InspectorMessage
from .._registration import Importance, InspectorMessage, register_check


@register_check(importance=Importance.CRITICAL, neurodata_type=SpatialSeries)
Expand Down
5 changes: 2 additions & 3 deletions src/nwbinspector/checks/_ecephys.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Check functions specific to extracellular electrophysiology neurodata types."""

import numpy as np

from pynwb.misc import Units
from pynwb.ecephys import ElectricalSeries
from pynwb.misc import Units

from .._registration import Importance, InspectorMessage, register_check
from ..utils import get_data_shape
from .._registration import register_check, Importance, InspectorMessage


@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=Units)
Expand Down
2 changes: 1 addition & 1 deletion src/nwbinspector/checks/_general.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Check functions that examine any general neurodata_type with the available attributes."""

from .._registration import register_check, InspectorMessage, Importance
from .._registration import Importance, InspectorMessage, register_check

COMMON_DESCRIPTION_PLACEHOLDERS = ["no description", "no desc", "none", "placeholder"]

Expand Down
2 changes: 1 addition & 1 deletion src/nwbinspector/checks/_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pynwb.icephys import IntracellularElectrode

from .._registration import register_check, Importance, InspectorMessage
from .._registration import Importance, InspectorMessage, register_check


@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=IntracellularElectrode)
Expand Down
2 changes: 1 addition & 1 deletion src/nwbinspector/checks/_image_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pynwb.image import ImageSeries
from pynwb.ophys import TwoPhotonSeries

from .._registration import register_check, Importance, InspectorMessage
from .._registration import Importance, InspectorMessage, register_check
from ..tools import get_nwbfile_path_from_internal_object


Expand Down
3 changes: 1 addition & 2 deletions src/nwbinspector/checks/_images.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Checks specific to the Images neurodata type."""

from packaging.version import Version

from pynwb.image import IndexSeries

from .._registration import register_check, Importance, InspectorMessage
from .._registration import Importance, InspectorMessage, register_check
from ..utils import get_package_version

# The Images neurodata type was unavailable prior to PyNWB v.2.1.0
Expand Down
3 changes: 1 addition & 2 deletions src/nwbinspector/checks/_nwb_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import h5py
from pynwb import NWBContainer


from .._registration import register_check, Importance, InspectorMessage, Severity
from .._registration import Importance, InspectorMessage, Severity, register_check


@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=NWBContainer)
Expand Down
Loading

0 comments on commit 67dca89

Please sign in to comment.