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 753137 - Make Gom more Python-friendly
Make Gom more Python-friendly
Status: RESOLVED FIXED
Product: gom
Classification: Other
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Gom Maintainers
Gom Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-08-01 14:51 UTC by Mathieu Bridon
Modified: 2015-08-08 14:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
python: Add a working example (3.86 KB, patch)
2015-08-01 14:51 UTC, Mathieu Bridon
committed Details | Review
python: Prepare for adding some GI overrides (2.19 KB, patch)
2015-08-01 14:51 UTC, Mathieu Bridon
needs-work Details | Review
python: Make ResourceGroup a sequence (2.45 KB, patch)
2015-08-01 14:51 UTC, Mathieu Bridon
committed Details | Review
python: Override the Sorting constructor (2.20 KB, patch)
2015-08-01 14:51 UTC, Mathieu Bridon
committed Details | Review
python: Prepare for adding some GI overrides (3.71 KB, patch)
2015-08-06 05:57 UTC, Mathieu Bridon
committed Details | Review

Description Mathieu Bridon 2015-08-01 14:51:31 UTC
Thanks to GObject-Introspection, Gom can already be used just fine in Python.

All that's needed is an example script to show how to use it, and a couple of overrides to make the API a bit more Pythonic.
Comment 1 Mathieu Bridon 2015-08-01 14:51:35 UTC
Created attachment 308604 [details] [review]
python: Add a working example

The example demonstrates how to use Gom from Python, connecting to a
database, creating resource classes, inserting resource instances,
fetching them back with or without filters, with or without ordering,
synchronously or asynchronously, and then closing the connection.

Some parts don't look very Pythonic, but it could be made better with GI
overrides.
Comment 2 Mathieu Bridon 2015-08-01 14:51:39 UTC
Created attachment 308605 [details] [review]
python: Prepare for adding some GI overrides
Comment 3 Mathieu Bridon 2015-08-01 14:51:48 UTC
Created attachment 308606 [details] [review]
python: Make ResourceGroup a sequence

This is a simple GI overrides, which allows iterating directly over a
Gom.ResourceGroup, accessing items as if it were a list, and getting its
length, all in the natural Python way.
Comment 4 Mathieu Bridon 2015-08-01 14:51:53 UTC
Created attachment 308607 [details] [review]
python: Override the Sorting constructor

In C, the gom_sorting_new constructor allows passing all the sorting
arguments to the created GomSorting object.

This allows doing exactly the same thing in Python as well, without
having to first create the Gom.Sorting object, then adding all the
sorting arguments.
Comment 5 Mathieu Bridon 2015-08-01 14:55:27 UTC
There are other overrides which could be added to make things nicer of course but these two are a good start.

Others can easily be added in the future, based on what Gom users feel would make things nicer.

One thing I'm a bit worried about is leaving the example script to bitrot with time, for example if we changed the API it would stop working.

However, I couldn't figure out how to add it to the unit tests, so I figured I'd submit it anyway, hoping somebody else would know. :)
Comment 6 Bastien Nocera 2015-08-03 13:44:41 UTC
Review of attachment 308604 [details] [review]:

Looks good.
Comment 7 Bastien Nocera 2015-08-03 13:45:41 UTC
Review of attachment 308605 [details] [review]:

::: configure.ac
@@ +151,3 @@
 
+AM_PATH_PYTHON([3.4])
+PKG_CHECK_MODULES(PYTHON, [pygobject-3.0 >= 3.16.0])

I don't think we want a hard-dependency on Python though.
Comment 8 Bastien Nocera 2015-08-03 13:46:23 UTC
Review of attachment 308606 [details] [review]:

Looks good.
Comment 9 Bastien Nocera 2015-08-03 13:47:15 UTC
Review of attachment 308607 [details] [review]:

Looks good.
Comment 10 Mathieu Bridon 2015-08-06 05:57:37 UTC
Created attachment 308836 [details] [review]
python: Prepare for adding some GI overrides

This adds an optional build-time dependency on Python 3 and PyGObject.
Comment 11 Bastien Nocera 2015-08-08 11:22:24 UTC
Review of attachment 308836 [details] [review]:

Looks good otherwise.

::: bindings/python/Makefile.include
@@ +1,3 @@
+if ENABLE_PYTHON
+overridesdir = $(pyoverridesdir)
+overrides_PYTHON = bindings/python/gi/overrides/Gom.py

You're just missing a:
EXTRA_DIST += bbbb/Gom.py
in there, so that it's always in the dist even if built without Python support.
Comment 12 Mathieu Bridon 2015-08-08 12:10:10 UTC
(In reply to Bastien Nocera from comment #11)
> You're just missing a:
> EXTRA_DIST += bbbb/Gom.py
> in there, so that it's always in the dist even if built without Python
> support.

It seems to always be added to the tarball, even without adding this.
Comment 13 Mathieu Bridon 2015-08-08 12:14:41 UTC
Attachment 308604 [details] pushed as 975b7a7 - python: Add a working example
Attachment 308606 [details] pushed as ed722a3 - python: Make ResourceGroup a sequence
Attachment 308607 [details] pushed as 27b4d00 - python: Override the Sorting constructor
Attachment 308836 [details] pushed as d3dac3f - python: Prepare for adding some GI overrides