From 52dfd67a198ddeb21aa0463f072a697f8bb1da6f Mon Sep 17 00:00:00 2001 From: tmontaigu Date: Sun, 14 Dec 2025 23:15:18 +0100 Subject: [PATCH] Upgrade to pybind11 3.0 First step of the upgrade process. The smart_holder capabilities are probably going to interest us. Some py::enum_ where empty, this made 'finalization' of pybind11's internals fail, so we had to populate these enums. --- cmake/PythonEnvHelper.cmake | 2 +- requirements-dev.txt | 2 +- requirements-release.txt | 2 +- src/PythonRepl.cpp | 2 +- src/Runtime/Runtime.cpp | 22 +++++++++++++++++++++- src/Runtime/ccCommandLine.cpp | 8 +++++++- wrapper/pycc/src/pycc.cpp | 27 +++++++++++++++++++++++++-- 7 files changed, 57 insertions(+), 8 deletions(-) diff --git a/cmake/PythonEnvHelper.cmake b/cmake/PythonEnvHelper.cmake index a6be07cf..0ea97229 100644 --- a/cmake/PythonEnvHelper.cmake +++ b/cmake/PythonEnvHelper.cmake @@ -1,6 +1,6 @@ macro(ensure_pybind11_cmake_module_is_in_path) execute_process( - COMMAND "${Python_EXECUTABLE}" "-m" "pybind11" "--cmake" + COMMAND "${Python_EXECUTABLE}" "-m" "pybind11" "--cmakedir" RESULT_VARIABLE _PYTHON_SUCCESS OUTPUT_VARIABLE PYBIND11_CMAKE_MODULES_PATH ) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7a69a857..f40c9cd9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,5 @@ numpy>=2.0 -pybind11>=2.13.0 +pybind11>=3.0 sphinx>=8.0.0 sphinx-rtd-theme pytest>=8.0.0 diff --git a/requirements-release.txt b/requirements-release.txt index a5403c44..edd97d67 100644 --- a/requirements-release.txt +++ b/requirements-release.txt @@ -1,2 +1,2 @@ numpy>=2.0 -pybind11>=2.13.0 +pybind11>=3.0 diff --git a/src/PythonRepl.cpp b/src/PythonRepl.cpp index 527982af..c7182bce 100644 --- a/src/PythonRepl.cpp +++ b/src/PythonRepl.cpp @@ -195,8 +195,8 @@ void PythonRepl::reset() void PythonRepl::importNeededPackages() { - executeCode(replArrows + "import pycc"); executeCode(replArrows + "import cccorelib"); + executeCode(replArrows + "import pycc"); executeCode(replArrows + "cc = pycc.GetInstance()"); } diff --git a/src/Runtime/Runtime.cpp b/src/Runtime/Runtime.cpp index 6e8de624..d033e8f3 100644 --- a/src/Runtime/Runtime.cpp +++ b/src/Runtime/Runtime.cpp @@ -126,7 +126,27 @@ void unsetCmdLineInterfaceInstance() noexcept PYBIND11_EMBEDDED_MODULE(ccinternals, m) { - py::enum_(m, "GlobalColor"); + py::enum_(m, "GlobalColor") + .value("color0", Qt::color0) + .value("color1", Qt::color1) + .value("black", Qt::black) + .value("white", Qt::white) + .value("darkGray", Qt::darkGray) + .value("gray", Qt::gray) + .value("lightGray", Qt::lightGray) + .value("red", Qt::red) + .value("green", Qt::green) + .value("blue", Qt::blue) + .value("cyan", Qt::cyan) + .value("magenta", Qt::magenta) + .value("yellow", Qt::yellow) + .value("darkRed", Qt::darkRed) + .value("darkGreen", Qt::darkGreen) + .value("darkBlue", Qt::darkBlue) + .value("darkCyan", Qt::darkCyan) + .value("darkMagenta", Qt::darkMagenta) + .value("darkYellow", Qt::darkYellow) + .value("transparent", Qt::transparent); py::class_(m, "QColor"); diff --git a/src/Runtime/ccCommandLine.cpp b/src/Runtime/ccCommandLine.cpp index f5f30a8b..a706ce9d 100644 --- a/src/Runtime/ccCommandLine.cpp +++ b/src/Runtime/ccCommandLine.cpp @@ -60,7 +60,13 @@ void define_ccCommandLine(py::module &m) py::class_ PyccCommandLineInterface(m, "ccCommandLineInterface"); - py::enum_(PyccCommandLineInterface, "ExportOption"); + py::enum_( + PyccCommandLineInterface, "ExportOption", py::arithmetic()) + .value("NoOptions", ccCommandLineInterface::ExportOption::NoOptions) + .value("ForceCloud", ccCommandLineInterface::ExportOption::ForceCloud) + .value("ForceMesh", ccCommandLineInterface::ExportOption::ForceMesh) + .value("ForceHierarchy", ccCommandLineInterface::ExportOption::ForceHierarchy) + .value("ForceNoTimestamp", ccCommandLineInterface::ExportOption::ForceNoTimestamp); py::class_ PyGlobalShiftOptions( PyccCommandLineInterface, "GlobalShiftOptions"); diff --git a/wrapper/pycc/src/pycc.cpp b/wrapper/pycc/src/pycc.cpp index 8f3e165e..52d1076b 100644 --- a/wrapper/pycc/src/pycc.cpp +++ b/wrapper/pycc/src/pycc.cpp @@ -132,8 +132,31 @@ void define_someQtThings(py::module &m) }); py::class_(m, "QPointF"); - // TODO: https://doc.qt.io/qt-5/qt.html#CursorShape-enum - py::enum_(m, "QtCursorShape"); + py::enum_(m, "QtCursorShape") + .value("ArrowCursor", Qt::CursorShape::ArrowCursor) + .value("UpArrowCursor", Qt::CursorShape::UpArrowCursor) + .value("CrossCursor", Qt::CursorShape::CrossCursor) + .value("WaitCursor", Qt::CursorShape::WaitCursor) + .value("IBeamCursor", Qt::CursorShape::IBeamCursor) + .value("SizeVerCursor", Qt::CursorShape::SizeVerCursor) + .value("SizeHorCursor", Qt::CursorShape::SizeHorCursor) + .value("SizeBDiagCursor", Qt::CursorShape::SizeBDiagCursor) + .value("SizeFDiagCursor", Qt::CursorShape::SizeFDiagCursor) + .value("SizeAllCursor", Qt::CursorShape::SizeAllCursor) + .value("BlankCursor", Qt::CursorShape::BlankCursor) + .value("SplitVCursor", Qt::CursorShape::SplitVCursor) + .value("SplitHCursor", Qt::CursorShape::SplitHCursor) + .value("PointingHandCursor", Qt::CursorShape::PointingHandCursor) + .value("ForbiddenCursor", Qt::CursorShape::ForbiddenCursor) + .value("WhatsThisCursor", Qt::CursorShape::WhatsThisCursor) + .value("BusyCursor", Qt::CursorShape::BusyCursor) + .value("OpenHandCursor", Qt::CursorShape::OpenHandCursor) + .value("ClosedHandCursor", Qt::CursorShape::ClosedHandCursor) + .value("DragCopyCursor", Qt::CursorShape::DragCopyCursor) + .value("DragLinkCursor", Qt::CursorShape::DragLinkCursor) + .value("LastCursor", Qt::CursorShape::LastCursor) + .value("BitmapCursor", Qt::CursorShape::BitmapCursor) + .value("CustomCursor", Qt::CursorShape::CustomCursor); } void define_pycc(py::module &m)