diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f91485..6525805 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.15.6 + rev: v0.16.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/setup.py b/setup.py index 2525df1..6c9ba80 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ if __name__ == "__main__": try: setup(use_scm_version={"version_scheme": "no-guess-dev"}) - except: # noqa + except: print( "\n\nAn error occurred while building the project, " "please ensure you have the most updated version of setuptools, " diff --git a/src/pybiocfilecache/cache.py b/src/pybiocfilecache/cache.py index 3c13bda..76a611c 100644 --- a/src/pybiocfilecache/cache.py +++ b/src/pybiocfilecache/cache.py @@ -1,9 +1,10 @@ import logging +from collections.abc import Iterator from contextlib import contextmanager from datetime import datetime from pathlib import Path from time import sleep, time -from typing import Any, Dict, Iterator, List, Literal, Optional, Tuple, Union +from typing import Any, Literal from biocframe import BiocFrame from sqlalchemy import create_engine, func, text @@ -39,7 +40,7 @@ class BiocFileCache: - Cleanup of expired resources """ - def __init__(self, cache_dir: Optional[Union[str, Path]] = None, config: Optional[CacheConfig] = None): + def __init__(self, cache_dir: str | Path | None = None, config: CacheConfig | None = None): """Initialize cache with optional configuration. Args: @@ -106,7 +107,7 @@ def _setup_database(self) -> None: return SCHEMA_VERSION - def _get_detached_resource(self, session: Session, obj: Union[Resource, Metadata]) -> Optional[dict]: + def _get_detached_resource(self, session: Session, obj: Resource | Metadata) -> dict | None: """Get a detached copy of a resource.""" if obj is None: return None @@ -205,7 +206,7 @@ def cleanup(self) -> int: ######>> get resources <<###### ############################### - def get(self, rname: str = None, rid: str = None) -> Optional[dict]: + def get(self, rname: str = None, rid: str = None) -> dict | None: """Get resource by name from cache. Args: @@ -244,10 +245,10 @@ def get(self, rname: str = None, rid: str = None) -> Optional[dict]: def add( self, rname: str, - fpath: Union[str, Path], + fpath: str | Path, rtype: Literal["local", "web", "relative"] = "relative", action: Literal["copy", "move", "asis"] = "copy", - expires: Optional[datetime] = None, + expires: datetime | None = None, download: bool = True, ext: bool = True, ) -> dict: @@ -334,7 +335,7 @@ def add( session.commit() raise Exception("Failed to add resource") from e - def add_batch(self, resources: List[Dict[str, Any]]) -> BiocFrame: + def add_batch(self, resources: list[dict[str, Any]]) -> BiocFrame: """Add multiple resources in a single transaction. Args: @@ -356,7 +357,7 @@ def add_batch(self, resources: List[Dict[str, Any]]) -> BiocFrame: def update( self, rname: str, - fpath: Union[str, Path], + fpath: str | Path, action: Literal["copy", "move", "asis"] = "copy", ) -> dict: """Update an existing resource. @@ -430,7 +431,7 @@ def remove(self, rname: str) -> None: session.rollback() raise Exception(f"Failed to remove resource '{rname}'") from e - def list_resources(self, rtype: Optional[str] = None, expired: Optional[bool] = None) -> BiocFrame: + def list_resources(self, rtype: str | None = None, expired: bool | None = None) -> BiocFrame: """List resources in the cache with optional filtering. Args: @@ -521,7 +522,7 @@ def validate_resource(self, resource: Resource) -> bool: # session.merge(resource) # session.commit() - def verify_cache(self) -> Tuple[int, int]: + def verify_cache(self) -> tuple[int, int]: """Verify integrity of all cached resources. Returns: @@ -559,7 +560,7 @@ def search(self, query: str, field: str = "rname", exact: bool = False) -> BiocF return BiocFrame(convert_to_columnar([self._get_detached_resource(session, r) for r in resources])) - def get_stats(self) -> Dict[str, Any]: + def get_stats(self) -> dict[str, Any]: """Get statistics about the cache.""" with self.get_session() as session: total = session.query(Resource).count() diff --git a/src/pybiocfilecache/config.py b/src/pybiocfilecache/config.py index e2dc88e..15b88fd 100644 --- a/src/pybiocfilecache/config.py +++ b/src/pybiocfilecache/config.py @@ -1,7 +1,6 @@ from dataclasses import dataclass from datetime import timedelta from pathlib import Path -from typing import Optional __author__ = "Jayaram Kancherla" __copyright__ = "Jayaram Kancherla" @@ -28,6 +27,6 @@ class CacheConfig: """ cache_dir: Path - cleanup_interval: Optional[timedelta] = None # timedelta(days=30) + cleanup_interval: timedelta | None = None # timedelta(days=30) rname_pattern: str = r"^[a-zA-Z0-9_-]+$" hash_algorithm: str = "md5" diff --git a/src/pybiocfilecache/utils.py b/src/pybiocfilecache/utils.py index 4295af6..4e7d3b3 100644 --- a/src/pybiocfilecache/utils.py +++ b/src/pybiocfilecache/utils.py @@ -7,7 +7,7 @@ import zlib from pathlib import Path from shutil import copy2, move -from typing import List, Literal +from typing import Literal __author__ = "Jayaram Kancherla" __copyright__ = "Jayaram Kancherla" @@ -99,7 +99,7 @@ def download_web_file(url: str, filename: str, download: bool): return outpath -def convert_to_columnar(list_of_dicts: List[dict]): +def convert_to_columnar(list_of_dicts: list[dict]): if not list_of_dicts: return {}