Tuesday, May 25, 2010

New Python list at gnome.org

One of the action items that came out of the UDS sessions that touched introspection was to create an appropriate list for discussing the transition to introspection and Python 3.x.

The list description should make clear why any of the existing lists was deemed a good fit:
Development of Python bindings

Note:

* it's for the implementation details and you need to know C, not Python
* questions about the internals are on-topic, even if you're not developing the internals themselves
* it's a single place to discuss pygtk, pygi, pygobject wrapper implementations

So if you are worried about how your GNOME apps written in Python are going to transition to GNOME 3.x and Python 3.x, join us before it's too late!

http://mail.gnome.org/mailman/listinfo/python-hackers-list

Monday, May 17, 2010

Telepathy and Ubuntu

As mentioned in my last post about the Ubuntu Developer Summit last week, there's interest in Ubuntu for using the Telepathy framework in more of their projects. There was discussion of using Telepathy in their telephony stack and also on some Ubuntu-specific changes in Empathy, but I was most interested in their effort to make easy and fun to code collaborative applications.

As part of the work on Sugar that Collabora is sponsoring, I also have a big interest in making as easy as possible to use the telepathy framework, be it in applications or in desktop components such as the Sugar shell.

For now, I'm going to help kickstart the process by implementing some toy-like API on top of Telepathy in the form of widgets for Quickly, here is the branch.

This is what we came up with in the brainstorming session about the "easy and fun" API:
class Client(Boo):
def __init__(self):
self.tube_handler = MessageTubeHandler("tubey")
self.tube_handler.connect("handle-channel", self.on_handle_channel)

def on_handle_channel(self, tube):
self.image_tube = tube
tube.connect("message-received", self.on_message_received)

def on_message_received(self, tube, msg):
if "img_url" in msg:
self._download_image(msg["img_url"])

def on_contact_selected(self, contact, account):
self.image_tube = tp.MessageTube(contact, account)
msg = {}
msg["note"] = self.label1.get_text()
self.image_tube.send(msg)

def on_tube_initiated(self, tube):
if "kenvandine" in tube.contact.props.identifier:
return


As PyGI is not packaged yet for Ubuntu and for the sake of getting started quickly, I'm going to do the initial implementation with the old telepathy-python bindings, but I hope that whatever gets into the Maverick release uses the much nicer telepathy-glib API through introspection.

Also will be trying to keep an eye on the collaboration needs of Sugar activities so more people benefit from this effort.

Ubuntu and GObject introspection

Canonical invited me to spend last week in Brussels at the Ubuntu Developer Summit, representing the upstream projects I'm part of: Telepathy, GNOME and Sugar.

On the GNOME front, I tried to understand Ubuntu plans regarding introspection and developing with Python. At the beginning I was very concerned because the developers I talked to didn't seemed to be aware of the changes that introspection would bring to GNOME and thus hadn't any strategy in place.

The most notable effect of the appearance of introspection support in GNOME is that the existing static bindings for Python and other languages will stop being maintained and no new bindings will be developed for new APIs. For downstreams such as Ubuntu this means that they will either have to maintain and develop static bindings themselves alone, or move to use introspection. See here for an explanation of how apps in python would use introspection to call GObject C code.

If Ubuntu limited itself to package whatever software upstream releases, they could just sit waiting for new releases and update the dependencies accordingly. But turns out they produce a lot of Python code themselves and thus need to get involved in this transition for their own good. They also have the goal of being a great platform for developing desktop apps with Python, and introspection will play a major role in that.

Jorge Castro was tremendously helpful by presenting myself to Barry Warsaw, who has a responsibility role in Ubuntu's use of Python. Barry has been working on the transition to Python 3 and GNOME's move to introspection can make it way easier by making obsolete an awful lot of CPython code. This will also make possible in the future to use other Python implementations than CPython for coding GNOME applications.

As the week progressed introspection got more and more present in Ubuntu's plans, which makes me very happy. Follows some of the most relevant mentions of it, check the whiteboard section of each blueprint for the details:

How do we get to Python 3 and do we go through 2.7 first? "Port PyGI to python3. Move python2 applications to use PyGI." There's lots we can do upstream to help with this, from providing a script to convert to the new API to create a compatibility layer in PyGI. We'll be discussing the creation of a mailing list for coordinating PyGObject and PyGI development and helping with the porting from the static bindings.

How GObject Introspection will change our platform "Actions: Package PyGI for Ubuntu (Python 2) [robert-ancell], create or hijack a mailing list for pygi development"

Fun and Easy Python API for Telepathy We are adding API to telepathy-glib in this direction and nobody has shown interest in working on new static bindings for it, so we need PyGI in order to access the new API.

packagekit as backend for software-center "Python API is out-of-date. It would require some adaption, especially since 0.6.x will break API. Packagekit-glib2 was written with gobject introspection support. So bindings could be generated in the future."

Review coming changes in GNOME and what we will want to do "Python introspection bindings well progressed at sprint. No resource for GLib introspection work. Libraries will stop making bindings and rely on introspection - we have to migrate at some time to keep bindings"

And there seems to have been also interest in introspection from the people pushing for Midgard in Ubuntu.

In summary, I'm very happy to count on Ubuntu in the development of PyGI, I plan to report in this blog about the progresses in polishing PyGI and porting apps to the new API.

P.S.: I'm under the impression that Planet GNOME is not widely read by Ubuntu people, so if someone could rely it to their planet, would be awesome.

Friday, May 7, 2010

Two talks in Greece about Sugar


The nice people at EELLAK have invited Simon and me to discuss the software side of their 1-to-1 deployments.

We'll be Saturday 15th in Athens and Sunday 16th in Thessaloniki, so if you happen to be there and are interested in discussing about Sugar, OLPC or free software in general, check out the program and appear.

Wednesday, May 5, 2010

Going to UDS-M

Canonical has been so nice to sponsor my attendance to the next Ubuntu Developer Summit in Brussels next week and Collabora is sponsoring my time there for Telepathy, Python and Sugar stuff. Thanks a lot to both companies.

The Ubuntu community has interest in making as easy as possible for regular users to create software and part of this effort is having a high-level API for having collaboration across the network. This of course will involve Telepathy and I have also a big interest in providing this experience to users of Sugar. Collabora are going to be flying as well some of their Telepathy developers to work on this and I look forward to finally meeting them.

Ubuntu has also committed heavily on Python for their development efforts, both on the desktop and in the server. For the desktop side of things, Python on GNOME is facing several challenges right now and I will be happy to help them make sure they don't lose any opportunities because of that. The challenges I have referred to are the obsolescence of static library bindings and the update to Python 3. On both issues Red Hat has contributed several developers to upstream and I will be happiest to discuss how we can also make Ubuntu contributors most welcome there. I'm also looking forward to finally meet Simon van der Linden in person after working together in PyGI for so long, he happens to live close to the venue so he'll jump to say hello and maybe do some hacking together (I have some patches in the queue that could use some review love).

There's also interest from Edubuntu in shipping Sugar, so I have registered to their blueprint and will be available to answer any questions they have regarding it. I have felt sad often when Ubuntu users have come asking how they could run Sugar on their machines and I had to point them to the instructions to build from the source, so it's great to have the possibility for Sugar to be accepted and supported by Ubuntu at last.

Using telepathy-glib in python through gobject-introspection

Until now, you had two options for writing telepathy clients in python: use the low level D-Bus API through dbus-python, or using telepathy-python which provided very little more for clients apart from registering the zillion of constants in Telepathy.

Telepathy-glib is a library that provides a higher level API for interacting with the Telepathy framework than the low level D-Bus API. No languages bindings exist currently for this library so only C apps such as Empathy used it, developers using languages such as Python and JavaScript were stuck with the D-Bus API and generally each app invented a more or less complete new API on top of it.

In parallel to a push for adding more high-level APIs to telepathy-glib, we are looking at what remains to be done in the gobject-introspection stack so we don't need to write static bindings for each language. After some weeks hacking on Gjs (Danielle Madeley), Vala (Travis Reitter) and PyGI (me) things are starting to take shape.

Following Danni's post on her progress, here comes an example observer written in Python and using PyGI to call telepathy-glib:

import gobject
gobject.threads_init()

from gi.repository import TelepathyGLib

#TelepathyGLib.debug_set_flags('all')

def observe_channels(observer, account, connection, channels,
dispatch_op, requests, context, user_data):
print 'observe_channels'

print 'account = %s' % account.get_object_path()
print 'connection = %s' % connection.get_object_path()

for channel in channels:
print 'channel = %s' % channel.get_object_path()

if dispatch_op is not None:
print 'dispatch_op = %s' % dispatch_op.get_object_path()
else:
print 'dispatch_op = None'

if requests is not None:
for request in requests:
print 'request = %s' % request.get_object_path()

context.accept()

dbus = TelepathyGLib.DBusDaemon.dup()
observer = TelepathyGLib.SimpleObserver.new(dbus, True, 'PythonObserver', True,
observe_channels, None)
observer.add_observer_filter({
TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE: TelepathyGLib.IFACE_CHANNEL_TYPE_TEXT,
})

observer.register()

main_loop = gobject.MainLoop()
main_loop.run()


This needs the latest code in telepathy-glib, gobject-introspection and pygi, and also a patch to PyGI that hasn't been release yet.