Skip to content

Commit

Permalink
Remove 3.8; updating annotation typing (#508)
Browse files Browse the repository at this point in the history
* remove 3.8; update typing

* changelog

* fix

* more fixes

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

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

* forgot about this one

* remove 3.8 from template, workflow, docs

---------

Co-authored-by: CodyCBakerPhD <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steph Prince <[email protected]>
  • Loading branch information
4 people committed Sep 16, 2024
1 parent 7c92e82 commit 4856bd6
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 83 deletions.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ body:
label: Python Version
options:
- earlier
- 3.8
- 3.9
- "3.10"
- "3.11"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/auto-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.8"
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/read-nwbfile-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"] # TODO: update mac and streaming methods
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: s-weigand/setup-conda@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/streaming-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest"] # TODO: update mac and streaming methods
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: s-weigand/setup-conda@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-13", "windows-latest"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: conda-incubator/setup-miniconda@v3
with:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Upcoming

### Deprecation
* Support for Python 3.8 has been removed. [#508](https://github.com/NeurodataWithoutBorders/nwbinspector/issues/508)

### Deprecation (API)
* The `inspect_nwb` method has been removed. Please use `inspect_nwbfile` or `inspect_nwbfile_object` instead. [#505](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/505)

### Improvements
* Removed the `robust_ros3_read` utility helper. [#506](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/506)



# v0.5.2

### Deprecation (API)
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ If you haven't checked it out already, please read the :nwb-overview:`NWB Overvi

The NWBInspector tool offers convenient command-line usage via any standard Conda or Python terminal.

To install the package in any generic Python v3.8-v3.12 environment, simply type
To install the package in any generic Python v3.9-v3.12 environment, simply type

::

Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
classifiers=[
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
Expand Down
6 changes: 3 additions & 3 deletions src/nwbinspector/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from pathlib import Path
from types import FunctionType
from typing import List, Optional
from typing import Optional

import jsonschema
import yaml
Expand Down Expand Up @@ -65,8 +65,8 @@ def load_config(filepath_or_keyword: PathType) -> dict:
def configure_checks(
checks: list = available_checks,
config: Optional[dict] = None,
ignore: Optional[List[str]] = None,
select: Optional[List[str]] = None,
ignore: Optional[list[str]] = None,
select: Optional[list[str]] = None,
importance_threshold: Importance = Importance.BEST_PRACTICE_SUGGESTION,
) -> list:
"""
Expand Down
73 changes: 35 additions & 38 deletions src/nwbinspector/_dandi_inspection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pathlib
from typing import Iterable, List, Literal, Union
from typing import Iterable, Literal, Union
from warnings import filterwarnings

import h5py
Expand All @@ -16,8 +16,8 @@ def inspect_dandiset(
dandiset_version: Union[str, Literal["draft"], None] = None,
config: Union[str, pathlib.Path, dict, Literal["dandi"], None] = None,
checks: Union[list, None] = None,
ignore: Union[List[str], None] = None,
select: Union[List[str], None] = None,
ignore: Union[list[str], None] = None,
select: Union[list[str], None] = None,
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
skip_validate: bool = False,
show_progress_bar: bool = True,
Expand Down Expand Up @@ -112,8 +112,8 @@ def inspect_dandi_file_path(
dandiset_version: Union[str, Literal["draft"], None] = None,
config: Union[str, pathlib.Path, dict, Literal["dandi"]] = "dandi",
checks: Union[list, None] = None,
ignore: Union[List[str], None] = None,
select: Union[List[str], None] = None,
ignore: Union[list[str], None] = None,
select: Union[list[str], None] = None,
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
skip_validate: bool = False,
client: Union["dandi.dandiapi.DandiAPIClient", None] = None,
Expand Down Expand Up @@ -186,8 +186,8 @@ def inspect_url(
url: str,
config: Union[str, pathlib.Path, dict, Literal["dandi"]] = "dandi",
checks: Union[list, None] = None,
ignore: Union[List[str], None] = None,
select: Union[List[str], None] = None,
ignore: Union[list[str], None] = None,
select: Union[list[str], None] = None,
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
skip_validate: bool = False,
) -> Iterable[Union[InspectorMessage, None]]:
Expand Down Expand Up @@ -237,34 +237,31 @@ def inspect_url(
validate_config(config=config)

byte_stream = remfile.File(url=url)
# TODO: when 3.8 support is removed, uncomment to replace block and de-indent
# with (
# h5py.File(name=byte_stream) as file,
# pynwb.NWBHDF5IO(file=file) as io,
# )
with h5py.File(name=byte_stream) as file:
with pynwb.NWBHDF5IO(file=file) as io:
if skip_validate is False:
validation_errors = pynwb.validate(io=io)

for validation_error in validation_errors:
yield InspectorMessage(
message=validation_error.reason,
importance=Importance.PYNWB_VALIDATION,
check_function_name=validation_error.name,
location=validation_error.location,
file_path=nwbfile_path,
)

nwbfile = io.read()

for message in inspect_nwbfile_object(
nwbfile_object=nwbfile,
config=config,
checks=checks,
ignore=ignore,
select=select,
importance_threshold=importance_threshold,
):
message.file_path = url
yield message
with (
h5py.File(name=byte_stream) as file,
pynwb.NWBHDF5IO(file=file) as io,
):
if not skip_validate:
validation_errors = pynwb.validate(io=io)

for validation_error in validation_errors:
yield InspectorMessage(
message=validation_error.reason,
importance=Importance.PYNWB_VALIDATION,
check_function_name=validation_error.name,
location=validation_error.location,
file_path=nwbfile_path,
)

nwbfile = io.read()

for message in inspect_nwbfile_object(
nwbfile_object=nwbfile,
config=config,
checks=checks,
ignore=ignore,
select=select,
importance_threshold=importance_threshold,
):
message.file_path = url
yield message
34 changes: 17 additions & 17 deletions src/nwbinspector/_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from enum import Enum
from pathlib import Path
from platform import platform
from typing import Dict, List, Optional, Union
from typing import Optional, Union

import numpy as np

Expand Down Expand Up @@ -44,7 +44,7 @@ class FormatterOptions:
"""Class structure for defining all free attributes for the design of a report format."""

def __init__(
self, indent_size: int = 2, indent: Optional[str] = None, section_headers: List[str] = ["=", "-", "~"]
self, indent_size: int = 2, indent: Optional[str] = None, section_headers: list[str] = ["=", "-", "~"]
):
"""
Class that defines all the format parameters used by the generic MessageFormatter.
Expand Down Expand Up @@ -75,9 +75,9 @@ class MessageFormatter:

def __init__(
self,
messages: List[InspectorMessage],
levels: List[str],
reverse: Optional[List[bool]] = None,
messages: list[InspectorMessage],
levels: list[str],
reverse: Optional[list[bool]] = None,
detailed: bool = False,
formatter_options: Optional[FormatterOptions] = None,
):
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(
self.formatted_messages = []

@staticmethod
def _count_messages_by_importance(messages: List[InspectorMessage]) -> Dict[str, int]:
def _count_messages_by_importance(messages: list[InspectorMessage]) -> dict[str, int]:
message_count_by_importance = {importance_level.name: 0 for importance_level in Importance}
for message in messages:
message_count_by_importance[message.importance.name] += 1
Expand Down Expand Up @@ -138,16 +138,16 @@ def _get_message_header(self, message: InspectorMessage):
message_header += f"with name '{message.object_name}'"
return message_header

def _get_message_increment(self, level_counter: List[int]):
def _get_message_increment(self, level_counter: list[int]):
return (
f"{'.'.join(np.array(level_counter, dtype=str))}.{self.message_counter}" f"{self.formatter_options.indent}"
)

def _add_subsection(
self,
organized_messages: Dict[str, Union[dict, List[InspectorMessage]]],
levels: List[str],
level_counter: List[int],
organized_messages: dict[str, Union[dict, list[InspectorMessage]]],
levels: list[str],
level_counter: list[int],
):
"""Recursive helper for display_messages."""
this_level_counter = list(level_counter) # local copy passed from previous recursion level
Expand Down Expand Up @@ -193,7 +193,7 @@ def _add_subsection(
self.formatted_messages.extend([f"{' ' * len(increment)} Message: {message.message}", ""])
self.message_counter += 1

def format_messages(self) -> List[str]:
def format_messages(self) -> list[str]:
"""Deploy recursive addition of sections, terminating with message display."""
report_header = _get_report_header()
self.formatted_messages.extend(
Expand All @@ -217,11 +217,11 @@ def format_messages(self) -> List[str]:


def format_messages(
messages: List[InspectorMessage],
levels: List[str] = None,
reverse: Optional[List[bool]] = None,
messages: list[InspectorMessage],
levels: list[str] = None,
reverse: Optional[list[bool]] = None,
detailed: bool = False,
) -> List[str]:
) -> list[str]:
"""Print InspectorMessages in order specified by the organization structure."""
if levels is None:
levels = ["file_path", "importance"]
Expand All @@ -230,14 +230,14 @@ def format_messages(
return formatted_messages


def print_to_console(formatted_messages: List[str]):
def print_to_console(formatted_messages: list[str]):
"""Print report file contents to console."""
sys.stdout.write(os.linesep * 2)
for line in formatted_messages:
sys.stdout.write(line + "\n")


def save_report(report_file_path: FilePathType, formatted_messages: List[str], overwrite=False):
def save_report(report_file_path: FilePathType, formatted_messages: list[str], overwrite=False):
"""Write the list of organized check results to a nicely formatted text file."""
report_file_path = Path(report_file_path)
if report_file_path.exists() and not overwrite:
Expand Down
8 changes: 4 additions & 4 deletions src/nwbinspector/_nwb_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import defaultdict
from concurrent.futures import ProcessPoolExecutor, as_completed
from pathlib import Path
from typing import Iterable, List, Optional, Type, Union
from typing import Iterable, Optional, Type, Union
from warnings import filterwarnings, warn

import pynwb
Expand Down Expand Up @@ -316,7 +316,7 @@ def inspect_nwbfile(


# TODO: deprecate once subject types and dandi schemas have been extended
def _intercept_in_vitro_protein(nwbfile_object: pynwb.NWBFile, checks: Optional[list] = None) -> List[callable]:
def _intercept_in_vitro_protein(nwbfile_object: pynwb.NWBFile, checks: Optional[list] = None) -> list[callable]:
"""
If the special 'protein' subject_id is specified, return a truncated list of checks to run.
Expand Down Expand Up @@ -351,8 +351,8 @@ def inspect_nwbfile_object(
nwbfile_object: pynwb.NWBFile,
checks: Optional[list] = None,
config: Optional[dict] = None,
ignore: Optional[List[str]] = None,
select: Optional[List[str]] = None,
ignore: Optional[list[str]] = None,
select: Optional[list[str]] = None,
importance_threshold: Union[str, Importance] = Importance.BEST_PRACTICE_SUGGESTION,
) -> Iterable[InspectorMessage]:
"""
Expand Down
4 changes: 2 additions & 2 deletions 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 enum import Enum
from typing import List, Optional
from typing import Optional

from natsort import natsorted

Expand All @@ -16,7 +16,7 @@ def _sort_unique_values(unique_values: list, reverse: bool = False):
return natsorted(unique_values, reverse=reverse)


def organize_messages(messages: List[InspectorMessage], levels: List[str], reverse: Optional[List[bool]] = None):
def organize_messages(messages: list[InspectorMessage], levels: list[str], reverse: Optional[list[bool]] = None):
"""
General function for organizing list of InspectorMessages.
Expand Down
6 changes: 3 additions & 3 deletions src/nwbinspector/testing/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from datetime import datetime
from pathlib import Path
from typing import Optional, Tuple
from typing import Optional
from urllib import request
from uuid import uuid4

Expand All @@ -20,7 +20,7 @@
TESTING_CONFIG_FILE_PATH = Path.cwd() / "tests" / "testing_config.json"


def check_streaming_tests_enabled() -> Tuple[bool, Optional[str]]:
def check_streaming_tests_enabled() -> tuple[bool, Optional[str]]:
"""
General purpose helper for determining if the testing environment can support S3 DANDI streaming.
Expand Down Expand Up @@ -136,7 +136,7 @@ def make_minimal_nwbfile():
return NWBFile(session_description="", identifier=str(uuid4()), session_start_time=datetime.now().astimezone())


def check_streaming_enabled() -> Tuple[bool, Optional[str]]:
def check_streaming_enabled() -> tuple[bool, Optional[str]]:
"""
General purpose helper for determining if the environment can support S3 DANDI streaming.
Expand Down
Loading

0 comments on commit 4856bd6

Please sign in to comment.