Skip to content

Commit

Permalink
remove 3.8; update typing
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed Sep 6, 2024
1 parent d55a34c commit a954b9f
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 41 deletions.
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
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
10 changes: 5 additions & 5 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
26 changes: 13 additions & 13 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 @@ -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,9 +217,9 @@ 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]:
"""Print InspectorMessages in order specified by the organization structure."""
Expand Down
6 changes: 3 additions & 3 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 @@ -375,8 +375,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
4 changes: 2 additions & 2 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
6 changes: 3 additions & 3 deletions src/nwbinspector/tools/_dandi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import re
from concurrent.futures import ProcessPoolExecutor, as_completed
from typing import Dict, Optional
from typing import Optional

from ..utils import calculate_number_of_cpu, is_module_installed


def get_s3_urls_and_dandi_paths(dandiset_id: str, version_id: Optional[str] = None, n_jobs: int = 1) -> Dict[str, str]:
def get_s3_urls_and_dandi_paths(dandiset_id: str, version_id: Optional[str] = None, n_jobs: int = 1) -> dict[str, str]:
"""
Collect S3 URLS from a DANDISet ID.
Expand Down Expand Up @@ -46,7 +46,7 @@ def get_s3_urls_and_dandi_paths(dandiset_id: str, version_id: Optional[str] = No
return s3_urls_to_dandi_paths


def _get_content_url_and_path(asset, follow_redirects: int = 1, strip_query: bool = True) -> Dict[str, str]:
def _get_content_url_and_path(asset, follow_redirects: int = 1, strip_query: bool = True) -> dict[str, str]:
"""
Private helper function for parallelization in 'get_s3_urls_and_dandi_paths'.
Expand Down
12 changes: 6 additions & 6 deletions src/nwbinspector/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@
from importlib import import_module
from pathlib import Path
from time import sleep
from typing import Callable, Dict, List, Optional, Tuple, TypeVar, Union
from typing import Callable, Optional, TypeVar, Union

import h5py
import numpy as np
from hdmf.backends.hdf5.h5_utils import H5Dataset
from numpy.typing import ArrayLike
from packaging import version

# TODO: deprecated these in favor of explicit typing
# TODO: deprecat these in favor of explicit typing
PathType = TypeVar("PathType", str, Path) # For types that can be either files or folders
FilePathType = TypeVar("FilePathType", str, Path)
OptionalListOfStrings = Optional[List[str]]
OptionalListOfStrings = Optional[list[str]]

dict_regex = r"({.+:.+})" # TODO: remove this from global scope
MAX_CACHE_ITEMS = 1000 # lru_cache default is 128 calls of matching input/output, but might need more to get use here


@lru_cache(maxsize=MAX_CACHE_ITEMS)
def _cache_data_retrieval_command(
data: h5py.Dataset, reduced_selection: Tuple[Tuple[Optional[int], Optional[int], Optional[int]]]
data: h5py.Dataset, reduced_selection: tuple[tuple[Optional[int], Optional[int], Optional[int]]]
) -> np.ndarray:
"""LRU caching for _cache_data_selection cannot be applied to list inputs; this expects the tuple or Dataset."""
selection = tuple([slice(*reduced_slice) for reduced_slice in reduced_selection]) # reconstitute the slices
return data[selection]


def cache_data_selection(data: Union[h5py.Dataset, ArrayLike], selection: Union[slice, Tuple[slice]]) -> np.ndarray:
def cache_data_selection(data: Union[h5py.Dataset, ArrayLike], selection: Union[slice, tuple[slice]]) -> np.ndarray:
"""Extract the selection lazily from the data object for efficient caching (most beneficial during streaming)."""
if isinstance(data, np.memmap): # np.memmap objects are not hashable - simply return the selection lazily
return data[selection]
Expand Down Expand Up @@ -166,7 +166,7 @@ def get_package_version(name: str) -> version.Version:


def robust_s3_read(
command: Callable, max_retries: int = 10, command_args: Optional[list] = None, command_kwargs: Optional[Dict] = None
command: Callable, max_retries: int = 10, command_args: Optional[list] = None, command_kwargs: Optional[dict] = None
):
"""Attempt the command (usually acting on an S3 IO) up to the number of max_retries using exponential backoff."""
command_args = command_args or []
Expand Down

0 comments on commit a954b9f

Please sign in to comment.