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 707735 - Provide API to check for foreign struct support
Provide API to check for foreign struct support
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
Git master
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks: 694604
 
 
Reported: 2013-09-08 18:44 UTC by Christoph Reiter (lazka)
Modified: 2014-05-06 03:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[New API] Add gi.require_foreign (7.62 KB, patch)
2014-05-06 03:34 UTC, Simon Feltman
committed Details | Review

Description Christoph Reiter (lazka) 2013-09-08 18:44:42 UTC
I want to check if pygobject's cairo support is installed (it's a separate package in debian/ubuntu). Mainly because if it is missing I get many bogus TypeErrors and OverflowErrors which don't really indicate what the problem is, confusing the user.

I currently use something like this:

#######
some_window = Gtk.OffscreenWindow()
some_window.show()
try:
    some_window.get_surface()
except TypeError:
    print "PyGObject is missing cairo support"
    exit(1)
#########

Questions:
 - Is there something better than the above? (I just received a bug report in which case the above segfaults)
 - Would it be a good idea to have something like gi.require_foreign("cairo", "Surface") which raises if support is missing?
Comment 1 Simon Feltman 2013-09-08 22:36:51 UTC
In terms of something better than what you have, I don't have any idea. Unfortunately importing gi._gi_cairo gives a warning because the foreign API is not initialized (and this subsequently breaks foreign conversions).

The proposed API sounds like a good idea, it could be a subset of pygi_struct_foreign_lookup taking the namespace and optionally name:
https://git.gnome.org/browse/pygobject/tree/gi/pygi-foreign.c?id=3.9.91#n66
Comment 2 John Stowers 2013-09-09 09:36:59 UTC
At some point one must trust the distros not be insane, right?
Comment 3 Simon Feltman 2014-04-28 06:39:33 UTC
(In reply to comment #2)
> At some point one must trust the distros not be insane, right?

I think the reason pygi-cairo is packaged separately is because it brings in cairo and X11. Which is a bummer for a headless system wanting to use pygi.
Comment 4 Simon Feltman 2014-05-06 03:34:06 UTC
The following fix has been pushed:
22a952e [New API] Add gi.require_foreign
Comment 5 Simon Feltman 2014-05-06 03:34:11 UTC
Created attachment 275931 [details] [review]
[New API] Add gi.require_foreign

Add gi.require_foreign(namespace, symbol=None) API for determining
if a foreign marshaling module is available. This can be used in an
applications import statement block to verify the existence of a
specific foreign marshaling module (cairo).
Additionally it forces loading of the foreign marshaling module as
well as the GI repository module. This allows non-introspected signal
closures to correctly marshal their arguments (bug 694604).