Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/commonlid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# model's ``load()``), so this stays cheap.
from commonlid import datasets as _tasks # noqa: F401
from commonlid import models as _models # noqa: F401
from commonlid._version import __version__
from commonlid.core.lid_dataset import LIDDataset, PrivateDatasetAccessError
from commonlid.core.lid_model import LIDModel, LIDPrediction
from commonlid.core.registry import (
Expand All @@ -19,8 +20,6 @@
from commonlid.evaluation.evaluator import Evaluator
from commonlid.evaluation.results import Result

__version__ = "0.1.0"

__all__ = [
"Evaluator",
"LIDDataset",
Expand Down
16 changes: 16 additions & 0 deletions src/commonlid/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Single source of truth for the package version.

Read from the wheel metadata so it can never drift from ``pyproject.toml``.
The fallback only fires for source-tree imports that were never installed
(e.g. ``PYTHONPATH=src python …``).
"""

from __future__ import annotations

from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as _pkg_version

try:
__version__ = _pkg_version("commonlid")
except PackageNotFoundError: # pragma: no cover
__version__ = "0.0.0+unknown"
11 changes: 11 additions & 0 deletions tests/unit/test_cli_stub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
from importlib.metadata import version as _pkg_version

from typer.testing import CliRunner

Expand All @@ -16,6 +17,16 @@ def test_version() -> None:
assert __version__ in result.stdout


def test_version_matches_package_metadata() -> None:
"""``commonlid.__version__`` must track the wheel's installed metadata.

Catches the failure mode where the publish workflow bumps
``pyproject.toml`` but a hand-kept version constant inside the package
drifts. The two should never diverge at runtime.
"""
assert __version__ == _pkg_version("commonlid")


def test_list_models_json_contains_known_models() -> None:
result = runner.invoke(app, ["list-models", "--json"])
assert result.exit_code == 0
Expand Down
Loading