GNOME Bugzilla – Bug 559947
Unchecked dependency on python>=2.4
Last modified: 2011-06-01 10:33:40 UTC
gtk+-2.14.4 gtk-builder-convert is a python script that uses sorted(), a command that was introduced in python2.4. It's hard-coded to use "first 'python' in PATH", however, ./configure doesn't check that that python is at least 2.4 or provide a way to specify alternate pythons that would suffice if the default one doesn't. Recent glib has a similar python requirement for one of its scripts and Does Things Better: AM_PATH_PYTHON to find executable path and then an install-exec-hook Makefile.am fragment to patch the path into the script. An alternative for that latter action would be to have the script as a .in template that gets substituted during ./configure
Using sorted is an oversight, I've tried hard to avoid requiring a newer versions of python in gtk-builder-convert, it should in theory work with python 2.0. sorted(x) should just be sorted_x = list(x); sorted_x.sort() instead.
>for obj in sorted(self.root_objects, > key=lambda n: n.getAttribute('id'), > reverse=True): > self._interface.childNodes.insert(0, obj) I gave it a whirl: >objects=self.root_objects >objects.sort(key=lambda n: n.getAttribute('id'), > reverse=True) >for obj in objects: > self._interface.childNodes.insert(0, obj) Works fine in python2.5, but it's still not portable. Under python2.3, Traceback (most recent call last):
+ Trace 209524
sys.exit(main(sys.argv))
conv.parse_file(input_filename)
self._parse()
reverse=True)
I can move reverse=True out: >objects=self.root_objects >objects.sort(key=lambda n: n.getAttribute('id')) >objects.reverse() >for obj in objects: > self._interface.childNodes.insert(0, obj) but that's only half of the problem. I don't know enough python to write a custom cmpfunc rather than using modern key= keyword.
>objects.sort(key=lambda n: n.getAttribute('id')) can be written as: objects.sort(lambda a, b: cmp(a.getAttribute('id'), b.getAttribute('id')))
2008-11-25 Johan Dahlin <jdahlin@async.com.br> Bug 559947 – Unchecked dependency on python>=2.4 * gtk/gtk-builder-convert: Avoid using sorted() which is only present in python 2.
Found another "new python" syntax in that script. With python2.3, building gnome-terminal-2.24.3 crashes: /sw/bin/gtk-builder-convert profile-preferences.glade profile-preferences.ui Traceback (most recent call last):
+ Trace 211508
self._convert(node.getAttribute("class"), node)
self._default_widget_converter(node)
self._convert_adjustment(prop)
page_size=page_size)
The offending code is around line 528: >properties.update(value=value, > lower=lower, > upper=upper, > step_increment=step, > page_increment=page, > page_size=page_size) but in python2.3, dict.update only takes a simple dictionary, not a list of key=value parameters.
This seems equivalent (to my non-python-expert eyes) and "works" (by which I mean "doesn't crash") on py23: >properties.update({"value":value, > "lower":lower, > "upper":upper, > "step_increment":step, > "page_increment":page, > "page_size":page_size})
This script also crashes when the current python version is >= 3.0. It uses print statements, but in python 3 print became a function. There may be other python 3 incompatibilities. Please change the title of this bug to reflect that this script also depends on python < 3.0. This crash is common on the MacPorts platform, where there is no standard default python version, and it causes at least one other port to fail to build. See: http://trac.macports.org/ticket/19441 Please upgrade the severity and priority of this bug. I'm afraid that the only practical solution may be to choose a specific major python version, depend on it, and hard-wire it into the shell-bang.
The above patch for the sorted() problem fixed breakage for Python < 2.4, but introduced new breakage for Python >= 3. There, the sort() method no longer supports comparison functions. Here is code that will work from Python 3 all the way back to very old Python, even before list comprehensions: > obj_ids = [] > for i in range(len(self.root_objects)): > obj_ids.append((self.root_objects[i].getAttribute('id'), i)) > obj_ids.sort() > obj_ids.reverse() > for id in obj_ids: > self._interface.childNodes.insert(0, self.root_objects[id[1]]) And it will only get worse. For example, the string format operator "%" is scheduled to be deprecated in Python 3.1. That will require extensive messy changes to continue to support all Python versions.
gtk-builder-convert has been removed from GTK+. Also, using Glade is the prefered methos to convert files from libglade to GtkBuilder format