Skip to content

Numpy 2.0 Wheels #15

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]
os: [ubuntu-latest, windows-2019, macos-13]

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_TEST_SKIP: "*_arm64 *_universal2:arm64"
uses: pypa/[email protected]

- name: Show files
run: ls -lh wheelhouse
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Release

on:
push:
tags:
- "v*.*.*"
branches:
- main

jobs:
build:
Expand Down
42 changes: 41 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@
requires = [
"setuptools>=42",
"wheel",
"pybind11~=2.6",
"pybind11>=2.12.0",
"tomli>=0.10; python_version<'3.11'",
]
build-backend = "setuptools.build_meta"

[project]
name = "earcutx"
version = "1.0.4"
requires-python = ">=3.8"
authors = [{name = "Samuel Kogler", email = "[email protected]"}]
license = {file = "LICENSE.md"}
description = "Python bindings for the mapbox earcut C++ polygon triangulation library."
dependencies = ["numpy>=1.24.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]
skip = "pp*"
# install the `test` extra
test-extras = ["test"]

# Run the package tests using `pytest`
test-command = "pytest {package}/tests"

# don't test on PyPy as it will re-build numpy

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this workin PyPy at all? I give up on that on the conda-forge build.

test-skip = "*_arm64 *_universal2:arm64"

[tool.cibuildwheel.macos]
archs = ["x86_64", "arm64"]
62 changes: 33 additions & 29 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,44 @@
from setuptools import setup

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we really should move to a "modern" build -- e.g. not putting code in setup.py.

maybe even scikit build?

from pybind11.setup_helpers import Pybind11Extension, build_ext

FILE_DIR = os.path.dirname(os.path.abspath(__file__))
VERSION = '1.0.1'

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)],
),
Pybind11Extension(
"earcutx",
["src/main.cpp"],
include_dirs=["include"],
define_macros=[("VERSION_INFO", _get_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='[email protected]',
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
)
5 changes: 2 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ py::array_t<IndexT> triangulate(py::array_t<CoordT> vertices, py::array_t<IndexT
);
}

PYBIND11_MODULE(mapbox_earcut, m)
PYBIND11_MODULE(earcutx, m)
{
m.doc() = R"pbdoc(
Python bindings to mapbox/earcut.hpp
-----------------------

.. currentmodule:: mapbox_earcut
.. currentmodule:: earcutx

.. autosummary::
:toctree: _generate
Expand All @@ -98,7 +98,6 @@ PYBIND11_MODULE(mapbox_earcut, m)
m.def("triangulate_float64", &triangulate<double, uint32_t>);

#ifdef VERSION_INFO

m.attr("__version__") = MACRO_TO_STR(VERSION_INFO) ;
#else
m.attr("__version__") = "dev";
Expand Down
50 changes: 25 additions & 25 deletions tests/test_earcut.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mapbox_earcut as earcut
import earcutx
import numpy as np
import pytest

Expand All @@ -7,66 +7,66 @@ def test_valid_triangulation_float32():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.float32).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


def test_valid_triangulation_float64():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.float64).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


def test_valid_triangulation_int32():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.int32).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


def test_inverted_vertex_order():
verts = np.array(
list(reversed([[0, 0], [1, 0], [1, 1]])), dtype=np.int32).reshape(
-1, 2)
verts = np.array(list(reversed([[0, 0], [1, 0], [1, 1]])), dtype=np.int32).reshape(
-1, 2
)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 0, 2]))


def test_no_triangles():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.int32).reshape(-1, 2)
rings = np.array([2, 3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (0, )
assert result.shape == (0,)


def test_valid_triangulation_int64():
verts = np.array([[0, 0], [1, 0], [1, 1]], dtype=np.int64).reshape(-1, 2)
rings = np.array([3])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.dtype == np.uint32
assert result.shape == (3, )
assert result.shape == (3,)
assert np.all(result == np.array([1, 2, 0]))


Expand All @@ -75,61 +75,61 @@ def test_end_index_too_large():
rings = np.array([5])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_end_index_too_small():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([2])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_end_index_neg():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([-1])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_rings_not_increasing():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([3, 0, 3])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_rings_same():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([3, 3])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_no_rings():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)


def test_no_rings():
verts = np.array([[0, 0], [1, 0], [1, 1]]).reshape(-1, 2)
rings = np.array([])

with pytest.raises(ValueError):
result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float64(verts, rings)


def test_empty_data():
verts = np.array([]).reshape(-1, 2)
rings = np.array([])

result = earcut.triangulate_float32(verts, rings)
result = earcutx.triangulate_float32(verts, rings)

assert result.shape == (0, )
assert result.shape == (0,)
Loading