Skip to content

Commit b0dcda7

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2ea30dd commit b0dcda7

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if __name__ == "__main__":
1111
try:
1212
setup(use_scm_version={"version_scheme": "no-guess-dev"})
13-
except: # noqa
13+
except:
1414
print(
1515
"\n\nAn error occurred while building the project, "
1616
"please ensure you have the most updated version of setuptools, "

src/pybiocfilecache/cache.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import logging
2+
from collections.abc import Iterator
23
from contextlib import contextmanager
34
from datetime import datetime
45
from pathlib import Path
56
from time import sleep, time
6-
from typing import Any, Dict, Iterator, List, Literal, Optional, Tuple, Union
7+
from typing import Any, Literal
78

89
from biocframe import BiocFrame
910
from sqlalchemy import create_engine, func, text
@@ -39,7 +40,7 @@ class BiocFileCache:
3940
- Cleanup of expired resources
4041
"""
4142

42-
def __init__(self, cache_dir: Optional[Union[str, Path]] = None, config: Optional[CacheConfig] = None):
43+
def __init__(self, cache_dir: str | Path | None = None, config: CacheConfig | None = None):
4344
"""Initialize cache with optional configuration.
4445
4546
Args:
@@ -106,7 +107,7 @@ def _setup_database(self) -> None:
106107

107108
return SCHEMA_VERSION
108109

109-
def _get_detached_resource(self, session: Session, obj: Union[Resource, Metadata]) -> Optional[dict]:
110+
def _get_detached_resource(self, session: Session, obj: Resource | Metadata) -> dict | None:
110111
"""Get a detached copy of a resource."""
111112
if obj is None:
112113
return None
@@ -205,7 +206,7 @@ def cleanup(self) -> int:
205206
######>> get resources <<######
206207
###############################
207208

208-
def get(self, rname: str = None, rid: str = None) -> Optional[dict]:
209+
def get(self, rname: str = None, rid: str = None) -> dict | None:
209210
"""Get resource by name from cache.
210211
211212
Args:
@@ -244,10 +245,10 @@ def get(self, rname: str = None, rid: str = None) -> Optional[dict]:
244245
def add(
245246
self,
246247
rname: str,
247-
fpath: Union[str, Path],
248+
fpath: str | Path,
248249
rtype: Literal["local", "web", "relative"] = "relative",
249250
action: Literal["copy", "move", "asis"] = "copy",
250-
expires: Optional[datetime] = None,
251+
expires: datetime | None = None,
251252
download: bool = True,
252253
ext: bool = True,
253254
) -> dict:
@@ -334,7 +335,7 @@ def add(
334335
session.commit()
335336
raise Exception("Failed to add resource") from e
336337

337-
def add_batch(self, resources: List[Dict[str, Any]]) -> BiocFrame:
338+
def add_batch(self, resources: list[dict[str, Any]]) -> BiocFrame:
338339
"""Add multiple resources in a single transaction.
339340
340341
Args:
@@ -356,7 +357,7 @@ def add_batch(self, resources: List[Dict[str, Any]]) -> BiocFrame:
356357
def update(
357358
self,
358359
rname: str,
359-
fpath: Union[str, Path],
360+
fpath: str | Path,
360361
action: Literal["copy", "move", "asis"] = "copy",
361362
) -> dict:
362363
"""Update an existing resource.
@@ -430,7 +431,7 @@ def remove(self, rname: str) -> None:
430431
session.rollback()
431432
raise Exception(f"Failed to remove resource '{rname}'") from e
432433

433-
def list_resources(self, rtype: Optional[str] = None, expired: Optional[bool] = None) -> BiocFrame:
434+
def list_resources(self, rtype: str | None = None, expired: bool | None = None) -> BiocFrame:
434435
"""List resources in the cache with optional filtering.
435436
436437
Args:
@@ -521,7 +522,7 @@ def validate_resource(self, resource: Resource) -> bool:
521522
# session.merge(resource)
522523
# session.commit()
523524

524-
def verify_cache(self) -> Tuple[int, int]:
525+
def verify_cache(self) -> tuple[int, int]:
525526
"""Verify integrity of all cached resources.
526527
527528
Returns:
@@ -559,7 +560,7 @@ def search(self, query: str, field: str = "rname", exact: bool = False) -> BiocF
559560

560561
return BiocFrame(convert_to_columnar([self._get_detached_resource(session, r) for r in resources]))
561562

562-
def get_stats(self) -> Dict[str, Any]:
563+
def get_stats(self) -> dict[str, Any]:
563564
"""Get statistics about the cache."""
564565
with self.get_session() as session:
565566
total = session.query(Resource).count()

src/pybiocfilecache/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from dataclasses import dataclass
22
from datetime import timedelta
33
from pathlib import Path
4-
from typing import Optional
54

65
__author__ = "Jayaram Kancherla"
76
__copyright__ = "Jayaram Kancherla"
@@ -28,6 +27,6 @@ class CacheConfig:
2827
"""
2928

3029
cache_dir: Path
31-
cleanup_interval: Optional[timedelta] = None # timedelta(days=30)
30+
cleanup_interval: timedelta | None = None # timedelta(days=30)
3231
rname_pattern: str = r"^[a-zA-Z0-9_-]+$"
3332
hash_algorithm: str = "md5"

src/pybiocfilecache/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import zlib
88
from pathlib import Path
99
from shutil import copy2, move
10-
from typing import List, Literal
10+
from typing import Literal
1111

1212
__author__ = "Jayaram Kancherla"
1313
__copyright__ = "Jayaram Kancherla"
@@ -99,7 +99,7 @@ def download_web_file(url: str, filename: str, download: bool):
9999
return outpath
100100

101101

102-
def convert_to_columnar(list_of_dicts: List[dict]):
102+
def convert_to_columnar(list_of_dicts: list[dict]):
103103
if not list_of_dicts:
104104
return {}
105105

0 commit comments

Comments
 (0)