Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaced sip #450

Closed
opoplawski opened this issue Sep 20, 2019 · 6 comments
Closed

Namespaced sip #450

opoplawski opened this issue Sep 20, 2019 · 6 comments

Comments

@opoplawski
Copy link
Contributor

Forwarded from: https://bugzilla.redhat.com/show_bug.cgi?id=1753414

python-pyface currently includes code that explicitly loads non-namespaced sip module,

yface/ui/qt4/workbench/split_tab_widget.py: import sip
pyface/ui/qt4/workbench/split_tab_widget.py: if sip.isdeleted(self):
pyface/qt/init.py: import sip
pyface/qt/init.py: sip.setapi('QDate', 2)
pyface/qt/init.py: sip.setapi('QDateTime', 2)
pyface/qt/init.py: sip.setapi('QString', 2)
pyface/qt/init.py: sip.setapi('QTextStream', 2)
pyface/qt/init.py: sip.setapi('QTime', 2)
pyface/qt/init.py: sip.setapi('QUrl', 2)
pyface/qt/init.py: sip.setapi('QVariant', 2)

Recent versions of sip now use name-spaced modules, so either this code can either be dropped or use PyQt4.sip instead.

(Or ideally, appears it at least has some support for PyQt5 which is better supported).

See also bug
https://bugzilla.redhat.com/show_bug.cgi?id=1753069

@corranwebster
Copy link
Contributor

Hi, thanks for the report, but I'm not quite sure what the problem is - the reference to the redhat issue is not particularly enlightening. Most of the code shown above is only run in the case that the Qt toolkit being used is PyQt4 and is not run when using the PyQt5 toolkit. We are doing essentially the same thing as, eg. qtpy here https://github.com/spyder-ide/qtpy/blob/master/qtpy/__init__.py#L181

Can you provide a bit more detail about what the issue is, with pointers to sip documentation showing best practices if we are not following them.

@opoplawski
Copy link
Contributor Author

Honestly, I don't think I can - I'm really just relaying the bug that was filed in fedora. But apparently one should be using PyQt4.sip.... instead of sip.... ?

@corranwebster
Copy link
Contributor

OK, I have dug a little deeper and this appears to be a very new, backwards incompatible change in PyQt's API. Importing PyQt4.sip does not work on versions of PyQt earlier than 4.12.2 or PyQt 5.11, and we need to be able to support earlier versions.

Fortunately PyQt installs sip into sys.modules on first import of QtCore so almost all uses of sip in Pyface are fine, because we explicitly import QtCore as part of the backend discovery process (see https://www.riverbankcomputing.com/static/Docs/PyQt4/incompatibilities.html#pyqt-v4-12-2 and https://github.com/enthought/pyface/blob/master/pyface/qt/__init__.py#L80). So the usage in split_tab_widget.py should cause no problems.

The setapi calls are more difficult, because those have to occur before the first PyQt import. They are only needed in the case of Python 2.7 and PyQt4. We will be dropping support for Python 2.7 next year, so that code will be being removed soon.

I think that the solution is to add

try:
    from PyQt4 import sip
except ImportError:
    import sip

into the prepare_pyqt4 function, which should cover all potential cases in typical Python environments. If that doesn't work from the point of view of the Redhat/Fedora packaging, you may need to explicitly patch based on knowing which version of PyQt4 you need.

@corranwebster
Copy link
Contributor

@opoplawski Hopefully this is resolved by #452

I am going to close this ticket, but please feel free to re-open if there is something that we have missed.

@opoplawski
Copy link
Contributor Author

What's the status of Qt5 support? Fedora is trying to move away from Qt4.

@corranwebster
Copy link
Contributor

Qt5 Should be fully supported via PyQt5; PySide2 support is experimental but seems to be working in most tests. There may be some issues around WebKit vs. WebEngine (so Qt 5.6 vs later versions): no-one has reported issues yet, but I don't think it is extensively used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants