diff --git a/docs/source/conf.py b/docs/source/conf.py index 0291e57f..f61fd9ed 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -60,10 +60,9 @@ autodoc_preserve_defaults = True # -- get version ------------------------------------------------------------- -from cool_seq_tool.version import __version__ +from cool_seq_tool import __version__ -version = __version__ -release = version +version = release = __version__ # -- linkcode ---------------------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 465780be..8989801c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,11 +61,10 @@ Source = "https://github.com/genomicmedlab/cool-seq-tool" "Bug Tracker" = "https://github.com/genomicmedlab/cool-seq-tool/issues" [build-system] -requires = ["setuptools>=64"] +requires = ["setuptools>=64", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" -[tool.setuptools.dynamic] -version = {attr = "cool_seq_tool.version.__version__"} +[tool.setuptools_scm] # Scanning for namespace packages in the ``src`` directory is true by # default in pyproject.toml, so you do NOT need to include the diff --git a/src/cool_seq_tool/__init__.py b/src/cool_seq_tool/__init__.py index 235589b3..45cca2e1 100644 --- a/src/cool_seq_tool/__init__.py +++ b/src/cool_seq_tool/__init__.py @@ -1 +1,10 @@ """The cool_seq_tool package""" + +from importlib.metadata import PackageNotFoundError, version + +try: + __version__ = version("cool_seq_tool") +except PackageNotFoundError: + __version__ = "unknown" +finally: + del version, PackageNotFoundError diff --git a/src/cool_seq_tool/api.py b/src/cool_seq_tool/api.py index ad1929ff..ddcd26f5 100644 --- a/src/cool_seq_tool/api.py +++ b/src/cool_seq_tool/api.py @@ -3,8 +3,8 @@ from fastapi import FastAPI from fastapi.openapi.utils import get_openapi +from cool_seq_tool import __version__ from cool_seq_tool.routers import SERVICE_NAME, default, mane, mappings -from cool_seq_tool.version import __version__ app = FastAPI( docs_url=f"/{SERVICE_NAME}", diff --git a/src/cool_seq_tool/schemas.py b/src/cool_seq_tool/schemas.py index a201b303..bfc18cf0 100644 --- a/src/cool_seq_tool/schemas.py +++ b/src/cool_seq_tool/schemas.py @@ -1,7 +1,6 @@ """Defines attribute constants, useful object structures, and API response schemas.""" import datetime -import re from enum import Enum, IntEnum from typing import Literal @@ -10,11 +9,10 @@ ConfigDict, StrictInt, StrictStr, - field_validator, model_validator, ) -from cool_seq_tool.version import __version__ +from cool_seq_tool import __version__ _now = str(datetime.datetime.now(tz=datetime.timezone.utc)) @@ -276,17 +274,6 @@ class ServiceMeta(BaseModelForbidExtra): "https://github.com/GenomicMedLab/cool-seq-tool" ) - @field_validator("version") - def validate_version(cls, v): - """Check version matches semantic versioning regex pattern. - https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string - """ - version_regex = r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" - if not re.match(version_regex, v): - msg = f"Invalid version {v}" - raise ValueError(msg) - return v - model_config = ConfigDict( json_schema_extra={ "example": { diff --git a/src/cool_seq_tool/utils.py b/src/cool_seq_tool/utils.py index 5a7ac2b7..d6ad69a5 100644 --- a/src/cool_seq_tool/utils.py +++ b/src/cool_seq_tool/utils.py @@ -3,8 +3,8 @@ import datetime import logging +from cool_seq_tool import __version__ from cool_seq_tool.schemas import ResidueMode, ServiceMeta -from cool_seq_tool.version import __version__ _logger = logging.getLogger(__name__) diff --git a/src/cool_seq_tool/version.py b/src/cool_seq_tool/version.py deleted file mode 100644 index 7069d0f7..00000000 --- a/src/cool_seq_tool/version.py +++ /dev/null @@ -1,3 +0,0 @@ -"""Define package version.""" - -__version__ = "0.4.1" diff --git a/tests/mappers/test_exon_genomic_coords.py b/tests/mappers/test_exon_genomic_coords.py index 16911300..39301f2a 100644 --- a/tests/mappers/test_exon_genomic_coords.py +++ b/tests/mappers/test_exon_genomic_coords.py @@ -1,7 +1,6 @@ """Module for testing that Cool Seq Tool works correctly.""" import copy -import re from datetime import datetime import pytest @@ -303,8 +302,7 @@ def check_service_meta(actual): :param ServiceMeta actual: Actual service metadata """ assert actual.name == "cool_seq_tool" - version_regex = r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" - assert bool(re.match(version_regex, actual.version)) + # pydantic checks that version is a string assert isinstance(actual.response_datetime, datetime) assert actual.url == "https://github.com/GenomicMedLab/cool-seq-tool"