Repository navigation
Replace Boost.Python with pybind11 - #176
Conversation
Note: Moved BatchDropCutter::getTrianglesUnderCutter to pure cpp implementation
This reverts commit e894a13.
|
Hi @aewallin @vespakoen, just following up on this PR. If either of you happens to have some spare time, would you mind giving it a look or testing it out? I’d be happy to make any necessary changes. Thanks in advance! |
|
Hi @CalaW - not sure what you needed from this lib, but I built a set of wheels from your branch for Python 3.13 and uploaded them here if you want them: https://github.com/SpectralVectors/opencamlib/releases/tag/Python313_Wheels |
|
Cool! I will take a look at this next week, I hope to also upgrade Boost to the modern version which should remove a lot of the install script. |
|
Hi @vespakoen, Thanks for taking a look! Yes, Boost is still required. This PR only replaces Boost.Python with pybind11. We still use Boost.Graph, for example boost/graph/adjacency_list.hpp. I have already replaced some uses of BOOST_FOREACH, boost::tie, and Boost.Math with the standard library. I can also make another PR to replace the remaining ones. |
|
Removing boost completely would be great, it saves a lot of hassle with their somewhat weird build system. Boost did gain some better compatibility with CMake though, which might help. Maybe getting rid of Boost completely should be a follow up PR, I'd focus on getting this to work on all the platforms. Will look into this soon... |
|
Did you also consider nanobind? (https://github.com/wjakob/nanobind) it seems to be very similar in syntax so might be worth a try? |
|
Yes, I did consider nanobind. At that time, it was still relatively new, while pybind11 was already the de facto standard and had a much larger user base (3.4k vs 18k star). From what I have seen, nanobind does have some advantages, especially smaller binaries and lower binding overhead. However, for ocl, I believe most of the heavy computation happens in C++, so I don’t expect the Python binding overhead to be a bottleneck. |
|
I opened a pull request to your fork, If that lands I think I am fine with merging this. Let me know what you all think ;) EDIT: Just saw that the README also needs some updating |
|
Thanks! I will check your PR and update the README as well. I am not fully sure that the Python API is completely stable, because the project currently does not have a complete test framework for checking API compatibility. I run all python examples and test file and they looked fine. I tried to keep the exposed classes, functions, and method names the same, but there may still be some behavior differences. For example, opencamlib/src/pythonlib/adaptivewaterline_py.hpp Lines 50 to 60 in 95b036f However, the underlying C++ implementation inherits the behavior from Waterline, which returns the complete list: opencamlib/src/pythonlib/waterline_py.hpp Lines 53 to 61 in 95b036f In the pybind11 version, I preserved the behavior of the C++ implementation instead but it's still easy to modify. Speaking of versioning, I noticed that the current versioning seems to be date-based, with the latest release being |
…` without segfault
The previous Boost.Python override support for `MillingCutter` was incomplete and effectively unusable: - `vertexDrop` was not virtual, so Python overrides were never called by `dropCutter()`. - Several required virtual functions (e.g. height/width queries) were not exposed, making it impossible to implement a complete custom cutter. - `offsetCutter()` returns an owning raw pointer, which is incompatible with Python object lifetime and could lead to dangling pointers or crashes. Even if these issues were addressed, overriding the low-level contact routines from Python would not be a practical or useful extension mechanism. The API was introduced incorrectly and is not known to have been used, so removing it does not introduce a compatibility concern.
Stop creating and activating a project-local virtual environment. Install and test with the currently selected Python executable instead.
- add GIL release - remove CCType package level export - change some python constructor signature to match cpp
- Use a local TSP graph to prevent leaks and double frees - Reset tour state between runs and handle empty/singleton inputs - Restore EllipsePosition's default constructor and type annotation - Make offset cutter ownership explicit and adjust fiber return policy - Normalize binding source formatting
|
Here's a full review by GPT-6 Astra: This PR replaces Boost.Python with pybind 11, simplifies packaging, and fixes several build and lifetime issues. This summary includes the current local follow-ups.
The Python migration includes observable API changes, beyond replacing the binding framework:
Compatibility checks found matching geometry in the tested BlenderCAM and FreeCAD scenarios. Waterline loop starting points and component order can differ, which may affect entry/travel positions even when contours match; exact historical ordering is not guaranteed. |
|
Hi @vespakoen I think this PR is ready to merge. I’ve run extensive compatibility tests on the Python bindings and documented the intentional behavior changes. I’ve also updated the README and CI/CD workflows, fixed the build issues we encountered. |
|
The python compatibility tests includes all 255 inventoried public Python API members, including methods, constructors, and properties, plus object lifetimes and representative BlenderCAM and FreeCAD usage patterns. See this commit. |
|
Great stuff! I am fine with merging this in. @aewallin any objections to this? |
|
FWIW, I built and tested the FreeCAD unit test suite against the PR branch. Everything is green on our side. Going beyond this, @aewallin might not have time or interest to maintain this library. If he's interested in some help, we could suggest moving to a github organization that he controls where he could add contributors to help. I'm pretty weak on the C++ but willing to test, advise, and cheer people on. :-) |
|
Hey @sliptonic thanks for testing on FreeCAD. And thank you @vespakoen for reviewing this, glad to see this finally merged! |
|
I would be happy to have you onboard as a contributer, this is for aewallin to decide though, you got my vote anyways ;) I was added as a contributor at some point to this repository, which seems to work fine. Are there any advantages to having a github organisation for this? |
|
An organization can outlive an individual account. Multiple owners are possible. Basically, It reduces the bus factor. Otherwise, not necessary. |
This PR replaces Boost.Python with pybind11, which has become the de facto standard for Python bindings in C++.
Key improvements:
This should resolve #164 and close #180.