Skip to content

Commit 4d9acd3

Browse files
committed
feature: add __version__ attribute to python pkg
1 parent 374882d commit 4d9acd3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

vortex-python/python/vortex/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@
8181

8282
assert _lib, "Ensure we eagerly import the Vortex native library"
8383

84+
from importlib import metadata as _metadata
85+
86+
# Resolve the installed distribution version so it is available as vortex.__version__.
87+
__version__ = "unknown"
88+
try:
89+
# Try to read the installed distribution version for the Python package name.
90+
__version__ = _metadata.version("vortex-data")
91+
except _metadata.PackageNotFoundError:
92+
# If the distribution is not installed, keep the unknown fallback.
93+
pass
94+
8495
__all__ = [
8596
# --- Modules ---
8697
"arrays",
@@ -169,4 +180,6 @@
169180
"ArrayIterator",
170181
# Scan
171182
"RepeatedScan",
183+
# Version
184+
"__version__",
172185
]

vortex-python/test/test_version.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
import importlib.metadata
5+
6+
import pytest
7+
8+
import vortex
9+
10+
11+
def test_version_matches_metadata():
12+
try:
13+
expected = importlib.metadata.version("vortex-data")
14+
except importlib.metadata.PackageNotFoundError:
15+
pytest.skip("vortex-data distribution metadata unavailable")
16+
# Ensure the exported version matches the distribution metadata.
17+
assert vortex.__version__ == expected

0 commit comments

Comments
 (0)