Skip to content

Commit cdd1cf4

Browse files
committed
Simplify version
1 parent 8c50bb0 commit cdd1cf4

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

python/evalica/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import contextlib
65
import math
76
import os
87
import warnings
@@ -16,6 +15,9 @@
1615
import pandas as pd
1716
from scipy.stats import bootstrap as scipy_bootstrap
1817

18+
__version__ = "0.4.0rc1"
19+
"""The version of Evalica."""
20+
1921

2022
class Winner(IntEnum):
2123
"""The outcome of the pairwise comparison."""
@@ -79,7 +81,6 @@ class RustExtensionWarning(RuntimeWarning):
7981
raise ImportError # noqa: TRY301
8082

8183
from . import _brzo
82-
from ._brzo import __version__
8384

8485
PYO3_AVAILABLE = True
8586
"""
@@ -94,11 +95,6 @@ class RustExtensionWarning(RuntimeWarning):
9495
stacklevel=1,
9596
)
9697

97-
import importlib.metadata
98-
99-
with contextlib.suppress(importlib.metadata.PackageNotFoundError):
100-
__version__ = importlib.metadata.version("evalica")
101-
10298
_brzo = None # type: ignore[assignment]
10399

104100
PYO3_AVAILABLE = False

python/evalica/_brzo.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import numpy.typing as npt
66
from . import DistanceName
77

88
__version__: str = ...
9-
"""The version of Evalica."""
9+
"""The version of Evalica Brzo module."""
1010

1111
def matrices(
1212
xs: Collection[int],

python/evalica/test_evalica.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def test_solver_errors_all_functions(algorithm: str) -> None:
6161

6262

6363
@pytest.mark.skipif(not evalica.PYO3_AVAILABLE, reason="Rust extension is not available")
64-
def test_version_consistency() -> None:
65-
assert evalica.__version__ == evalica._brzo.__version__ # noqa: SLF001
64+
def test_brzo_has_version() -> None:
65+
assert hasattr(evalica._brzo, "__version__") # noqa: SLF001
66+
assert isinstance(evalica._brzo.__version__, str) # noqa: SLF001
6667

6768

6869
def test_exports() -> None:
@@ -116,3 +117,16 @@ def test_pairwise_scores_solver_error(monkeypatch: pytest.MonkeyPatch) -> None:
116117
monkeypatch.setattr(evalica, "PYO3_AVAILABLE", False)
117118
with pytest.raises(evalica.SolverError):
118119
evalica.pairwise_scores(np.array([1.0, 2.0, 3.0]), solver="pyo3")
120+
121+
122+
def test_version_without_brzo() -> None:
123+
with unittest.mock.patch.dict(sys.modules, {"evalica._brzo": None}):
124+
sys.modules.pop("evalica", None)
125+
126+
with warnings.catch_warnings():
127+
warnings.simplefilter("ignore", category=RuntimeWarning)
128+
import evalica # noqa: PLC0415
129+
130+
assert not evalica.PYO3_AVAILABLE
131+
assert isinstance(evalica.__version__, str)
132+
assert len(evalica.__version__) > 0

0 commit comments

Comments
 (0)