Skip to content

Commit

Permalink
feat!: use setuptools-scm, capture version at package root (#194)
Browse files Browse the repository at this point in the history
* use setuptools-scm for versioning instead of explicit declaration in version.py
* provide version in package root instead of version module
  • Loading branch information
korikuzma authored Jul 15, 2024
1 parent e294926 commit b45d2b4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
autodoc_preserve_defaults = True

# -- get version -------------------------------------------------------------
from importlib.metadata import version
from disease import __version__

release = version = version("disease_normalizer")
release = version = __version__

# -- linkcode ----------------------------------------------------------------
def linkcode_resolve(domain, info):
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ disease_norm_dump = "disease.cli:dump_database"
disease_norm_check_db = "disease.cli:check_db"

[build-system]
requires = ["setuptools>=64"]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
version = {attr = "disease.version.__version__"}
[tool.setuptools_scm]

[tool.setuptools.packages.find]
where = ["src"]
Expand Down
11 changes: 9 additions & 2 deletions src/disease/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
"""The VICC library for normalizing diseases."""

from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

from .version import __version__

APP_ROOT = Path(__file__).resolve().parents[0]


try:
__version__ = version("disease-normalizer")
except PackageNotFoundError:
__version__ = "unknown"
finally:
del version, PackageNotFoundError


from disease.schemas import ( # noqa: E402
NamespacePrefix,
RefType,
Expand Down
4 changes: 1 addition & 3 deletions src/disease/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from botocore.exceptions import ClientError
from ga4gh.core import domain_models, entity_models

from disease import NAMESPACE_LOOKUP, PREFIX_LOOKUP, SOURCES_LOWER_LOOKUP
from disease import NAMESPACE_LOOKUP, PREFIX_LOOKUP, SOURCES_LOWER_LOOKUP, __version__
from disease.database.database import AbstractDatabase
from disease.schemas import (
Disease,
Expand All @@ -19,8 +19,6 @@
SourceName,
)

from .version import __version__

_logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion src/disease/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ga4gh.core import domain_models
from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr

from disease.version import __version__
from disease import __version__


class MatchType(IntEnum):
Expand Down
3 changes: 0 additions & 3 deletions src/disease/version.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,27 +284,27 @@ def test_service_meta(query_handler):
response = query_handler.search(test_query)
service_meta = response.service_meta_
assert service_meta.name == "disease-normalizer"
assert service_meta.version >= "0.2.0"
assert service_meta.version
assert isinstance(service_meta.response_datetime, datetime)
assert service_meta.url == "https://github.com/cancervariants/disease-normalization"

response = query_handler.normalize(test_query)
service_meta = response.service_meta_
assert service_meta.name == "disease-normalizer"
assert service_meta.version >= "0.2.0"
assert service_meta.version
assert isinstance(service_meta.response_datetime, datetime)
assert service_meta.url == "https://github.com/cancervariants/disease-normalization"

response = query_handler.search("this-will-not-normalize")
service_meta = response.service_meta_
assert service_meta.name == "disease-normalizer"
assert service_meta.version >= "0.2.0"
assert service_meta.version
assert isinstance(service_meta.response_datetime, datetime)
assert service_meta.url == "https://github.com/cancervariants/disease-normalization"

response = query_handler.normalize("this-will-not-normalize")
service_meta = response.service_meta_
assert service_meta.name == "disease-normalizer"
assert service_meta.version >= "0.2.0"
assert service_meta.version
assert isinstance(service_meta.response_datetime, datetime)
assert service_meta.url == "https://github.com/cancervariants/disease-normalization"

0 comments on commit b45d2b4

Please sign in to comment.