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 686828 - Add API for getting wrapped gi modules without overrides
Add API for getting wrapped gi modules without overrides
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: 2012-10-24 22:18 UTC by Simon Feltman
Modified: 2012-10-25 07:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[API add] Add get_introspection_module for getting un-overridden modules (7.39 KB, patch)
2012-10-25 02:22 UTC, Simon Feltman
none Details | Review
[API add] Add get_introspection_module for getting un-overridden modules (7.08 KB, patch)
2012-10-25 02:30 UTC, Simon Feltman
none Details | Review
[API add] Add get_introspection_module for getting un-overridden modules (8.76 KB, patch)
2012-10-25 07:42 UTC, Simon Feltman
none Details | Review
[API add] Add get_introspection_module for getting un-overridden modules (8.77 KB, patch)
2012-10-25 07:45 UTC, Simon Feltman
committed Details | Review

Description Simon Feltman 2012-10-24 22:18:08 UTC
We need a public API for explicitly getting a wrapped gi module from within overrides. Currently is done by peeking into the importers module cache and pulling out an internal variable:

gi/overrides/GLib.py:
GLib = gi.importer.modules['GLib']._introspection_module

This is ok for the general case of importing from the registry because the importer ensures the DynamicModule and IntrospectionModule are loaded before the overrides. However, from the perspective of a discrete override file it is somewhat magical and should be replaced with an explicit getter.
Comment 1 Simon Feltman 2012-10-25 02:22:38 UTC
Created attachment 227214 [details] [review]
[API add] Add get_introspection_module for getting un-overridden modules

Add gi.module.get_introspection_module to explicitly get a
wrapped module pulled in through introspection without static
and python override handling. This API is intended for python
overrides to use rather than having them access
gi.importer.modules['<name>']._introspection_module directly.
Replace aforementioned usage in all overrides.
Comment 2 Simon Feltman 2012-10-25 02:30:32 UTC
Created attachment 227215 [details] [review]
[API add] Add get_introspection_module for getting un-overridden modules

Add gi.module.get_introspection_module to explicitly get a
wrapped module pulled in through introspection without static
and python override handling. This API is intended for python
overrides to use rather than having them access
gi.importer.modules['<name>']._introspection_module directly.
Replace aforementioned usage in all overrides.
Comment 3 Martin Pitt 2012-10-25 05:29:41 UTC
Thanks, this is a nice cleanup indeed!

In this testcase:

+        # Using a DynamicModule will use get_introspection_module internally.
+        mod_overridden = gi.module.DynamicModule(mod_name)
+        mod_overridden._load()

... I don't understand this line:

+        self.assertTrue(mod1 is mod_overridden._introspection_module)

mod1 is the module without overrides, so why this should be identical to the overridden one here?
Comment 4 Simon Feltman 2012-10-25 06:51:09 UTC
The test is emulating what gi.importer does in a simpler way. The unittest is intended to test the precise behavior of introspection module caching. So going through gi.importer (from gi.repository import Foo) would have side effects in regards to modifying sys.modules and gi.importer.modules. The test attempts to minimize side effects which should be tested as a separate unit elsewhere.

A DynamicModule is what is returned when using "from gi.repository import Foo". DynamicModule wraps up an IntrospectionModule and an overrides module (if found) as instance variables named _introspection_module and _overrides_module respectively. DynamicModule.__getattr__ then uses these to return gi classes and functions back (overrides are tried first).

In short, a DynamicModule is composed of the same introspection module returned from a call to get_introspection_module. The last assert checks that loading a DynamicModule will retrieve the correct cache for its composition. I will add some of this text as comments.
Comment 5 Simon Feltman 2012-10-25 07:42:10 UTC
Created attachment 227224 [details] [review]
[API add] Add get_introspection_module for getting un-overridden modules

Additionally added doc strings and comments.
Comment 6 Simon Feltman 2012-10-25 07:45:21 UTC
The following fix has been pushed:
e9624ed [API add] Add get_introspection_module for getting un-overridden modules
Comment 7 Simon Feltman 2012-10-25 07:45:23 UTC
Created attachment 227225 [details] [review]
[API add] Add get_introspection_module for getting un-overridden modules

Add gi.module.get_introspection_module to explicitly get a
wrapped module pulled in through introspection without static
and python override handling. This API is intended for python
overrides to use rather than having them access
gi.importer.modules['<name>']._introspection_module directly.
Replace aforementioned usage in all overrides.