Skip to content

Commit

Permalink
WIP: fix current version fetching in workflow and Makefile; fix test …
Browse files Browse the repository at this point in the history
…for pyproject.toml; add fetch_version.py and __version__.py

target to fix: issue #256
  • Loading branch information
SylviaDu99 committed Sep 11, 2024
1 parent 635aea0 commit 41c44f6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .github/fetch_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from policyengine_core.__version__ import __version__


def fetch_version():
try:
return __version__
except Exception as e:
print(f"Error fetching version: {e}")
return None


if __name__ == "__main__":
print(fetch_version())
2 changes: 1 addition & 1 deletion .github/is-version-number-acceptable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ then
exit 0
fi

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

if git rev-parse --verify --quiet $current_version
then
Expand Down
2 changes: 1 addition & 1 deletion .github/publish-git-tag.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env bash

git tag `python setup.py --version`
git tag `python .github/fetch_version.py`
git push --tags || true # update the repository version
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ test: test-country-template
coverage xml -i

build:
python setup.py sdist bdist_wheel
python -m build

changelog:
build-changelog changelog.yaml --output changelog.yaml --update-last-date --start-from 0.1.0 --append-file changelog_entry.yaml
build-changelog changelog.yaml --org PolicyEngine --repo policyengine-core --output CHANGELOG.md --template .github/changelog_template.md
bump-version changelog.yaml setup.py
bump-version changelog.yaml pyproject.toml
rm changelog_entry.yaml || true
touch changelog_entry.yaml
9 changes: 9 additions & 0 deletions policyengine_core/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import importlib.metadata
import tomli

try:
with open("pyproject.toml", "rb") as f:
pyproject = tomli.load(f)
__version__ = pyproject["project"]["version"]
except Exception as e:
__version__ = importlib.metadata.version("policyengine_core")
17 changes: 7 additions & 10 deletions tests/core/test_toml.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import os
import subprocess
from pathlib import Path
import tomli
import pytest


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


def test_toml_syntax():
file_path = "../../pyproject.toml"
def test_toml_syntax(toml_data):
try:
with open(file_path, "rb") as f:
tomli.load(f)
toml_data
except tomli.TOMLDecodeError as e:
pytest.fail(f"TOML syntax error: {e}")


def test_required_fields(toml_data):
required_fields = ["name", "version", "description"]
required_fields = ["name", "version", "dependencies"]
for field in required_fields:
assert field in toml_data.get(
"project", {}
Expand Down

0 comments on commit 41c44f6

Please sign in to comment.