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 761141 - Make it possible to require multiple modules with a single call to gi.require_version()
Make it possible to require multiple modules with a single call to gi.require...
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
Git master
Other Linux
: Normal enhancement
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2016-01-26 16:36 UTC by Dustin Falgout
Modified: 2016-04-25 04:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gi.require_version() enhancement (3.02 KB, patch)
2016-01-26 16:36 UTC, Dustin Falgout
none Details | Review
gi.require_version() enhancement-2 (3.03 KB, patch)
2016-01-27 03:39 UTC, Dustin Falgout
none Details | Review
test for gi.require_version() (2.03 KB, patch)
2016-01-27 05:50 UTC, Dustin Falgout
none Details | Review
gi.require_version() enhancement-3 (3.08 KB, patch)
2016-01-27 06:25 UTC, Dustin Falgout
none Details | Review
gi: Add require_versions() function (5.34 KB, patch)
2016-02-06 10:28 UTC, Dustin Falgout
none Details | Review
gi: Add require_versions() function (6.09 KB, patch)
2016-02-24 09:07 UTC, Dustin Falgout
none Details | Review
adds new function gi.require_versions() (2.70 KB, patch)
2016-03-20 08:36 UTC, Dustin Falgout
committed Details | Review

Description Dustin Falgout 2016-01-26 16:36:58 UTC
Created attachment 319762 [details] [review]
gi.require_version() enhancement

This patch modifies gi.require_version() so that multiple modules can be required in a single call to the function. Also adds a docstring for the function.

Let me know if it looks good or if it needs any modifications. Thanks.


Cheers!
Comment 1 Dustin Falgout 2016-01-27 03:39:13 UTC
Created attachment 319802 [details] [review]
gi.require_version() enhancement-2

Added default values for better compatibility (both backward and forward).
Comment 2 Dustin Falgout 2016-01-27 05:50:21 UTC
Created attachment 319804 [details] [review]
test for gi.require_version()

Added test for `gi.require_version()`.
Also fixed method body content for `TestImporter.test_require_version_warning()` (the content was duplicated from `TestImporter.test_invalid_repository_module_name()`)
Comment 3 Dustin Falgout 2016-01-27 06:25:45 UTC
Created attachment 319805 [details] [review]
gi.require_version() enhancement-3

Be more explicit with assigning value of `requires` variable.
Use requires.items() for iteration (for py2/py3 compatible code).

Btw, sorry for all the noise. I'm having "one of those days" :-|
Comment 4 Simon Feltman 2016-02-06 08:10:12 UTC
Review of attachment 319805 [details] [review]:

Thanks for the patches. Please see [1] for commit message guidelines.

While I think the feature is nice, I generally dislike overloaded functions. How about adding this as an additional require_versions() function?

[1] https://wiki.gnome.org/Git/CommitMessages
Comment 5 Dustin Falgout 2016-02-06 10:28:18 UTC
Created attachment 320525 [details] [review]
gi: Add require_versions() function

gi: Add require_versions() function

This new function accepts a dict of one or more namespace, version
pairs. Moves the logic from gi.require_version() to the new
gi.require_versions(), the former now simply calls the latter. Also
adds a new test and fixes an existing test that was broken.

https://bugzilla.gnome.org/show_bug.cgi?id=761141
Comment 6 Dustin Falgout 2016-02-23 11:43:48 UTC
Just wanted to check in on this. Please let me know your thoughts. Thanks.
Comment 7 Simon Feltman 2016-02-24 07:03:33 UTC
Review of attachment 320525 [details] [review]:

Overall this looks good. Just a few noted comments with regards to test dependencies. It also looks like your commit message didn't make it into that patch, are you using "git format-patch" ?

Note that the GNOME 3.20 release is in API freeze so we would need to request a freeze break to get this in (which I think would probably be fine).

Thanks.

::: tests/test_import_machinery.py
@@ +139,3 @@
+        with check("Gdk", 3):
+            with warnings.catch_warnings(record=True) as warning:
+                from gi.repository import Gdk

We need be careful about using repos which are not GLib, GObject, Gio and GIMarshallingTests because the test suite needs to run on a minimal install (Gtk not installed). See [1].

[1] https://git.gnome.org/browse/pygobject/tree/tests/test_overrides_gtk.py#n62

@@ +150,3 @@
+    def test_gi_require_versions(self):
+
+        gi.require_versions({'AppStreamGlib': '1.0', 'Gtk': '3.0', 'GLib': '2.0'})

Same here.
Comment 8 Dustin Falgout 2016-02-24 09:07:50 UTC
Created attachment 322217 [details] [review]
gi: Add require_versions() function

I incorporated your feedback. I also found and corrected an error in my logic for checking the type of arguments at the start of gi.require_version(). Let me know if you need anything else from me. Thanks.
Comment 9 Dustin Falgout 2016-02-28 13:46:18 UTC
Just checking in on this again. I'm not sure how much time there is left to get it in for 3.20?
Comment 10 Simon Feltman 2016-02-28 19:59:37 UTC
Review of attachment 322217 [details] [review]:

Dustin,

Prior to submitting a freeze break for this I've gone through the code once more and ran tests. There are still a few problems/questions to address (apologies for this taking so long).

To make this addition simpler for reviewers and clearer in terms of functional composition, I suggest leaving gi.require_version() as is and adding the additional gi.require_versions() which simply calls the original in a loop, something like:


    def require_versions(versions):
        for namespace, version in versions.items():
            require_version(namespace, version)


Additionally I'm hitting unittest failures with this:

$ make check TEST_NAMES=test_import_machinery
...
======================================================================
ERROR: test_gi_require_versions (test_import_machinery.TestImporter)
----------------------------------------------------------------------
Traceback (most recent call last):
  • File "/home/simon/Source/gnome-3.20/src/pygobject/tests/test_import_machinery.py", line 156 in test_gi_require_versions
    gi.require_versions({'Gio', '2.0'})
  • File "/home/simon/Source/gnome-3.20/src/pygobject/py2build/gi/__init__.py", line 104 in require_versions
    'requires must be of type {0}, {1} given.'.format(type(dict), type(requires))
TypeError: requires must be of type <type 'type'>, <type 'set'> given.

======================================================================
ERROR: test_require_version_warning (test_import_machinery.TestImporter)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/simon/Source/gnome-3.20/src/pygobject/tests/test_import_machinery.py", line 143, in test_require_version_warning
    self.assertTrue(issubclass(warning[0].category, PyGIWarning))
IndexError: list index out of range

======================================================================
FAIL: test_gi_require_version (test_import_machinery.TestImporter)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/simon/Source/gnome-3.20/src/pygobject/tests/test_import_machinery.py", line 172, in test_gi_require_version
    gi.require_version('GLib', '2.0')
AssertionError: ValueError not raised

::: gi/__init__.py
@@ +95,3 @@
+    Example:
+
+    :type requires: dict

Example should use: gi.require_versions(...)

@@ +103,3 @@
+        raise TypeError(
+            'requires must be of type {0}, {1} given.'.format(type(dict), type(requires))
+        )

Generally avoid strict type checking (this could be removed completely). Or if you really must, test for the abstract collections.Mapping, see:
https://docs.python.org/2/library/collections.html#collections.Mapping
Comment 11 Dustin Falgout 2016-03-20 08:36:45 UTC
Created attachment 324358 [details] [review]
adds new function gi.require_versions()

Incorporated feedback.
Comment 12 Dustin Falgout 2016-04-17 06:55:18 UTC
Could I get a status update on this? Thanks.
Comment 13 Simon Feltman 2016-04-25 04:31:02 UTC
Comment on attachment 324358 [details] [review]
adds new function gi.require_versions()

This was committed with a fix to a test failure:

    from gi import GLib

was changed to:

    from gi.repository import GLib

See: https://git.gnome.org/browse/pygobject/commit/?id=1bb267
Comment 14 Simon Feltman 2016-04-25 04:32:02 UTC
Thanks!