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 736678 - Refactor overrides import/modules
Refactor overrides import/modules
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
Git master
Other Linux
: Normal enhancement
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks: 682886
 
 
Reported: 2014-09-15 14:22 UTC by Christoph Reiter (lazka)
Modified: 2015-06-15 08:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (13.86 KB, patch)
2014-09-15 14:22 UTC, Christoph Reiter (lazka)
none Details | Review
patch-v2 (14.08 KB, patch)
2014-12-02 15:00 UTC, Christoph Reiter (lazka)
committed Details | Review
gst-python-fix (1.44 KB, patch)
2015-04-23 20:06 UTC, Christoph Reiter (lazka)
committed Details | Review

Description Christoph Reiter (lazka) 2014-09-15 14:22:41 UTC
Created attachment 286207 [details] [review]
patch

I tried to add deprecation warnings for override module attribute access but decided to clean things up first.

- I've removed the Registry, because it's just another layer of overrides and not really used anywhere

- Instead of a DynamicModule import will now return the original IntrospectionModule in case there are no overrides or an OverridesProxyModule in case there are, which uses __getattr__ to fall back to the IntrospectionModule

- All the overrides logic is now in gi.overrides

To keep things like Gedit working gi.importer.modules[namespace] will point to the final module during override import. I haven't tested Gedit, but Regress in the test suite uses the same interface.

I think this makes the import process easier to understand / modify, but ymmv.

For the speed:

before:
python -mtimeit -s'from gi.repository import Gtk' 'Gtk.Button'
1000000 loops, best of 3: 0.965 usec per loop
python -mtimeit -s'from gi.repository import Gtk' 'Gtk.Button()'
10000 loops, best of 3: 25.3 usec per loop

after:
python -mtimeit -s'from gi.repository import Gtk' 'Gtk.Button'
10000000 loops, best of 3: 0.0462 usec per loop
python -mtimeit -s'from gi.repository import Gtk' 'Gtk.Button()'
10000 loops, best of 3: 23.1 usec per loop

Probably not that visible in real code..

Any feedback welcome
Comment 1 Simon Feltman 2014-09-16 05:47:46 UTC
Review of attachment 286207 [details] [review]:

This cleanup is welcome as the registry mechanism has always been confusing. I didn't look at the changes too closely but something that came up immediately was putting more stuff into overrides/__init__.py. There was an idea noted in bug 687335 about actually clearing that file out so we can use it as a namespace package (PEP-0420). I don't know the details and I haven't really thought about this part of the code base much lately but it is something to consider.
Comment 2 Christoph Reiter (lazka) 2014-09-16 07:12:03 UTC
Re bug 687335, moving overrides.__init__ to let's say gi.overridesutil and adjusting one import in importer.py should be it.
Comment 3 Christoph Reiter (lazka) 2014-12-02 15:00:21 UTC
Created attachment 291993 [details] [review]
patch-v2

Small update to handle/ignore non-strings in __all__ like before. The Gedit overrides erroneously put a function object there.
Comment 4 Simon Feltman 2014-12-19 06:41:00 UTC
Review of attachment 291993 [details] [review]:

Looks good to me, thanks!
Comment 5 Christoph Reiter (lazka) 2014-12-27 14:54:26 UTC
Thanks for the review!
Comment 6 Thibault Saunier 2015-04-23 17:01:52 UTC
That refactoring broke the Gst.Fraction overrides (in the case we want to get a value from C to python):


Before the commit (4d0ab13a8461f781986accc637fada3909cfb91a):

 $ python3 -c "from gi.repository import Gst; Gst.init(None); print(Gst.Structure.from_string('video/x-raw,framerate=10/1')[0]['framerate'])"

<Gst.Fraction 10/1>

After the commit (149c31beced944c72fba6ca6e096c81c1100ea2b):

 $ python3 -c "from gi.repository import Gst; Gst.init(None); print(Gst.Structure.from_string('video/x-raw,framerate=10/1')[0]['framerate'])"
Traceback (most recent call last):
  • File "<string>", line 1 in <module>
  • File "/home/thiblahute/devel/pitivi/1.0-uninstalled/gst-python/gi/overrides/Gst.py", line 228 in __getitem__
    return self.get_value(key)
TypeError: unknown type GstFraction

The override in question is available (registered) here:

http://cgit.freedesktop.org/gstreamer/gst-python/tree/gi/overrides/gstmodule.c#n131
Comment 7 Christoph Reiter (lazka) 2015-04-23 18:24:04 UTC
I'll have a look.

btw. gst-python in jhbuild is build for Python 2, but the overrides fail to import under Python 2.
Comment 8 Christoph Reiter (lazka) 2015-04-23 20:06:48 UTC
Created attachment 302266 [details] [review]
gst-python-fix

This was the problem: http://cgit.freedesktop.org/gstreamer/gst-python/tree/gi/overrides/gstmodule.c#n88

The pygobject error message was unrelated/wrong.
Comment 9 Simon Feltman 2015-04-23 21:23:04 UTC
Review of attachment 302266 [details] [review]:

LGTM. Please commit to master and the 3.16 branch
Comment 10 Christoph Reiter (lazka) 2015-04-23 21:53:05 UTC
Thanks, done.
Comment 11 Thibault Saunier 2015-04-24 06:05:01 UTC
Thanks a lot :)
Comment 12 Thibault Saunier 2015-06-12 08:04:17 UTC
Hello,

Would it possible to get a bugfix release with that patch in 3.16? Pitivi is unusable right now on any distro with Gnome 3.16 because of it.

Thanks a lot :)
Comment 13 Simon Feltman 2015-06-13 02:59:55 UTC
(In reply to Thibault Saunier from comment #12)
> Hello,
> 
> Would it possible to get a bugfix release with that patch in 3.16? Pitivi is
> unusable right now on any distro with Gnome 3.16 because of it.
> 
> Thanks a lot :)

Possibly in the next few days (my gnome dev machine is currently broken).

If anyone else wants to do the release it would be appreciated, just make sure distcheck passes on Python 2.7 and 3.
Comment 14 Simon Feltman 2015-06-15 08:43:27 UTC
Ok, 3.16.2 has been released:
https://git.gnome.org/browse/pygobject/commit/?id=66311fd
Comment 15 Thibault Saunier 2015-06-15 08:47:26 UTC
Thanks Simon :)