From 659bde525dcd282a84cb659b3cfdb820059d2409 Mon Sep 17 00:00:00 2001 From: Kori Kuzma Date: Fri, 12 Jul 2024 09:35:57 -0400 Subject: [PATCH] feat!: use setuptools-scm, capture version at package root * use setuptools-scm for versioning instead of explicit declaration in version.py * provide version in package root instead of version module --- docs/source/conf.py | 3 +-- pyproject.toml | 5 ++--- src/gene/__init__.py | 11 +++++++++-- src/gene/query.py | 3 +-- src/gene/schemas.py | 2 +- src/gene/version.py | 3 --- 6 files changed, 14 insertions(+), 13 deletions(-) delete mode 100644 src/gene/version.py diff --git a/docs/source/conf.py b/docs/source/conf.py index 959356b..6958429 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -68,8 +68,7 @@ # -- get version ------------------------------------------------------------- from gene import __version__ # noqa: E402 -version = __version__ -release = version +version = release = __version__ # -- linkcode ---------------------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index eb227ed..8e7c014 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,11 +63,10 @@ gene_norm_dump = "gene.cli:dump_database" gene_norm_check_db = "gene.cli:check_db" [build-system] -requires = ["setuptools>=61.0"] +requires = ["setuptools>=64", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" -[tool.setuptools.dynamic] -version = {attr = "gene.version.__version__"} +[tool.setuptools_scm] [tool.setuptools.packages.find] where = ["src"] diff --git a/src/gene/__init__.py b/src/gene/__init__.py index 4d2b71e..eb2471c 100644 --- a/src/gene/__init__.py +++ b/src/gene/__init__.py @@ -1,10 +1,9 @@ """The VICC library for normalizing genes.""" +from importlib.metadata import PackageNotFoundError, version from os import environ from pathlib import Path -from .version import __version__ - APP_ROOT = Path(__file__).resolve().parent SEQREPO_ROOT_DIR = Path( @@ -12,6 +11,14 @@ ) +try: + __version__ = version("gene-normalizer") +except PackageNotFoundError: + __version__ = "unknown" +finally: + del version, PackageNotFoundError + + class DownloadException(Exception): # noqa: N818 """Exception for failures relating to source file downloads.""" diff --git a/src/gene/query.py b/src/gene/query.py index 17ecd3d..273846c 100644 --- a/src/gene/query.py +++ b/src/gene/query.py @@ -9,7 +9,7 @@ from ga4gh.core import domain_models, entity_models, ga4gh_identify from ga4gh.vrs import models -from gene import ITEM_TYPES, NAMESPACE_LOOKUP, PREFIX_LOOKUP +from gene import ITEM_TYPES, NAMESPACE_LOOKUP, PREFIX_LOOKUP, __version__ from gene.database import AbstractDatabase, DatabaseReadException from gene.schemas import ( BaseGene, @@ -29,7 +29,6 @@ SourcePriority, UnmergedNormalizationService, ) -from gene.version import __version__ _logger = logging.getLogger(__name__) diff --git a/src/gene/schemas.py b/src/gene/schemas.py index f298769..6e96e32 100644 --- a/src/gene/schemas.py +++ b/src/gene/schemas.py @@ -14,7 +14,7 @@ constr, ) -from gene.version import __version__ +from gene import __version__ CURIE = constr(pattern=r"^\w[^:]*:.+$") diff --git a/src/gene/version.py b/src/gene/version.py deleted file mode 100644 index 71445f0..0000000 --- a/src/gene/version.py +++ /dev/null @@ -1,3 +0,0 @@ -"""Gene normalizer version""" - -__version__ = "0.3.2"