Skip to content

Commit

Permalink
WIP: add pyproject.toml, test_toml.py; edited setup.py to avoid overw…
Browse files Browse the repository at this point in the history
…riting with pyproject.toml

target to fix: issue PolicyEngine#256
  • Loading branch information
SylviaDu99 committed Sep 12, 2024
1 parent baa2c2c commit 996737a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 44 deletions.
14 changes: 9 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[build-system]
requires = [
"setuptools",
"pathlib"
]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "policyengine-core"
version = "3.6.0"
version = "3.6.3"
dependencies = [
"pytest>=8,<9",
"numpy~=1.26.4",
Expand Down Expand Up @@ -46,6 +43,7 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Information Analysis",
]
dynamic = ["scripts"]

[project.optional-dependencies]
dev = [
Expand All @@ -67,5 +65,11 @@ dev = [
[project.urls]
Homepage = "https://github.com/policyengine/policyengine-core"

[tool.setuptools.packages.find]
exclude = ["tests*"]

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

[project.entry-points.console_scripts]
policyengine-core = "policyengine_core.scripts.policyengine_command:main"
78 changes: 39 additions & 39 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@
# 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",
"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",
]

dev_requirements = [
"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",
]
# general_requirements = [
# "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",
# ]
#
# dev_requirements = [
# "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",
# ]

setup(
name="policyengine-core",
Expand Down Expand Up @@ -74,10 +74,10 @@
],
},
python_requires=">=3.9",
extras_require={
"dev": dev_requirements,
},
# extras_require={
# "dev": dev_requirements,
# },
include_package_data=True, # Will read MANIFEST.in
install_requires=general_requirements,
# install_requires=general_requirements,
packages=find_packages(exclude=["tests*"]),
)
51 changes: 51 additions & 0 deletions test_toml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import subprocess
import tomli
import pytest
from packaging import version

@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.")
with open(file_path, "rb") as f:
return tomli.load(f)

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

def test_required_fields(toml_data):
required_fields = ["name", "version", "description"]
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."

def test_package_build():
try:
subprocess.run(["python", "-m", "build"], check=True)
except subprocess.CalledProcessError:
pytest.fail("Failed to build package.")

def test_package_installation():
try:
subprocess.run(["pip", "install", "."], check=True)
except subprocess.CalledProcessError:
pytest.fail("Failed to install package.")

def test_run_tests():
try:
subprocess.run(["pytest"], check=True)
except subprocess.CalledProcessError:
pytest.fail("Some tests failed.")
except FileNotFoundError:
pytest.skip("pytest not found. Make sure it's installed and in your PATH.")

0 comments on commit 996737a

Please sign in to comment.