coin3d / pivy

python bindings to coin3d
ISC License
53 stars 37 forks source link

Pivy Python 3.10/3.11 compatibility? #88

Closed hobbes1069 closed 2 years ago

hobbes1069 commented 2 years ago

As reported in the FreeCAD forums[1], the guess is that this is a Python compatibility issue...

Excerpt here:

0.19, Dimension013, added view property 'ScaleMultiplier'
Traceback (most recent call last):
  File "/usr/lib64/freecad/Mod/Draft/draftviewproviders/view_dimension.py", line 701, in onChanged
    self.font.size = vobj.FontSize.Value * vobj.ScaleMultiplier
  File "/usr/lib64/python3.10/site-packages/pivy/coin.py", line 3998, in __setattr__
    field = self.getField(name)
  File "/usr/lib64/python3.10/site-packages/pivy/coin.py", line 3873, in getField
    return _coin.SoFieldContainer_getField(self, name)
<class 'SystemError'>: <built-in function SoFieldContainer_getField> returned a result with an exception set
v0.19, Dimension014, added view property 'ScaleMultiplier'

Fedora 35 has Python 3.10 but future Fedora 36 will have Python 3.11...

looooo commented 2 years ago

Can you try running the privy test?

hobbes1069 commented 2 years ago

Sure, what's the command? I'm using CMake for the build system.

Is it built in, or do I just need to run the test files with python?

hobbes1069 commented 2 years ago

I ran the tests against my installed package and unsurprisingly there are errors: https://hobbes1069.fedorapeople.org/coin_tests.log

looooo commented 2 years ago

I am currently stuck with python3.10 update at pyside2. Therefore it most likely need some time until I can test privy with python 3.10.

hobbes1069 commented 2 years ago

Me too. I've worked through some of it though. https://src.fedoraproject.org/rpms/python-pyside2/blob/rawhide/f/python3.10.patch

I have some more but haven't committed it yet.

$ cat pyside-python310.patch
Index: pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/basewrap                                     per.cpp
===================================================================
--- pyside-setup-opensource-src-5.15.2.orig/sources/shiboken2/libshiboken/basewr                                     apper.cpp
+++ pyside-setup-opensource-src-5.15.2/sources/shiboken2/libshiboken/basewrapper                                     .cpp
@@ -366,7 +366,7 @@ SbkObjectType *SbkObject_TypeF(void)
     static PyTypeObject *type = nullptr;
     if (!type) {
         type = reinterpret_cast<PyTypeObject *>(SbkType_FromSpec(&SbkObject_Typ                                     e_spec));
-        Py_TYPE(type) = SbkObjectType_TypeF();
+        Py_SET_TYPE(type, SbkObjectType_TypeF());
         Py_INCREF(Py_TYPE(type));
         type->tp_weaklistoffset = offsetof(SbkObject, weakreflist);
         type->tp_dictoffset = offsetof(SbkObject, ob_dict);
@@ -1110,7 +1110,7 @@ introduceWrapperType(PyObject *enclosing
     typeSpec->slots[0].pfunc = reinterpret_cast<void *>(baseType ? baseType : S                                     bkObject_TypeF());

     PyObject *heaptype = SbkType_FromSpecWithBases(typeSpec, baseTypes);
-    Py_TYPE(heaptype) = SbkObjectType_TypeF();
+    Py_SET_TYPE(heaptype, SbkObjectType_TypeF());
     Py_INCREF(Py_TYPE(heaptype));
     auto *type = reinterpret_cast<SbkObjectType *>(heaptype);
 #if PY_VERSION_HEX < 0x03000000
looooo commented 2 years ago

Great, I will try the patches. Which version of pyside2 / qt are you compiling?

looooo commented 2 years ago

Not sure if it makes a lot of sense to backport these changes. Maybe it's better to wait for a newer qt / pyside2 version to be packaged for conda-forge. I guess qt6.x and pyside2 6.x will have python 3.10 support.

hobbes1069 commented 2 years ago

Pyside2 5.15.2 Qt 5.15.2

Yes, the first patch was backported from a Pyside2 6.x commit. I don't know how much work they will put into Pyside2 5.x at this point, but is FreeCAD compatible with Qt6? I don't even want to think about migrating all of Fedora :)

looooo commented 2 years ago

Yep, I see the troubles. I will try to patch pyside 5.13 to work with python 3.10. once done I will come back to this issue.

hobbes1069 commented 2 years ago

Sounds good. I played around with trying to find python related commits from 6.2.2 and try to backport but it became a rabbit hole and I had to give up.

looooo commented 2 years ago

@hobbes1069 conda-forge is updating to qt5.15 so we can work on the same issue. I asked a question @ gitter. I hope someone takes care of this issue: https://gitter.im/PySide/pyside2?at=61bb76659a9ec834fbd1c865

hawkmoth commented 2 years ago

@hobbes1069 It looks like the FreeCAD issue is partly related to Coin3 vs. Coin4. The fc35 pivy is built against Coin4, while the FreeCAD modules seem to be using the Coin3 API (???).

$>dnf repoquery --provides Coin3
Last metadata expiration check: 3:06:45 ago on Fri 31 Dec 2021 07:18:25 PM PST.
Coin3 = 3.1.3-29.fc35
Coin3(x86-32) = 3.1.3-29.fc35
Coin3(x86-64) = 3.1.3-29.fc35
libCoin.so.60
libCoin.so.60()(64bit)**                 <===
$> dnf repoquery --provides Coin4
Last metadata expiration check: 3:08:23 ago on Fri 31 Dec 2021 07:18:25 PM PST.
Coin4 = 4.0.0-9.fc35
Coin4(x86-32) = 4.0.0-9.fc35
Coin4(x86-64) = 4.0.0-9.fc35
libCoin.so.80
libCoin.so.80()(64bit)                    <=== 
dnf repoquery --requires python3-pivy
Last metadata expiration check: 3:09:46 ago on Fri 31 Dec 2021 07:18:25 PM PST.
/usr/bin/python3
libCoin.so.80()(64bit)                    <===
libSoQt.so.20()(64bit)
libc.so.6(GLIBC_2.14)(64bit)
libgcc_s.so.1()(64bit)
libgcc_s.so.1(GCC_3.0)(64bit)
libgcc_s.so.1(GCC_3.3.1)(64bit)
libstdc++.so.6()(64bit)
libstdc++.so.6(CXXABI_1.3)(64bit)
libstdc++.so.6(CXXABI_1.3.8)(64bit)
libstdc++.so.6(CXXABI_1.3.9)(64bit)
libstdc++.so.6(GLIBCXX_3.4)(64bit)
python(abi) = 3.10
rtld(GNU_HASH)

The following works just fine in the FreeCAD Python console:

from pivy import coin
doc = App.newDocument("testpivy")
view = Gui.ActiveDocument.ActiveView 
sg=view.getScenegraph()
sg.addChild(coin.SoCube())

This minimum excerpt from the Draft workbench code produces an error similar to the above:

pick = coin.SoPickStyle()
pick.style.setValue(coin.SoPickStyle.UNPICKABLE)

The issue is that the style attribute does not exist. Which may be due to incompatible APIs between Coin3 and Coin4 (I do not know either one).

ipatch commented 2 years ago

a couple of use noticed similar issues on macos as well. those of us who building and install freecad on macos with macos homebrew have seen issues related to python 3.10

it appears shiboken2 v5.15.2 will not compile / build with the latest python 3.10

https://github.com/FreeCAD/homebrew-freecad/issues/267#issuecomment-1003179443

there was a bug reported upstream below,

https://bugreports.qt.io/browse/PYSIDE-1436


i mention all of this because apparently python 3.10 has introduced some changes that aren't compatible with libraries like shiboken2 in its current state unfortunately. and i doubt the upstream qt maintainers are gunna wanna back port fixes to get shiboken2 v5.15.2 and pyside2 v5.15.2 to work with python 3.10

antonok-edm commented 2 years ago

In case anyone here is itching to get back to work on their FreeCAD projects, https://github.com/coin3d/pivy/pull/91 should do the trick!

adrianinsaval commented 2 years ago

From what version onwards is pivy compatible with python 3.10, is it 0.6.6?

antonok-edm commented 2 years ago

@adrianinsaval it should be in 0.6.7.