Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
23 changes: 12 additions & 11 deletions src/pybiocfilecache/cache.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/pybiocfilecache/config.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
4 changes: 2 additions & 2 deletions src/pybiocfilecache/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {}

Expand Down
Loading