Bug 405796 - Python scripting broken (PyQt5 not found by CMake)
Summary: Python scripting broken (PyQt5 not found by CMake)
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Scripting (show other bugs)
Version: nightly build (please specify the git hash!)
Platform: Microsoft Windows Microsoft Windows
: NOR critical
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-24 04:19 UTC by Alvin Wong
Modified: 2019-03-26 09:30 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alvin Wong 2019-03-24 04:19:07 UTC
Since some time before nightly build 27678b4ca0 (#494), PyQt5 is not detected when building Krita.

[2019-03-23T08:22:39.918Z]   File "C:/Packaging/workspace/Krita_Nightly_Windows_Build/krita/cmake/modules/FindPyQt5.py", line 9, in <module>
[2019-03-23T08:22:39.918Z]     print("pyqt_version:%06.0x" % PyQt5.Qt.PYQT_VERSION)
[2019-03-23T08:22:39.918Z] AttributeError: module 'PyQt5.Qt' has no attribute 'PYQT_VERSION'

I suspect it needs to be PyQt5.QtCore.PYQT_VERSION instead, but I don't know if it is a change since some version of PyQt5 or if there is a bug in the toolchain. Anyway, whatever change to this will need to be verified on all platforms.
Comment 1 Rebecca Breu 2019-03-24 10:00:24 UTC
Finding your PyQT isn't the issue, it's that there seems to be something weird about it. I cannot reproduce this with PyQT 5.9.2 nor the most recent 5.12.1. Which version of PyQT are you building against?
Comment 2 Halla Rempt 2019-03-24 12:20:16 UTC
This is the nightly Windows build, so it's using the 3rdpary/ext_pyqt definition, which uses https://www.riverbankcomputing.com/static/Downloads/PyQt5/PyQt5_gpl-5.12.1.zip
Comment 3 Rebecca Breu 2019-03-24 12:41:58 UTC
If PyQt5.QtCore.PYQT_VERSION works for that version, there is no reason not to switch to that. In fact, it seems to be the cleaner solution as it looks like that is where PYQT_VERSION etc are defined in the first place. Works on both my installations.
Comment 4 Alvin Wong 2019-03-26 08:07:40 UTC
So it looks like PyQt5 is now requiring a private copy of the sip module. From the changelog:

2018-06-17  Phil Thompson  <phil@riverbankcomputing.com>

	* lib/configure.py, rb-product:
	Use a private copy of the sip module. SIP v4.19.9 is now required.
	[7c9bae40b66c]

Simply copying the `sip.pyd` into `PyQt5/` doesn't seem to work (resulted in `ValueError: PyCapsule_GetPointer called with incorrect name`).

As Ivanyossi pointed out on IRC, according to the docs [1], I need to add `--sip-module PyQt5.sip` to configure sip. However, in this case it doesn't install the "legacy" top-level `sip` module unlike what the docs seem to imply, even though the `--no-module` option wasn't passed.

With this change, Krita can again compile with Python scripting and the scripts does seem to work. But I can find two places in Krita that tries to `import sip` [2] [3] and I can't tell if they would be working as expected with this change.

I also found that Boud had made this change in the past but backed out of it [4]. Boud, do you remember why you backed out of it?

[1]: https://www.riverbankcomputing.com/static/Docs/sip/installation.html#ref-private-sip
[2]: https://github.com/KDE/krita/blob/44080b7b7af892e410bf3bb5b2f19ea785f760fb/plugins/extensions/pykrita/plugin/krita/attic/mikro.py#L30
[3]: https://github.com/KDE/krita/blob/44080b7b7af892e410bf3bb5b2f19ea785f760fb/plugins/extensions/pykrita/plugin/utilities.cpp#L92
[4]: https://github.com/KDE/krita/commit/93a2b48e3a0bf1251deaaf84263a76d846c39cef
Comment 5 Halla Rempt 2019-03-26 08:33:48 UTC
mikro.py isn't used atm, as far as I remember. I'm not sure why I removed the private sip stuff; I think I was only experimenting with it.
Comment 6 Alvin Wong 2019-03-26 08:55:57 UTC
(In reply to Boudewijn Rempt from comment #5)
> mikro.py isn't used atm, as far as I remember. I'm not sure why I removed
> the private sip stuff; I think I was only experimenting with it.

Ok. Should I be worried of that piece of code with `import sip` in utilities.cpp? It looks like it's setting some parameters, but I don't know what it actually does.
Comment 7 Halla Rempt 2019-03-26 09:03:24 UTC
That's a bit of a poser. For Python 3, we don't need that code, since the new API is selected by default in python 3. But we're vaguely compatible with Python 2, where this is needed.
Comment 8 Alvin Wong 2019-03-26 09:30:22 UTC
Git commit 331beffd5332ecfed95a8ca4ba2bfee56fedad47 by Alvin Wong.
Committed on 26/03/2019 at 09:24.
Pushed by alvinwong into branch 'master'.

Fix Python scripting broken by new pyqt and sip

PyQt5 started requiring a private copy of the sip module, so we have to
build sip as a private sip module for PyQt5.

M  +2    -1    3rdparty/ext_sip/CMakeLists.txt
M  +3    -0    plugins/extensions/pykrita/plugin/krita/attic/mikro.py
M  +4    -0    plugins/extensions/pykrita/plugin/utilities.cpp

https://commits.kde.org/krita/331beffd5332ecfed95a8ca4ba2bfee56fedad47