From 6fefcb25bb8c4c1a694f0b4d743fb60a8e98634a Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Thu, 9 May 2024 14:29:24 -0400 Subject: [PATCH 01/16] move cibuildwheel to pyproject and test on numpy 2.0 --- .github/workflows/build.yml | 7 ++----- pyproject.toml | 13 +++++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 768b2da..e0cab3f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, windows-2019, macos-11] + os: [ubuntu-22.04, windows-2019, macos-11] steps: - uses: actions/checkout@v3 @@ -16,10 +16,7 @@ jobs: submodules: recursive - name: Build wheels - uses: pypa/cibuildwheel@v2.16.2 - env: - CIBW_ARCHS_MACOS: x86_64 arm64 - CIBW_TEST_SKIP: "*_arm64 *_universal2:arm64" + uses: pypa/cibuildwheel@v2.17.0 - name: Show files run: ls -lh wheelhouse diff --git a/pyproject.toml b/pyproject.toml index 79cf107..cb9d1e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,5 +3,18 @@ requires = [ "setuptools>=42", "wheel", "pybind11~=2.6", + "numpy==1.26.4" ] build-backend = "setuptools.build_meta" + +[tool.cibuildwheel] +# install the `test` extra +test-extras = ["test"] +# Run the package tests using `pytest` + +test-command = "pytest {package}/tests && pip install --force-reinstall --upgrade --pre numpy && pytest {package}/tests" +test-skip = "*_arm64 *_universal2:arm64" + +[tool.cibuildwheel.macos] +archs = ["x86_64", "arm64"] + From 921f3692c123923c6d64249b5c58a885efc10a70 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Thu, 9 May 2024 14:30:21 -0400 Subject: [PATCH 02/16] trigger action --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index cb9d1e1..80bfbfb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = [ "setuptools>=42", "wheel", "pybind11~=2.6", - "numpy==1.26.4" + "numpy==1.26.4" ] build-backend = "setuptools.build_meta" From 93e4ad30c002497dc21f6ef1ed67aaab1e5c2d4f Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Thu, 9 May 2024 14:32:25 -0400 Subject: [PATCH 03/16] try oldest numpy on python 3.6 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 80bfbfb..340fe22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = [ "setuptools>=42", "wheel", "pybind11~=2.6", - "numpy==1.26.4" + "numpy>=1.19.5" ] build-backend = "setuptools.build_meta" From 3bb9b851f05dd38f8dcf6ac643d9c810907da938 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Thu, 9 May 2024 15:04:02 -0400 Subject: [PATCH 04/16] move project info to pyproject --- pyproject.toml | 28 ++++++++++++++++++++++++++-- setup.py | 39 ++++++++------------------------------- src/main.cpp | 1 - 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 340fe22..23490d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,10 +3,35 @@ requires = [ "setuptools>=42", "wheel", "pybind11~=2.6", - "numpy>=1.19.5" + "numpy>=1.26.0" ] build-backend = "setuptools.build_meta" +[project] +name = "mapbox_earcut" +version = "1.0.2" +requires-python = ">=3.7" +authors = [{name = "Samuel Kogler", email = "samuel.kogler@gmail.com"}] +license = {file = "LICENSE.md"} +description = "Python bindings for the mapbox earcut C++ polygon triangulation library." +dependencies = ["numpy>=1.26.0"] + +[project.urls] +Source = "https://github.com/skogler/mapbox_earcut_python" +CSource = "https://github.com/mapbox/earcut.hpp" + +[project.readme] +file = "README.md" +content-type = "text/markdown" + +[tool.setuptools] +zip-safe = false +include-package-data = true + +[project.optional-dependencies] +test = ["pytest"] + + [tool.cibuildwheel] # install the `test` extra test-extras = ["test"] @@ -17,4 +42,3 @@ test-skip = "*_arm64 *_universal2:arm64" [tool.cibuildwheel.macos] archs = ["x86_64", "arm64"] - diff --git a/setup.py b/setup.py index faee1db..9c86f5b 100644 --- a/setup.py +++ b/setup.py @@ -1,42 +1,19 @@ -import os - from setuptools import setup from pybind11.setup_helpers import Pybind11Extension, build_ext -FILE_DIR = os.path.dirname(os.path.abspath(__file__)) -VERSION = '1.0.1' +# TODO +VERSION = "1.0.2" ext_modules = [ - Pybind11Extension('mapbox_earcut', - ['src/main.cpp'], - include_dirs=['include'], - define_macros = [('VERSION_INFO', VERSION)], - ), + Pybind11Extension( + "mapbox_earcut", + ["src/main.cpp"], + include_dirs=["include"], + define_macros=[("VERSION_INFO", VERSION)], + ), ] -def get_readme_contents(): - with open(os.path.join(FILE_DIR, 'README.md'), 'r') as readme_file: - return readme_file.read() - setup( - name='mapbox_earcut', - version=VERSION, - url='https://github.com/skogler/mapbox_earcut_python', - author='Samuel Kogler', - author_email='samuel.kogler@gmail.com', - description= - 'Python bindings for the mapbox earcut C++ polygon triangulation library.', - long_description=get_readme_contents(), - long_description_content_type='text/markdown', - license='ISC', ext_modules=ext_modules, - install_requires=['numpy'], - extras_require={'test': 'pytest'}, cmdclass=dict(build_ext=build_ext), - zip_safe=False, - project_urls={ - 'Source': 'https://github.com/skogler/mapbox_earcut_python', - 'Original C++ Source': 'https://github.com/mapbox/earcut.hpp', - }, - include_package_data = True ) diff --git a/src/main.cpp b/src/main.cpp index daaff82..221e986 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,7 +98,6 @@ PYBIND11_MODULE(mapbox_earcut, m) m.def("triangulate_float64", &triangulate); #ifdef VERSION_INFO - m.attr("__version__") = MACRO_TO_STR(VERSION_INFO) ; #else m.attr("__version__") = "dev"; From d32238947fe11034003949bd00e0f63bb3676074 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Thu, 9 May 2024 19:50:45 -0400 Subject: [PATCH 05/16] relax versions --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 23490d3..a6bc636 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,18 +3,18 @@ requires = [ "setuptools>=42", "wheel", "pybind11~=2.6", - "numpy>=1.26.0" + "numpy>=1.19.0" ] build-backend = "setuptools.build_meta" [project] name = "mapbox_earcut" version = "1.0.2" -requires-python = ">=3.7" +requires-python = ">=3.6" authors = [{name = "Samuel Kogler", email = "samuel.kogler@gmail.com"}] license = {file = "LICENSE.md"} description = "Python bindings for the mapbox earcut C++ polygon triangulation library." -dependencies = ["numpy>=1.26.0"] +dependencies = ["numpy>=1.19.0"] [project.urls] Source = "https://github.com/skogler/mapbox_earcut_python" From 2d7a36ad92da4d8e5dce316ad4bd3e5b57c95268 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Thu, 9 May 2024 20:44:00 -0400 Subject: [PATCH 06/16] set minimum python to 3.7 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a6bc636..c3c53ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta" [project] name = "mapbox_earcut" version = "1.0.2" -requires-python = ">=3.6" +requires-python = ">=3.7" authors = [{name = "Samuel Kogler", email = "samuel.kogler@gmail.com"}] license = {file = "LICENSE.md"} description = "Python bindings for the mapbox earcut C++ polygon triangulation library." From 7865c688a4b3f88d86ad6ced207d06584d2e7647 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Thu, 9 May 2024 23:25:27 -0400 Subject: [PATCH 07/16] skip tests where numpy isn't available as wheels --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c3c53ec..f3539ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,8 @@ test-extras = ["test"] # Run the package tests using `pytest` test-command = "pytest {package}/tests && pip install --force-reinstall --upgrade --pre numpy && pytest {package}/tests" -test-skip = "*_arm64 *_universal2:arm64" + +test-skip = "*_arm64 *_universal2:arm64 pp*" [tool.cibuildwheel.macos] archs = ["x86_64", "arm64"] From 9abaf372b815e1db8f5432c90af1d737f4009120 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Fri, 10 May 2024 13:41:45 -0400 Subject: [PATCH 08/16] skip pypy --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f3539ea..ef21e7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,10 @@ test-extras = ["test"] test-command = "pytest {package}/tests && pip install --force-reinstall --upgrade --pre numpy && pytest {package}/tests" -test-skip = "*_arm64 *_universal2:arm64 pp*" +test-skip = "*_arm64 *_universal2:arm64" + +# Numpy only builds wheels for very specific versions of PyPy for some reasy +skip = "pp*" [tool.cibuildwheel.macos] archs = ["x86_64", "arm64"] From db28557fe428c77669b9e6217b96d73c8486c447 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Fri, 10 May 2024 14:18:30 -0400 Subject: [PATCH 09/16] try pinning pybind --- pyproject.toml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ef21e7c..6680a4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,8 +2,7 @@ requires = [ "setuptools>=42", "wheel", - "pybind11~=2.6", - "numpy>=1.19.0" + "pybind11==2.12.0", ] build-backend = "setuptools.build_meta" @@ -35,14 +34,16 @@ test = ["pytest"] [tool.cibuildwheel] # install the `test` extra test-extras = ["test"] -# Run the package tests using `pytest` - -test-command = "pytest {package}/tests && pip install --force-reinstall --upgrade --pre numpy && pytest {package}/tests" -test-skip = "*_arm64 *_universal2:arm64" - -# Numpy only builds wheels for very specific versions of PyPy for some reasy -skip = "pp*" +# Run the package tests using `pytest` +# also test against pre-release Numpy +# TODO : when numpy 2.0 releases this can be reduced to just one pytest +test-command = ["pytest {package}/tests", + "pip install --force-reinstall --upgrade --pre numpy", + "pytest {package}/tests"] + +# don't test on PyPy as it will re-build numpy +test-skip = "*_arm64 *_universal2:arm64 pp*" [tool.cibuildwheel.macos] archs = ["x86_64", "arm64"] From 2b8fb940348692cb3b189b53cbcd5b3d07c27b09 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Fri, 10 May 2024 15:06:11 -0400 Subject: [PATCH 10/16] use tomli for old python --- pyproject.toml | 1 + setup.py | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6680a4c..f1e845c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ requires = [ "setuptools>=42", "wheel", "pybind11==2.12.0", + "tomli>=0.10; python_version<'3.11'", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 9c86f5b..c31fa2a 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,42 @@ +import os + from setuptools import setup from pybind11.setup_helpers import Pybind11Extension, build_ext -# TODO -VERSION = "1.0.2" + +def _get_version() -> str: + """ + Get the version defined in `pyproject.toml` to prevent + requiring the version to be specified in two places. + + Note that Python only introduced a TOML parser in + Python 3.11 so this requires `pip install tomli` for older + versions of Python. + """ + try: + # we could also do this with + # if `sys.version_info >= (3, 11)` + from tomllib import load + except BaseException: + # a parser with the same API from pypi + from tomli import load + + # current working directory + cwd = os.path.abspath(os.path.expanduser(os.path.dirname(__file__))) + # file-relative pyproject path + path = os.path.join(cwd, "pyproject.toml") + with open(path, "rb") as f: + pyproject = load(f) + + return pyproject["project"]["version"] + ext_modules = [ Pybind11Extension( "mapbox_earcut", ["src/main.cpp"], include_dirs=["include"], - define_macros=[("VERSION_INFO", VERSION)], + define_macros=[("VERSION_INFO", _get_version())], ), ] From 145dd08e437ef9622ae2ef693423b1a821d20da8 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Mon, 29 Jul 2024 13:01:16 -0400 Subject: [PATCH 11/16] address suggestions and release as earcutx --- .github/workflows/build.yml | 4 ++-- pyproject.toml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e0cab3f..eaf5a7d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-22.04, windows-2019, macos-11] + os: [ubuntu-24.04, windows-2019, macos-11] steps: - uses: actions/checkout@v3 @@ -16,7 +16,7 @@ jobs: submodules: recursive - name: Build wheels - uses: pypa/cibuildwheel@v2.17.0 + uses: pypa/cibuildwheel@v2.19.2 - name: Show files run: ls -lh wheelhouse diff --git a/pyproject.toml b/pyproject.toml index f1e845c..b7588bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,15 +2,15 @@ requires = [ "setuptools>=42", "wheel", - "pybind11==2.12.0", + "pybind11>=2.12.0", "tomli>=0.10; python_version<'3.11'", ] build-backend = "setuptools.build_meta" [project] -name = "mapbox_earcut" -version = "1.0.2" -requires-python = ">=3.7" +name = "earcutx" +version = "1.0.3" +requires-python = ">=3.8" authors = [{name = "Samuel Kogler", email = "samuel.kogler@gmail.com"}] license = {file = "LICENSE.md"} description = "Python bindings for the mapbox earcut C++ polygon triangulation library." From 784c5b87780a2874d7cc09ba0f3434e37f3f44f5 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Mon, 29 Jul 2024 13:15:05 -0400 Subject: [PATCH 12/16] skip pypy --- pyproject.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b7588bc..4b027f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ requires-python = ">=3.8" authors = [{name = "Samuel Kogler", email = "samuel.kogler@gmail.com"}] license = {file = "LICENSE.md"} description = "Python bindings for the mapbox earcut C++ polygon triangulation library." -dependencies = ["numpy>=1.19.0"] +dependencies = ["numpy>=1.24.0"] [project.urls] Source = "https://github.com/skogler/mapbox_earcut_python" @@ -33,6 +33,7 @@ test = ["pytest"] [tool.cibuildwheel] +skip = "pp*" # install the `test` extra test-extras = ["test"] @@ -44,7 +45,7 @@ test-command = ["pytest {package}/tests", "pytest {package}/tests"] # don't test on PyPy as it will re-build numpy -test-skip = "*_arm64 *_universal2:arm64 pp*" +test-skip = "*_arm64 *_universal2:arm64" [tool.cibuildwheel.macos] archs = ["x86_64", "arm64"] From 6fdbf6d7a15bcb66c53ab56449aaaef645fa06a6 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Mon, 29 Jul 2024 13:23:52 -0400 Subject: [PATCH 13/16] try building on ubuntu latest --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eaf5a7d..6af7db0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-24.04, windows-2019, macos-11] + os: [ubuntu-latest, windows-2019, macos-11] steps: - uses: actions/checkout@v3 From bb1281b21f716b9624e9751688a6185fc0c0b209 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Mon, 29 Jul 2024 15:10:01 -0400 Subject: [PATCH 14/16] update macos runner --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6af7db0..37a90f4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-2019, macos-11] + os: [ubuntu-latest, windows-2019, macos-13] steps: - uses: actions/checkout@v3 From 1d379cdf4dbcfceab71a0b1f03e1dfcd174046a6 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Mon, 29 Jul 2024 16:15:42 -0400 Subject: [PATCH 15/16] release on main --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2e1d098..2cc6950 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,8 +2,8 @@ name: Release on: push: - tags: - - "v*.*.*" + branches: + - main jobs: build: From 85c0fd6d1970d3e709cc427e8a742f43e8032562 Mon Sep 17 00:00:00 2001 From: Michael Dawson-Haggerty Date: Mon, 29 Jul 2024 18:21:59 -0400 Subject: [PATCH 16/16] update test module ref --- pyproject.toml | 8 ++----- setup.py | 2 +- src/main.cpp | 4 ++-- tests/test_earcut.py | 50 ++++++++++++++++++++++---------------------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4b027f2..885cff2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta" [project] name = "earcutx" -version = "1.0.3" +version = "1.0.4" requires-python = ">=3.8" authors = [{name = "Samuel Kogler", email = "samuel.kogler@gmail.com"}] license = {file = "LICENSE.md"} @@ -38,11 +38,7 @@ skip = "pp*" test-extras = ["test"] # Run the package tests using `pytest` -# also test against pre-release Numpy -# TODO : when numpy 2.0 releases this can be reduced to just one pytest -test-command = ["pytest {package}/tests", - "pip install --force-reinstall --upgrade --pre numpy", - "pytest {package}/tests"] +test-command = "pytest {package}/tests" # don't test on PyPy as it will re-build numpy test-skip = "*_arm64 *_universal2:arm64" diff --git a/setup.py b/setup.py index c31fa2a..8916bb8 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ def _get_version() -> str: ext_modules = [ Pybind11Extension( - "mapbox_earcut", + "earcutx", ["src/main.cpp"], include_dirs=["include"], define_macros=[("VERSION_INFO", _get_version())], diff --git a/src/main.cpp b/src/main.cpp index 221e986..1309f64 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,13 +77,13 @@ py::array_t triangulate(py::array_t vertices, py::array_t