Skip to content

Commit e0833e2

Browse files
authored
feature: add __version__ attribute to Python package (#5641)
This PR adds the `__version__` attribute to the Python package. This is commonly added to Python packages to help observe the version of a package through the package API. I tried to make this with dynamic versioning in mind, but please don't hesitate to provide feedback if this misses the mark. Closes #5615 --------- Signed-off-by: d33bs <[email protected]> Signed-off-by: Dave Bunten <[email protected]>
1 parent 1d1ba18 commit e0833e2

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

vortex-python/python/vortex/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
from importlib import metadata as _metadata
5+
46
from . import _lib, arrays, dataset, expr, file, io, ray, registry, scan
57
from ._lib.arrays import ( # pyright: ignore[reportMissingModuleSource]
68
AlpArray,
@@ -81,6 +83,15 @@
8183

8284
assert _lib, "Ensure we eagerly import the Vortex native library"
8385

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
"""
13+
Tests that we see the correct __version__
14+
value exported by the package.
15+
"""
16+
try:
17+
expected = importlib.metadata.version("vortex-data")
18+
except importlib.metadata.PackageNotFoundError:
19+
pytest.skip("vortex-data distribution metadata unavailable")
20+
# Ensure the exported version matches the distribution metadata.
21+
assert vortex.__version__ == expected

0 commit comments

Comments
 (0)