After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 687047 - gedit external plugin broken with current master
gedit external plugin broken with current master
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
Git master
Other All
: Immediate major
: ---
Assigned To: martin.pitt
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-10-28 14:45 UTC by Paolo Borelli
Modified: 2012-11-03 10:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix IOChannel unittests for python 2.7 (4.05 KB, patch)
2012-10-30 21:29 UTC, Simon Feltman
none Details | Review
Fix IOChannel unittests for python 2.7 (1.94 KB, patch)
2012-10-31 03:39 UTC, Simon Feltman
committed Details | Review
Fix GLib override incompatibilities with static API (9.21 KB, patch)
2012-10-31 03:48 UTC, Simon Feltman
committed Details | Review
Fix GLib override incompatibilities with old static API (9.52 KB, patch)
2012-10-31 05:43 UTC, Simon Feltman
committed Details | Review
Fix IOChannel unittests for python 2.7 (1.94 KB, patch)
2012-10-31 05:43 UTC, Simon Feltman
committed Details | Review

Description Paolo Borelli 2012-10-28 14:45:55 UTC
It looks like latest changes broke gedit's external tools plugin:


[paolo@murdock ~]$ gedit 
Gtk-Message: Failed to load module "pk-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"
/opt/gnome/lib64/gedit/plugins/externaltools/outputpanel.py:171: PyGIDeprecationWarning: idle_add is deprecated; use GLib.idle_add instead
  GObject.idle_add(self.scroll_to_end)
/opt/gnome/lib64/gedit/plugins/externaltools/capture.py:105: PyGIDeprecationWarning: io_add_watch is deprecated; use GLib.io_add_watch instead
  self.on_output)
/opt/gnome/lib64/python3.3/site-packages/gi/overrides/GLib.py:610: PyGIDeprecationWarning: Calling io_add_watch without priority as second argument is deprecated
  PyGIDeprecationWarning)
Traceback (most recent call last):
  • File "/opt/gnome/lib64/gedit/plugins/externaltools/functions.py", line 250 in capture_menu_action
    run_external_tool(window, panel, node)
  • File "/opt/gnome/lib64/gedit/plugins/externaltools/functions.py", line 203 in run_external_tool
    capture.execute()
  • File "/opt/gnome/lib64/gedit/plugins/externaltools/capture.py", line 105 in execute
    self.on_output)
  • File "/opt/gnome/lib64/python3.3/site-packages/gi/overrides/__init__.py", line 80 in wrapped
    return fn(*args, **kwargs)
  • File "/opt/gnome/lib64/python3.3/site-packages/gi/overrides/GLib.py", line 631 in io_add_watch
    assert isinstance(channel, GLib.IOChannel) AssertionError

Comment 1 Martin Pitt 2012-10-29 21:54:32 UTC
Argh, sorry about that! I can reproduce.
Comment 2 Martin Pitt 2012-10-29 22:07:44 UTC
I fixed this part in:

http://git.gnome.org/browse/pygobject/commit/?id=0f94a0a4ebd2bbfd06d8f9a2bb2b17dabf7678ef

However, now I get the following:

/usr/lib/gedit/plugins/externaltools/capture.py:219: PyGIDeprecationWarning: idle_add is deprecated; use GLib.idle_add instead
  GObject.idle_add(self.emit, 'end-execute', error_code)
TypeError: 1 parameters needed for signal end-execute; 0 given
TypeError: 1 parameters needed for signal end-execute; 0 given
[...]

I'll look into that ASAP, but I'm at UDS this week, so please feel free to beat me to it.
Comment 3 Simon Feltman 2012-10-30 21:29:59 UTC
Created attachment 227687 [details] [review]
Fix IOChannel unittests for python 2.7

These are changes to get unittests working again:

- Use __future__ unicode_literals to minimize difference between python 2.7 and 3. Comparisons encode arguments as 'UTF-8' for testing readline operations.

- Add backwards compatible "next" to support the python 2.7 iteration.

- Change isinstance(channel, file) to hasattr(channel, 'fileno') to support all python versions (and duck typing).

Also, I think it would be nice to continue supporting python io objects in place of IOChannels instead of deprecating this. It is very useful for adapting things like pythons multiprocessing module into a glib/gtk main loop.
Comment 4 Simon Feltman 2012-10-30 22:12:20 UTC
The problem seems to be the original: idle_add, timeout_add, and io_add_watch functions supported a variable number of additional arguments to pass to the callback (not just a single user_data). priority could then be specified as an additional keyword arg. So the overridden prototypes need to follow the form:

def idle_add(callback, *args, **kwargs):
    # Check within kwargs for priority
    # Use all of args as closure arguments but as a single user_data for overridden method.
Comment 5 Simon Feltman 2012-10-31 03:39:28 UTC
Created attachment 227702 [details] [review]
Fix IOChannel unittests for python 2.7

The encode calls ended up not being needed.
Comment 6 Simon Feltman 2012-10-31 03:48:27 UTC
Created attachment 227703 [details] [review]
Fix GLib override incompatibilities with static API

Change idle_add, timeout_add, timeout_add_seconds, and io_add_watch to accept *args and **kwargs as arguments to callback functions instead of a single user_data arg.

This also removes priority as an argument to the overridden methods and is instead pulled in through **kwargs (as in the original static bindings). This should at least get things working again. Another pass can be done to add the priority arg back with deprecations, but it will take a lot more argument mangling to make that happen.

Verified the external tools plugin works again within gedit.

A review would be nice but if no one is around I will push these patches as the current head is somewhat broken.
Comment 7 Simon Feltman 2012-10-31 05:43:49 UTC
The following fixes have been pushed:
80db2a5 Fix GLib override incompatibilities with old static API
9c6399b Fix IOChannel unittests for python 2.7
Comment 8 Simon Feltman 2012-10-31 05:43:56 UTC
Created attachment 227706 [details] [review]
Fix GLib override incompatibilities with old static API

Change idle_add, timeout_add, timeout_add_seconds, and
io_add_watch to accept *args and **kwargs as arguments
to the callback functions instead of only accepting a single
user_data arg. This ensures the new overridden introspection
methods are backwards compatible with the static versions
they replaced.
Comment 9 Simon Feltman 2012-10-31 05:43:59 UTC
Created attachment 227707 [details] [review]
Fix IOChannel unittests for python 2.7

Use __future__ unicode_literals to minimize difference
between python 2.7 and 3. Comparisons need to encode arguments as
'UTF-8' for testing readline operations.
Add backwards compatible "next" to support the python 2.7 iteration.
Change isinstance(channel, file) to hasattr(channel, 'fileno') to
support all python versions (and duck typing).
Comment 10 Martin Pitt 2012-10-31 06:57:12 UTC
Thanks Simon for the fast fix! I'll clean up the patch in a few days when I travle back home; I want to factor out the mangling of the callback and bring back the real GLib API.
Comment 11 Martin Pitt 2012-11-03 10:48:14 UTC
For the record, I now fixed this more properly in git.