Skip to content

Commit 41c44f6

Browse files
committed
WIP: fix current version fetching in workflow and Makefile; fix test for pyproject.toml; add fetch_version.py and __version__.py
target to fix: issue #256
1 parent 635aea0 commit 41c44f6

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

.github/fetch_version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from policyengine_core.__version__ import __version__
2+
3+
4+
def fetch_version():
5+
try:
6+
return __version__
7+
except Exception as e:
8+
print(f"Error fetching version: {e}")
9+
return None
10+
11+
12+
if __name__ == "__main__":
13+
print(fetch_version())

.github/is-version-number-acceptable.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ then
1212
exit 0
1313
fi
1414

15-
current_version=`python setup.py --version`
15+
current_version=`python .github/fetch_version.py`
1616

1717
if git rev-parse --verify --quiet $current_version
1818
then

.github/publish-git-tag.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#! /usr/bin/env bash
22

3-
git tag `python setup.py --version`
3+
git tag `python .github/fetch_version.py`
44
git push --tags || true # update the repository version

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ test: test-country-template
2121
coverage xml -i
2222

2323
build:
24-
python setup.py sdist bdist_wheel
24+
python -m build
2525

2626
changelog:
2727
build-changelog changelog.yaml --output changelog.yaml --update-last-date --start-from 0.1.0 --append-file changelog_entry.yaml
2828
build-changelog changelog.yaml --org PolicyEngine --repo policyengine-core --output CHANGELOG.md --template .github/changelog_template.md
29-
bump-version changelog.yaml setup.py
29+
bump-version changelog.yaml pyproject.toml
3030
rm changelog_entry.yaml || true
3131
touch changelog_entry.yaml

policyengine_core/__version__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import importlib.metadata
2+
import tomli
3+
4+
try:
5+
with open("pyproject.toml", "rb") as f:
6+
pyproject = tomli.load(f)
7+
__version__ = pyproject["project"]["version"]
8+
except Exception as e:
9+
__version__ = importlib.metadata.version("policyengine_core")

tests/core/test_toml.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
import os
2-
import subprocess
1+
from pathlib import Path
32
import tomli
43
import pytest
54

65

76
@pytest.fixture(scope="module")
87
def toml_data():
9-
file_path = "../../pyproject.toml"
10-
if not os.path.exists(file_path):
11-
pytest.fail("pyproject.toml not found in the current directory.")
8+
file_path = Path("/policyengine-core/pyproject.toml")
9+
if not file_path.exists():
10+
pytest.fail(f"pyproject.toml not found in the current directory.")
1211
with open(file_path, "rb") as f:
1312
return tomli.load(f)
1413

1514

16-
def test_toml_syntax():
17-
file_path = "../../pyproject.toml"
15+
def test_toml_syntax(toml_data):
1816
try:
19-
with open(file_path, "rb") as f:
20-
tomli.load(f)
17+
toml_data
2118
except tomli.TOMLDecodeError as e:
2219
pytest.fail(f"TOML syntax error: {e}")
2320

2421

2522
def test_required_fields(toml_data):
26-
required_fields = ["name", "version", "description"]
23+
required_fields = ["name", "version", "dependencies"]
2724
for field in required_fields:
2825
assert field in toml_data.get(
2926
"project", {}

0 commit comments

Comments
 (0)