diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 61fbd30..0697e05 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,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.cfg b/setup.cfg index cc0b526..24bd544 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,7 +15,7 @@ long_description_content_type = text/markdown; charset=UTF-8; variant=GFM url = https://github.com/biocpy/txdb # Add here related links, for example: project_urls = - Documentation = https://biocpy.github.io/txdb/ + Documentation = https://biocpy.github.io/txdb/ Source = https://github.com/biocpy/txdb # Changelog = https://pyscaffold.org/en/latest/changelog.html # Tracker = https://github.com/pyscaffold/pyscaffold/issues diff --git a/setup.py b/setup.py index 1a4cd32..dceef48 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,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/txdb/__init__.py b/src/txdb/__init__.py index e97557e..b67a076 100644 --- a/src/txdb/__init__.py +++ b/src/txdb/__init__.py @@ -19,4 +19,4 @@ from .txdb import TxDb from .txdbregistry import TxDbRegistry -__all__ = ["TxDb", "TxDbRegistry", "TxDbRecord"] +__all__ = ["TxDb", "TxDbRecord", "TxDbRegistry"] diff --git a/src/txdb/record.py b/src/txdb/record.py index 5ccf4f3..465ce21 100644 --- a/src/txdb/record.py +++ b/src/txdb/record.py @@ -2,7 +2,6 @@ from dataclasses import dataclass from datetime import date, datetime -from typing import Optional __author__ = "Jayaram Kancherla" __copyright__ = "Jayaram Kancherla" @@ -14,18 +13,18 @@ class TxDbRecord: """Container for a single TxDb entry.""" txdb_id: str - release_date: Optional[date] + release_date: date | None url: str - organism: Optional[str] = None # e.g. "Hsapiens" - source: Optional[str] = None # e.g. "UCSC", "BioMart" - build: Optional[str] = None # e.g. "hg38.knownGene" + organism: str | None = None # e.g. "Hsapiens" + source: str | None = None # e.g. "UCSC", "BioMart" + build: str | None = None # e.g. "hg38.knownGene" # Parsed from URL path (e.g. .../3.22/TxDb...) - bioc_version: Optional[str] = None + bioc_version: str | None = None @classmethod - def from_config_entry(cls, txdb_id: str, entry: dict) -> "TxDbRecord": + def from_config_entry(cls, txdb_id: str, entry: dict) -> TxDbRecord: """Build a record from a TXDB_CONFIG entry: { "release_date": "YYYY-MM-DD", # optional @@ -35,7 +34,7 @@ def from_config_entry(cls, txdb_id: str, entry: dict) -> "TxDbRecord": url = entry["url"] date_str = entry.get("release_date") - rel_date: Optional[date] + rel_date: date | None if date_str: rel_date = datetime.strptime(date_str, "%Y-%m-%d").date() else: @@ -62,10 +61,8 @@ def _parse_txdb_id(txdb_id: str): into (organism, source, build). """ name = txdb_id - if name.startswith("TxDb."): - name = name[len("TxDb.") :] - if name.endswith(".sqlite"): - name = name[: -len(".sqlite")] + name = name.removeprefix("TxDb.") + name = name.removesuffix(".sqlite") parts = name.split(".") if len(parts) < 2: @@ -77,7 +74,7 @@ def _parse_txdb_id(txdb_id: str): return organism, source, build -def _parse_bioc_version(url: str) -> Optional[str]: +def _parse_bioc_version(url: str) -> str | None: """Extract the Bioconductor/AnnotationHub-like version from URL. Example: diff --git a/src/txdb/txdb.py b/src/txdb/txdb.py index e27265d..2aae2b1 100644 --- a/src/txdb/txdb.py +++ b/src/txdb/txdb.py @@ -1,5 +1,4 @@ import sqlite3 -from typing import List, Optional from biocframe import BiocFrame from genomicranges import GenomicRanges, SeqInfo @@ -95,8 +94,8 @@ def _fetch_as_gr( self, table: str, prefix: str, - columns: Optional[List[str]] = None, - filter: Optional[dict] = None, + columns: list[str] | None = None, + filter: dict | None = None, ) -> GenomicRanges: """Internal helper to fetch a table and convert to GenomicRanges. @@ -165,7 +164,7 @@ def _fetch_as_gr( seqinfo=self.seqinfo, ) - def transcripts(self, filter: Optional[dict] = None) -> GenomicRanges: + def transcripts(self, filter: dict | None = None) -> GenomicRanges: """Retrieve transcripts as a GenomicRanges object. Args: @@ -177,7 +176,7 @@ def transcripts(self, filter: Optional[dict] = None) -> GenomicRanges: """ return self._fetch_as_gr("transcript", "tx", filter=filter) - def exons(self, filter: Optional[dict] = None) -> GenomicRanges: + def exons(self, filter: dict | None = None) -> GenomicRanges: """Retrieve exons as a GenomicRanges object. Args: @@ -189,7 +188,7 @@ def exons(self, filter: Optional[dict] = None) -> GenomicRanges: """ return self._fetch_as_gr("exon", "exon", filter=filter) - def cds(self, filter: Optional[dict] = None) -> GenomicRanges: + def cds(self, filter: dict | None = None) -> GenomicRanges: """Retrieve coding sequences (CDS) as a GenomicRanges object. Args: diff --git a/src/txdb/txdbregistry.py b/src/txdb/txdbregistry.py index 7cbe3d1..a188b90 100644 --- a/src/txdb/txdbregistry.py +++ b/src/txdb/txdbregistry.py @@ -1,7 +1,7 @@ import os import sqlite3 from pathlib import Path -from typing import Any, Dict, Optional, Union +from typing import Any from pybiocfilecache import BiocFileCache @@ -19,7 +19,7 @@ class TxDbRegistry: def __init__( self, - cache_dir: Optional[Union[str, Path]] = None, + cache_dir: str | Path | None = None, force: bool = False, ) -> None: """Initialize the TxDB registry. @@ -39,7 +39,7 @@ def __init__( self._cache_dir.mkdir(parents=True, exist_ok=True) self._bfc = BiocFileCache(self._cache_dir) - self._registry_map: Dict[str, TxDbRecord] = {} + self._registry_map: dict[str, TxDbRecord] = {} self._initialize_registry(force=force) @@ -195,7 +195,7 @@ def load_db(self, txdb_id: str, force: bool = False) -> TxDb: path = self.download(txdb_id, force=force) return TxDb(path) - def _get_filepath(self, resource: Any) -> Optional[str]: + def _get_filepath(self, resource: Any) -> str | None: """Helper to extract absolute path from a BiocFileCache resource.""" if hasattr(resource, "rpath"): rel_path = str(resource.rpath)