Merge lp://staging/~coreygoldberg/window-mocker/py3 into lp://staging/window-mocker

Proposed by Corey Goldberg
Status: Merged
Approved by: Thomi Richards
Approved revision: 45
Merged at revision: 24
Proposed branch: lp://staging/~coreygoldberg/window-mocker/py3
Merge into: lp://staging/window-mocker
Diff against target: 657 lines (+285/-74)
13 files modified
bin/window-mocker (+7/-6)
debian/control (+25/-1)
debian/rules (+9/-4)
po/window-mocker.pot (+1/-1)
setup.py (+1/-2)
tests/test_app_functional.py (+24/-17)
tests/test_plugins.py (+26/-10)
tests/test_testapp_modlue_functions.py (+6/-5)
windowmocker/__init__.py (+1/-4)
windowmocker/plugins/__init__.py (+36/-18)
windowmocker/plugins/base.py (+2/-3)
windowmocker/plugins/qt4.py (+2/-3)
windowmocker/plugins/qt5.py (+145/-0)
To merge this branch: bzr merge lp://staging/~coreygoldberg/window-mocker/py3
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+196978@code.staging.launchpad.net

Commit message

python3 compatibility, Qt5 plugin

Description of the change

- ported to py2/py3 compatible
- using Qt5 plugin when running under Python3

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

129 +try:
130 + from StringIO import StringIO
131 +except ImportError:
132 + from io import StringIO
133 +
134 from mock import patch
135 -from StringIO import StringIO

We don't need to support py26 or earlier, so just import io.StringIO every time.

Otherwise, looks good

Revision history for this message
Martin Pitt (pitti) wrote :

Note that io.StringIO insists on writing unicode objects only, so it does behave differently than StringIO.StringIO in Python 2.7. If window-mocker carefully converts everythign that's fine, but doing so will break the Python 3 support. So far I must say I avoid io.StringIO in code that supports both py 2 and 3 as it makes the code quite ugly (lots of "if sys.version" checks). But YMMV.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

> so just import io.StringIO every time.

this is problematic due to Unicode handling.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

> > so just import io.StringIO every time.
>
> this is problematic due to Unicode handling.

Hang on, it should make your life easier, not harder :)

Python 3 code needs clear separation of unicode vs byte strings. TBH, your python2 code should as well. If you want to deal with bytes, you can import 'io.BytesIO' instead. In my experience, using the older StringIO.StringIO class leads to problems down the line, since the behavior is remarkably different depending on what version of python you're running.

I guess if you're maintaining the code then that's fine, but I think this is going to cause you problems down the line :)

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

290 +
291 +
292 +

Too much whitespace (PEP8) :)

190 +# use Qt4 plugin for Python2, Qt5 plugin for Python3
191 +if sys.version_info[0] < 3:
192 + from windowmocker.plugins.qt4 import QtPlugin
193 +else:
194 + from windowmocker.plugins.qt5 import QtPlugin

Just thinking about our upgrade strategy here... If we do this, then the autopilot tests will need to be duplicated - one set of tests against Qt4, and another against Qt5 (because the introspection tree will be different - please correct me if I'm wrong here).

The Qt4 plugin should be importable in both python2 and python3, and should remain the default plugin.

The Qt5 plugin is only importable in python3, so we should make that plugin selectable, but only in python3 land.

Then we can port the autopilot tests that use window-mocker over, and we can explicitly ask for the Qt5 plugin, and either skip the tests in py2, or re-write them to work in py2/Qt4 as well.

However, following the above strategy will mean we don't break the AP tests once this gets merged.

review: Needs Fixing
26. By Corey Goldberg

update debian control

27. By Corey Goldberg

make qt4 default plugin

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
28. By Corey Goldberg

use io.StringIO

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi Corey,

There's still a few problems here. I grabbed your branch and built the package, but:

1) It only builds a python-windowmocker package, so there's no way to build & install the python3 variant.

2) If I run it from the source directly with:

PYTHONPATH=`pwd` python3 bin/window-mocker

then I get some python3 incompatibilities:

Traceback (most recent call last):
  File "bin/window-mocker", line 53, in <module>
    main()
  File "bin/window-mocker", line 25, in main
    application = create_application_from_data()
  File "/home/thomi/code/canonical/window-mocker/py3/windowmocker/__init__.py", line 83, in create_application_from_data
    if not isinstance(app_type_name, basestring):
NameError: global name 'basestring' is not defined

These two issues prevent me from testing this further. Please let me know once these have been fixed and I can look at it again.

review: Needs Fixing
29. By Corey Goldberg

fixed py3 package

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
30. By Corey Goldberg

wrong package name

31. By Corey Goldberg

changed version in setup

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
32. By Corey Goldberg

merged debian pybuild

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
33. By Corey Goldberg

pyqt5 for py3 only

34. By Corey Goldberg

fixed d/rules

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
35. By Corey Goldberg

delay import of pyqt

36. By Corey Goldberg

fix delayed import of pyqt

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
37. By Corey Goldberg

added register_named_plugin

38. By Corey Goldberg

fixed plugins import

39. By Corey Goldberg

removed commented import

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
40. By Corey Goldberg

added unit tests for plugins

41. By Corey Goldberg

fixed d/rules for copy

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

bzr branch lp:~coreygoldberg/window-mocker/py3
cd py3
bzr bd
sudo dpkg -i ../build-area/*.deb

Does not work, because the .desktop files collide. You need to fix them like you had to fix the executable scripts.

Please make sure that, at a minimum, you can build the packages, install them, and the installed executables work before resubmitting for a review.

review: Needs Fixing
42. By Corey Goldberg

fixed shadowed py3 files

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Corey Goldberg (coreygoldberg) wrote :

packages build now.

note.. when running `window-mocker`, i get the following output to console:

"No handlers could be found for logger "windowmocker.plugins.base""

when running `window-mocker3`, I don't get that debug output.

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi Corey,

Selecting the Qt5 plugin doesn't work. I expect:

window-mocker3 -t Qt4

to launch a Qt4 window, and:

window-mocker3 -t Qt5

to launch a Qt5 window.

At the moment they both launch a Qt4 window.

review: Needs Fixing
43. By Corey Goldberg

fixes for calling plugin

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi,

The latest revision includes several defects:

1) Running 'window-mocker' just produces an error and exits:

$ window-mocker
ERROR:windowmocker.plugins:No plugin was found with name '<function get_default_plugin_name at 0x1618398>'
Error: Unable to process request: Type name '<function get_default_plugin_name at 0x1618398>' is invalid

2) Running 'window-mocker3' produces similar errors:

$ window-mocker3
ERROR:windowmocker.plugins:No plugin was found with name '<function get_default_plugin_name at 0x7f90a55847a0>'
Error: Unable to process request: Type name '<function get_default_plugin_name at 0x7f90a55847a0>' is invalid

For both points 1) and 2), the desired behavior is that it should just open the window with the default plugin (qt4 in both cases).

3) Running 'window-mocker -h' lists the 'Qt5' plugin as an available option, but that's incorrect - Qt5 is not available in python 2. If you try and actually run it in this configuration, it crashes:

$ window-mocker -t Qt5
Traceback (most recent call last):
  File "/usr/bin/window-mocker", line 54, in <module>
    main()
  File "/usr/bin/window-mocker", line 25, in main
    application = create_application_from_data(app_type_name=args.type)
  File "/usr/lib/python2.7/dist-packages/windowmocker/__init__.py", line 88, in create_application_from_data
    app_instance = app_plugin(data)
  File "/usr/lib/python2.7/dist-packages/windowmocker/plugins/__init__.py", line 20, in create_qt5_plugin
    from windowmocker.plugins.qt5 import QtPlugin as Qt5Plugin
  File "/usr/lib/python2.7/dist-packages/windowmocker/plugins/qt5.py", line 10, in <module>
    from PyQt5 import QtCore, QtWidgets
ImportError: No module named PyQt5

The Qt4 plugin should not be listed as an option in python2.

4) Running 'window-mocker3 -t Qt5' does indeed produce a Qt5 window (yay!), but closing that window causes window-mocker3 to crash (segfault, in fact, which is impressive, for a python application).

Given that these regressed, it's probably a good idea to add functional tests for all these issues before fixing them.

review: Needs Fixing
44. By Corey Goldberg

fixed get_default_plugin_name

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
45. By Corey Goldberg

fixes

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Barry Warsaw (barry) wrote :

Apologies for not seeing this mp first, but I have a competing mp:

https://code.launchpad.net/~barry/window-mocker/py3/+merge/204237

I'll take a look at Corey's branch and see if mine is missing anything. I don't have much of an opinion about PyQt4/PyQt5, but I have a strong opinion that window-mocker should only be Python 3. We don't want to B-D or Depend on any Python 2 related packages. Let's get rid of them once and for all. AFAICT, this is used as an application, not a library, so it doesn't need to be bilingual, and we definitely don't want to carry those extra dependencies. It also simplifies the code.

As for Qt4/5, what's the use case for letting that be switchable, other than the bug mentioned in my mp (which I can't reproduce here locally)? It should be hard to switch back to PyQt4, but OTOH PyQt5 works okay for me (and it passes all the tests <wink>). Does it need to be switchable, or can it be one or the other? OTOH, I don't care too much since both work in Python 3. :)

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Approving, since the Qt5 crash has been tracked down to another module. Let's land this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches