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 709008 - Fully expose GI API to Python
Fully expose GI API to Python
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2013-09-28 21:35 UTC by Simon Feltman
Modified: 2013-10-07 22:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Move info tuple retrieval into generic function (15.10 KB, patch)
2013-10-05 08:34 UTC, Simon Feltman
committed Details | Review
Move child info retrieval into generic function (3.17 KB, patch)
2013-10-05 08:34 UTC, Simon Feltman
committed Details | Review
Move info string retrieval into generic function (1.58 KB, patch)
2013-10-05 08:34 UTC, Simon Feltman
committed Details | Review
Add GIBaseInfo.equal method (3.07 KB, patch)
2013-10-05 08:34 UTC, Simon Feltman
committed Details | Review
Avoid calling g_base_info_get_name on GI_INFO_TYPE_TYPE (4.35 KB, patch)
2013-10-05 08:34 UTC, Simon Feltman
committed Details | Review
Expose all GI enum and flags types (9.89 KB, patch)
2013-10-05 08:34 UTC, Simon Feltman
committed Details | Review
Add missing methods on PyGIBaseInfo and sub-classes (40.09 KB, patch)
2013-10-05 08:34 UTC, Simon Feltman
committed Details | Review

Description Simon Feltman 2013-09-28 21:35:38 UTC
There are a few methods which are missing in the static bindings for GI (pygi-info and pygi-repository). This ticket is for an audit of that code to flush out a fully exposed the GI API. Beyond fixing the need for occasional one off additions, having this API is important when doing analysis and potentially more.
Comment 1 Simon Feltman 2013-10-05 08:34:25 UTC
Created attachment 256523 [details] [review]
Move info tuple retrieval into generic function

Create new generic function for retrieving a tuple of child infos.
This greatly simplifies all the bindings which return tuples from
a common pattern of functions on GIBaseInfo based instances.
Comment 2 Simon Feltman 2013-10-05 08:34:28 UTC
Created attachment 256524 [details] [review]
Move child info retrieval into generic function

Add a generic function for bindings which return a single child info.
This trivializes binding methods like PyGIObjectInfo.get_parent and
fixes leaks in PyGIObjectInfo.get_class_struct and
PyGIVFuncInfo.get_invoker.
Comment 3 Simon Feltman 2013-10-05 08:34:30 UTC
Created attachment 256525 [details] [review]
Move info string retrieval into generic function

Add get_info_string for sharing binding of simple string retrieval on
GIBaseInfo objects.
Comment 4 Simon Feltman 2013-10-05 08:34:32 UTC
Created attachment 256526 [details] [review]
Add GIBaseInfo.equal method

Break PyGIBaseInfo rich compare into two methods: equal and richcompare.
Equal is a direct exposure of the GI method and richcompare makes use of
this with additional support for Pyton "==" and "!=" operators.
Comment 5 Simon Feltman 2013-10-05 08:34:35 UTC
Created attachment 256527 [details] [review]
Avoid calling g_base_info_get_name on GI_INFO_TYPE_TYPE

Calling g_base_info_get_name on infos tagged with GI_INFO_TYPE_TYPE will
cause a crash. Avoid this by adding _safe_base_info_get_name and using that
throughout the bindings.
Logged GI bug as: https://bugzilla.gnome.org/show_bug.cgi?id=709456
Comment 6 Simon Feltman 2013-10-05 08:34:37 UTC
Created attachment 256528 [details] [review]
Expose all GI enum and flags types

Add new types for GIDirection, GITransfer, GIArrayType, GIScopeType,
GIVFuncInfoFlags, GIFieldInfoFlags, GIFuncitonInfoFlags, GITypeTag, and
GInfoType. These types are found in the gi._gi module exposed without the
"GI" prefix and contain all of their values as class attributes. e.g.
gi._gi.Transfer.EVERYTHING.
Comment 7 Simon Feltman 2013-10-05 08:34:40 UTC
Created attachment 256529 [details] [review]
Add missing methods on PyGIBaseInfo and sub-classes

Expose all methods of GIBaseBase info and its sub-classes.
Comment 8 Martin Pitt 2013-10-07 10:34:02 UTC
Review of attachment 256523 [details] [review]:

Wow, nice cleanup!
Comment 9 Martin Pitt 2013-10-07 10:41:16 UTC
Comment on attachment 256527 [details] [review]
Avoid calling g_base_info_get_name on GI_INFO_TYPE_TYPE

It would be nice to revert that once we start depending on a (future) g-i version which has this fixed, to avoid the extra function call. Do you know a standard way to do that? Could we perhaps add some #error "re-check if this bug got fixed" when building with g-i >= 1.40 or so?
Comment 10 Martin Pitt 2013-10-07 10:51:27 UTC
Comment on attachment 256528 [details] [review]
Expose all GI enum and flags types

I'm a bit torn on the last two patches. They will make it much easier to debug introspection issues right in Python, but expose a lot of API of g-i which might change, is probably not ever used in production, and makes imports a bit slower?

No veto from me though, so please go ahead.

Thank you!
Comment 11 Simon Feltman 2013-10-07 22:07:09 UTC
Attachment 256523 [details] pushed as cdd03a2 - Move info tuple retrieval into generic function
Attachment 256524 [details] pushed as d2aef36 - Move child info retrieval into generic function
Attachment 256525 [details] pushed as e7b758b - Move info string retrieval into generic function
Attachment 256526 [details] pushed as c86b2fe - Add GIBaseInfo.equal method
Attachment 256527 [details] pushed as 0120af6 - Avoid calling g_base_info_get_name on GI_INFO_TYPE_TYPE
Attachment 256528 [details] pushed as e190eb7 - Expose all GI enum and flags types
Attachment 256529 [details] pushed as a76b061 - Add missing methods on PyGIBaseInfo and sub-classes
Comment 12 Simon Feltman 2013-10-07 22:51:46 UTC
Thanks for the reviews!

(In reply to comment #9)
> It would be nice to revert that once we start depending on a (future) g-i
> version which has this fixed, to avoid the extra function call. Do you know a
> standard way to do that? Could we perhaps add some #error "re-check if this bug
> got fixed" when building with g-i >= 1.40 or so?

This would be nice but I don't know of a way to do it. In general we should probably run an occasional grep on our tree for "bugzilla" and audit those lines. Granted we always give the bug url as comments for things we workaround or perhaps we could introduce a new "tag" like WORKAROUND: ...

(In reply to comment #10)
> (From update of attachment 256528 [details] [review])
> I'm a bit torn on the last two patches. They will make it much easier to debug
> introspection issues right in Python, but expose a lot of API of g-i which
> might change, is probably not ever used in production, and makes imports a bit
> slower?

In terms of performance, I don't see anything above "0m0.000s" with or without the new bindings with a simple script containing only "import gi". But things are probably cached and I have a beefy machine.

Also keep in mind these APIs have been left somewhat "private" in the sense that a lot of it is only accessible on gi._gi (we only put needed stuff on "gi") and under classes like Gtk.Widget.__info__. However, method objects will expose CallableInfo items directly (Gtk.Widget.pressed.get_arguments()). But this has been the case since we did the load time optimizations.

Beyond the benefits of debugging and better function docs, this will greatly help with analysis and experimentation. For instance, I've been playing with a static binding generator using these bindings which can regenerate these same bindings (I really hope it could be used for cairo as well). Similarly we can use this for jit binding generation managed in pure python (ala llvmpy or David Malcoms new jit work with gcc: libgccjit.so and pygccjit (https://github.com/davidmalcolm/pygccjit).