Skip to content

Commit

Permalink
python stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Aug 23, 2023
1 parent 111350f commit 13ae702
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 15 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build

on: [push, pull_request]

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-latest, macos-latest]
steps:
- run: git config --global submodule.fetchJobs 8
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Build wheels
uses: pypa/cibuildwheel@v2.14.1
with:
package-dir: bindings/python
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl


27 changes: 20 additions & 7 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,29 @@
project(python)

add_subdirectory(third_party)
pybind11_add_module(manifold3d manifold3d.cpp)
target_link_libraries(manifold3d PRIVATE manifold)
target_compile_options(manifold3d PRIVATE ${MANIFOLD_FLAGS})
target_compile_features(manifold3d PUBLIC cxx_std_17)
target_include_directories(manifold3d
if(SKBUILD)
set(module_name _manifold3d)
else()
set(module_name manifold3d)
endif()
pybind11_add_module(${module_name} manifold3d.cpp)
target_link_libraries(${module_name} PRIVATE manifold)
target_compile_options(${module_name} PRIVATE ${MANIFOLD_FLAGS}
-DMODULE_NAME=${module_name})
target_compile_features(${module_name} PUBLIC cxx_std_17)
target_include_directories(${module_name}
PRIVATE ${PYBIND11_DIR}/include
)
set_target_properties(manifold3d PROPERTIES OUTPUT_NAME "manifold3d")
set_target_properties(${module_name} PROPERTIES OUTPUT_NAME "${module_name}")
if(SKBUILD)
install(
TARGETS manifold3d
TARGETS ${module_name}
LIBRARY DESTINATION .
)
else()
install(
TARGETS ${module_name}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
COMPONENT bindings
)
endif()
12 changes: 6 additions & 6 deletions bindings/python/examples/extrude.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from manifold3d import CrossSection, FillRule
from manifold3d import CrossSection


def run():
Expand All @@ -11,28 +11,28 @@ def run():
polygons = cross_section.to_polygons()
polygon = polygons[0]
if set(polygon) != set(polygon_points):
raise Exception(f"{polygon=} differs from {polygon_points=}")
raise Exception(f"polygon={polygon} differs from polygon_points={polygon_points}")

# extrude a polygon to create a manifold
extruded_polygon = cross_section.extrude(10.0)
eps = 0.001
observed_volume = extruded_polygon.get_volume()
expected_volume = 10.0
if abs(observed_volume - expected_volume) > eps:
raise Exception(f"{observed_volume=} differs from {expected_volume=}")
raise Exception(f"observed_volume={observed_volume} differs from expected_volume={expected_volume}")
observed_surface_area = extruded_polygon.get_surface_area()
expected_surface_area = 42.0
if abs(observed_surface_area - expected_surface_area) > eps:
raise Exception(f"{observed_surface_area=} differs from {expected_surface_area=}")
raise Exception(f"observed_surface_area={observed_surface_area} differs from expected_surface_area={expected_surface_area}")

# get bounding box from manifold
observed_bbox = extruded_polygon.bounding_box
expected_bbox = (0.0, 0.0, 0.0, 1.0, 1.0, 10.0)
if observed_bbox != expected_bbox:
raise Exception(f"{observed_bbox=} differs from {expected_bbox=}")
raise Exception(f"observed_bbox={observed_bbox} differs from expected_bbox={expected_bbox}")

return extruded_polygon


if __name__ == "__main__":
run()
run()
2 changes: 1 addition & 1 deletion bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ std::vector<T> toVector(const py::array_t<T> &arr) {
return std::vector<T>(arr.data(), arr.data() + arr.size());
}

PYBIND11_MODULE(manifold3d, m) {
PYBIND11_MODULE(MODULE_NAME, m) {
m.doc() = "Python binding for the Manifold library.";

m.def("set_min_circular_angle", Quality::SetMinCircularAngle,
Expand Down
1 change: 1 addition & 0 deletions bindings/python/manifold3d/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from ._manifold3d import *
46 changes: 46 additions & 0 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[project]
name = "manifold3d"
version = "2.2.0"
authors = [
{ name="Emmett Lalish", email="elalish@gmail.com" },
]
description = "Library for geometric robustness"
readme = "README.md"
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: C++",
"Topic :: Multimedia :: Graphics :: 3D Modeling",
]
requires-python = ">=3.7"

[project.urls]
"Homepage" = "https://github.com/elalish/manifold"
"Bug Tracker" = "https://github.com/elalish/manifold/issues"

[build-system]
requires = [
"setuptools",
"scikit-build>=0.13",
"cmake",
"ninja",
]
build-backend = "setuptools.build_meta"

[tool.cibuildwheel]
test-requires = ["trimesh"]
test-command = "python {project}/bindings/python/examples/run_all.py"
# Setuptools bug causes collision between pypy and cpython artifacts
before-build = "rm -rf {project}/build"
manylinux-x86_64-image = "manylinux_2_28"
musllinux-x86_64-image = "musllinux_1_2"
skip = ["*-win32", "*_i686", "pp*"]

[tool.cibuildwheel.macos]
archs = ["x86_64", "arm64"]
environment = "MACOSX_DEPLOYMENT_TARGET=10.14"

[tool.cibuildwheel.windows]
before-build = "pip install delvewheel"
repair-wheel-command = "delvewheel repair -w {dest_dir} {wheel}"
13 changes: 13 additions & 0 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from skbuild import setup

setup(
name="manifold3d",
version="2.2.0",
description=" Geometry library for topological robustness",
author="Emmett Lalish",
packages=["manifold3d"],
cmake_install_dir="manifold3d",
cmake_source_dir="../../",
zip_safe=True,
cmake_args=["-DMANIFOLD_PAR=TBB"],
)
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}: pkgs.stdenv.mkDerivation {
inherit doCheck;
pname = "manifold-${parallel-backend}";
version = "beta";
version = "2.2.0";
src = self;
nativeBuildInputs = (with pkgs; [
cmake
Expand Down

0 comments on commit 13ae702

Please sign in to comment.