GNOME Bugzilla – Bug 753137
Make Gom more Python-friendly
Last modified: 2015-08-08 14:46:16 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.
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.
Created attachment 308605 [details] [review] python: Prepare for adding some GI overrides
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.
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.
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. :)
Review of attachment 308604 [details] [review]: Looks good.
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.
Review of attachment 308606 [details] [review]: Looks good.
Review of attachment 308607 [details] [review]: Looks good.
Created attachment 308836 [details] [review] python: Prepare for adding some GI overrides This adds an optional build-time dependency on Python 3 and PyGObject.
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.
(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.
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