GNOME Bugzilla – Bug 707735
Provide API to check for foreign struct support
Last modified: 2014-05-06 03:34:11 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?
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
At some point one must trust the distros not be insane, right?
(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.
The following fix has been pushed: 22a952e [New API] Add gi.require_foreign
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).