Skip to content

Commit 89cd8e0

Browse files
Merge pull request #100 from ram-from-tvl/dynamic-versioning
dynamic versioning
2 parents 12d4558 + 876c711 commit 89cd8e0

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "open-data-pvnet"
7-
version = "0.1.1" # Static version
7+
dynamic = ["version"]
88
readme = { file = "README.md", content-type = "text/markdown" }
99
description = "An open-source project supporting solar forecasting with PVNet."
1010
license = { text = "MIT" }

tests/test_metadata.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
import tomllib
2+
from importlib import metadata
3+
24
import open_data_pvnet
35

46

57
def test_version_consistency():
68
"""
7-
Verify that the version in pyproject.toml matches the version in __init__.py
9+
Verify that the dynamic version works correctly and matches the version in __init__.py
810
"""
9-
# Read version from pyproject.toml
11+
# Read the dynamic version configuration from pyproject.toml
1012
with open("pyproject.toml", "rb") as f:
1113
pyproject_data = tomllib.load(f)
12-
pyproject_version = pyproject_data["project"]["version"]
14+
15+
# Verify that dynamic versioning is configured
16+
assert "version" in pyproject_data["project"]["dynamic"], (
17+
"Dynamic versioning should be configured in pyproject.toml"
18+
)
19+
20+
# Get the version from the installed package metadata
21+
try:
22+
package_version = metadata.version("open-data-pvnet")
23+
except metadata.PackageNotFoundError:
24+
# If package is not installed, skip this check
25+
package_version = None
1326

1427
# Read version from the __init__.py file
1528
init_version = open_data_pvnet.__version__
1629

17-
# Assert both versions are the same
18-
assert pyproject_version == init_version, (
19-
f"Version mismatch: pyproject.toml has {pyproject_version}, "
20-
f"but __init__.py has {init_version}"
30+
# If package is installed, verify versions match
31+
if package_version:
32+
assert package_version == init_version, (
33+
f"Version mismatch: installed package has {package_version}, "
34+
f"but __init__.py has {init_version}"
35+
)
36+
37+
# Verify that setuptools dynamic configuration is correct
38+
dynamic_config = pyproject_data["tool"]["setuptools"]["dynamic"]
39+
assert "version" in dynamic_config, (
40+
"Version should be configured in [tool.setuptools.dynamic]"
41+
)
42+
assert dynamic_config["version"]["attr"] == "open_data_pvnet.__version__", (
43+
"Dynamic version should point to open_data_pvnet.__version__"
2144
)

0 commit comments

Comments
 (0)