Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pyproject.toml #267

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- bump: minor
changes:
added:
- pyproject.toml, transforming from setup.py
- testing for pyproject.toml
changed:
- edited dependencies in setup.py to avoid overwriting
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")
74 changes: 74 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "policyengine-core"
version = "3.6.3"
dependencies = [
"pytest>=8,<9",
"numpy~=1.26.4",
"black",
"linecheck<1",
"yaml-changelog<1",
"coverage",
"sortedcontainers<3",
"numexpr<3",
"dpath<3",
"psutil<6",
"wheel<1",
"h5py>=3,<4",
"requests>=2.27.1,<3",
"pandas>=1",
"plotly>=5.6.0,<6",
"ipython>=7.17.0,<8",
"pyvis>=0.3.2",
"tomli==2.0.1",
"build==1.2.2",
]
requires-python = ">=3.9"
authors = [
{name = "PolicyEngine", email = "[email protected]"}
]
description = "Core microsimulation engine enabling country-specific policy models."
readme = "README.md"
license = {file = "LICENSE"}
keywords = ["tax", "benefit", "microsimulation", "framework"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: POSIX",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Information Analysis",
]
dynamic = ["scripts"]

[project.optional-dependencies]
dev = [
"jupyter-book<1",
"furo<2023",
"markupsafe==2.0.1",
"coverage",
"furo",
"mypy<2",
"sphinx==5.0.0",
"sphinx-argparse==0.4.0",
"sphinx-math-dollar==1.2.1",
"types-PyYAML==6.0.12.2",
"types-requests==2.28.11.7",
"types-setuptools==65.6.0.2",
"types-urllib3==1.26.25.4",
]

[project.urls]
Homepage = "https://github.com/policyengine/policyengine-core"

[tool.setuptools]
include-package-data = true

[project.entry-points.console_scripts]
policyengine-core = "policyengine_core.scripts.policyengine_command:main"
83 changes: 0 additions & 83 deletions setup.py

This file was deleted.

41 changes: 41 additions & 0 deletions tests/core/test_toml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
from pathlib import Path

import pytest
import tomli


@pytest.fixture(scope="module")
def toml_data():
# get the path of current file and find pyproject.toml relatively
file_path = (
Path(os.path.abspath(os.path.dirname(__file__))).parents[1]
/ "pyproject.toml"
)
if not file_path.exists():
pytest.fail(f"pyproject.toml not found in the current directory.")

Check warning on line 16 in tests/core/test_toml.py

View check run for this annotation

Codecov / codecov/patch

tests/core/test_toml.py#L16

Added line #L16 was not covered by tests
with open(file_path, "rb") as f:
return tomli.load(f)


def test_toml_syntax(toml_data):
try:
toml_data
except tomli.TOMLDecodeError as e:
pytest.fail(f"TOML syntax error: {e}")

Check warning on line 25 in tests/core/test_toml.py

View check run for this annotation

Codecov / codecov/patch

tests/core/test_toml.py#L24-L25

Added lines #L24 - L25 were not covered by tests


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


def test_build_system(toml_data):
build_system = toml_data.get("build-system", {})
assert "requires" in build_system, "Build system 'requires' is missing."
assert (
"build-backend" in build_system
), "Build system 'build-backend' is missing."
Loading