From 00b79db591c968c1831d993417dd827c4889354d Mon Sep 17 00:00:00 2001 From: noman404 Date: Wed, 22 Jan 2025 23:40:36 +0800 Subject: [PATCH 01/10] added toml following setup.py --- pyproject.toml | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..c646d838 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,76 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "policyengine-core" +version = "3.16.1" +dependencies = [ + "pytest>=8,<9", + "numpy~=1.26.4", + "black", + "linecheck<1", + "yaml-changelog<1", + "coverage", + "sortedcontainers<3", + "numexpr<3", + "dpath<3", + "psutil>=6,<7", + "wheel<1", + "h5py>=3,<4", + "requests>=2.27.1,<3", + "pandas>=1", + "plotly>=5.6.0,<6", + "ipython>=8,<9", + "pyvis>=0.3.2", + "tomli==2.0.1", + "build==1.2.2", + "huggingface_hub>=0.25.1", + "microdf_python>=0.4.3", +] +requires-python = ">=3.9" +authors = [ + {name = "PolicyEngine", email = "hello@policyengine.org"} +] +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<3", + "coverage", + "furo<2025", + "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" \ No newline at end of file From 092b0662f7bece41a9601773c8a7e456ad99d11d Mon Sep 17 00:00:00 2001 From: noman404 Date: Wed, 22 Jan 2025 23:45:50 +0800 Subject: [PATCH 02/10] added changelog entry --- changelog_entry.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29b..f96edf0e 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -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 \ No newline at end of file From 57412ebfcf11b4e4c1d0fa7c04f6fa8c431b5326 Mon Sep 17 00:00:00 2001 From: noman404 Date: Wed, 22 Jan 2025 23:46:39 +0800 Subject: [PATCH 03/10] added version related logic --- .github/fetch_version.py | 13 +++++++++++++ .github/is-version-number-acceptable.sh | 2 +- .github/publish-git-tag.sh | 2 +- policyengine_core/__version__.py | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .github/fetch_version.py create mode 100644 policyengine_core/__version__.py diff --git a/.github/fetch_version.py b/.github/fetch_version.py new file mode 100644 index 00000000..ab3a19bb --- /dev/null +++ b/.github/fetch_version.py @@ -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()) \ No newline at end of file diff --git a/.github/is-version-number-acceptable.sh b/.github/is-version-number-acceptable.sh index 0f704a93..a9067e6b 100755 --- a/.github/is-version-number-acceptable.sh +++ b/.github/is-version-number-acceptable.sh @@ -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 diff --git a/.github/publish-git-tag.sh b/.github/publish-git-tag.sh index 0143c67b..420f08f0 100755 --- a/.github/publish-git-tag.sh +++ b/.github/publish-git-tag.sh @@ -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 diff --git a/policyengine_core/__version__.py b/policyengine_core/__version__.py new file mode 100644 index 00000000..818405c2 --- /dev/null +++ b/policyengine_core/__version__.py @@ -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") \ No newline at end of file From 154edb052977ee69ed030c26f301b5e15c6776fd Mon Sep 17 00:00:00 2001 From: noman404 Date: Wed, 22 Jan 2025 23:46:57 +0800 Subject: [PATCH 04/10] updated makefile --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 33da57ef..755a4a30 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,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 \ No newline at end of file From 436548de8b466f2b771809cc17cf420f5f0e0185 Mon Sep 17 00:00:00 2001 From: noman404 Date: Wed, 22 Jan 2025 23:47:16 +0800 Subject: [PATCH 05/10] added test toml --- tests/core/test_toml.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/core/test_toml.py diff --git a/tests/core/test_toml.py b/tests/core/test_toml.py new file mode 100644 index 00000000..d01ac3c1 --- /dev/null +++ b/tests/core/test_toml.py @@ -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.") + 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}") + + +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." \ No newline at end of file From 2d7dc3cd3200edc1ca0696f7204b47c021e081cb Mon Sep 17 00:00:00 2001 From: noman404 Date: Wed, 22 Jan 2025 23:47:29 +0800 Subject: [PATCH 06/10] removed setup file --- setup.py | 84 -------------------------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 setup.py diff --git a/setup.py b/setup.py deleted file mode 100644 index 59b2700f..00000000 --- a/setup.py +++ /dev/null @@ -1,84 +0,0 @@ -from pathlib import Path - -from setuptools import find_packages, setup - -# Read the contents of our README file for PyPi -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() - -# Please make sure to cap all dependency versions, in order to avoid unwanted -# functional and integration breaks caused by external code updates. - -general_requirements = [ - "pytest>=8,<9", - "numpy~=1.26.4", - "sortedcontainers<3", - "numexpr<3", - "dpath<3", - "psutil>=6,<7", - "wheel<1", - "h5py>=3,<4", - "requests>=2,<3", - "pandas>=1", - "plotly>=5,<6", - "ipython>=8,<9", - "pyvis>=0.3.2", - "microdf_python>=0.4.3", - "huggingface_hub>=0.25.1", -] - -dev_requirements = [ - "black", - "linecheck<1", - "jupyter-book<1", - "yaml-changelog<1", - "coverage", - "furo<2025", - "markupsafe<3", - "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", -] - -setup( - name="policyengine-core", - version="3.16.1", - author="PolicyEngine", - author_email="hello@policyengine.org", - 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.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Topic :: Scientific/Engineering :: Information Analysis", - ], - description="Core microsimulation engine enabling country-specific policy models.", - keywords="tax benefit microsimulation framework", - license="https://www.fsf.org/licensing/licenses/agpl-3.0.html", - license_files=("LICENSE",), - url="https://github.com/policyengine/policyengine-core", - long_description=long_description, - long_description_content_type="text/markdown", - entry_points={ - "console_scripts": [ - "policyengine-core=policyengine_core.scripts.policyengine_command:main", - ], - }, - python_requires=">=3.10", - extras_require={ - "dev": dev_requirements, - }, - include_package_data=True, # Will read MANIFEST.in - install_requires=general_requirements, - packages=find_packages(exclude=["tests*"]), -) From 914cb51a42afd312cca03b1853c3eeed170bfd58 Mon Sep 17 00:00:00 2001 From: noman404 Date: Thu, 30 Jan 2025 02:17:44 +0800 Subject: [PATCH 07/10] removed setup.py added from merge --- setup.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 setup.py diff --git a/setup.py b/setup.py deleted file mode 100644 index e69de29b..00000000 From cbbea5f877aefac357e9fa4b8f58b2ca1fe736fa Mon Sep 17 00:00:00 2001 From: noman404 Date: Thu, 30 Jan 2025 02:19:39 +0800 Subject: [PATCH 08/10] added change log --- changelog.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog.yaml b/changelog.yaml index ddb1cf2b..15512c13 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -795,3 +795,8 @@ fixed: - Bug in parametric reforms. date: 2025-01-28 07:08:07 +- bump: major + changes: + fixed: + - Updated to toml. + date: 2025-01-30 02:18:47 From b657f3386d017b32650d973a44289659e24eae42 Mon Sep 17 00:00:00 2001 From: noman404 Date: Thu, 30 Jan 2025 02:22:27 +0800 Subject: [PATCH 09/10] apply reformat --- .github/fetch_version.py | 2 +- policyengine_core/__version__.py | 2 +- tests/core/test_toml.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/fetch_version.py b/.github/fetch_version.py index ab3a19bb..ddecd809 100644 --- a/.github/fetch_version.py +++ b/.github/fetch_version.py @@ -10,4 +10,4 @@ def fetch_version(): if __name__ == "__main__": - print(fetch_version()) \ No newline at end of file + print(fetch_version()) diff --git a/policyengine_core/__version__.py b/policyengine_core/__version__.py index 818405c2..f10d0c84 100644 --- a/policyengine_core/__version__.py +++ b/policyengine_core/__version__.py @@ -6,4 +6,4 @@ pyproject = tomli.load(f) __version__ = pyproject["project"]["version"] except Exception as e: - __version__ = importlib.metadata.version("policyengine_core") \ No newline at end of file + __version__ = importlib.metadata.version("policyengine_core") diff --git a/tests/core/test_toml.py b/tests/core/test_toml.py index d01ac3c1..288b3224 100644 --- a/tests/core/test_toml.py +++ b/tests/core/test_toml.py @@ -38,4 +38,4 @@ def test_build_system(toml_data): assert "requires" in build_system, "Build system 'requires' is missing." assert ( "build-backend" in build_system - ), "Build system 'build-backend' is missing." \ No newline at end of file + ), "Build system 'build-backend' is missing." From 5b2bff47c077713ca462accfaed8ccf2aca65eb5 Mon Sep 17 00:00:00 2001 From: noman404 Date: Thu, 30 Jan 2025 02:43:11 +0800 Subject: [PATCH 10/10] fix change log mistake, applied format --- changelog.yaml | 5 ----- changelog_entry.yaml | 6 ++---- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/changelog.yaml b/changelog.yaml index 15512c13..ddb1cf2b 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -795,8 +795,3 @@ fixed: - Bug in parametric reforms. date: 2025-01-28 07:08:07 -- bump: major - changes: - fixed: - - Updated to toml. - date: 2025-01-30 02:18:47 diff --git a/changelog_entry.yaml b/changelog_entry.yaml index f96edf0e..0fdc7108 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -1,7 +1,5 @@ -- bump: minor +- bump: major changes: added: - pyproject.toml, transforming from setup.py - - testing for pyproject.toml - changed: - - edited dependencies in setup.py to avoid overwriting \ No newline at end of file + - testing for pyproject.toml \ No newline at end of file