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 559947 - Unchecked dependency on python>=2.4
Unchecked dependency on python>=2.4
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
2.14.x
Other Mac OS
: Normal normal
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
Depends on:
Blocks:
 
 
Reported: 2008-11-08 21:46 UTC by Daniel Macks
Modified: 2011-06-01 10:33 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Daniel Macks 2008-11-08 21:46:44 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
Comment 1 Johan (not receiving bugmail) Dahlin 2008-11-08 23:50:22 UTC
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.
Comment 2 Daniel Macks 2008-11-09 15:55:25 UTC
>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):
  • File "/sw/bin/gtk-builder-convert", line 747 in ?
    sys.exit(main(sys.argv))
  • File "/sw/bin/gtk-builder-convert", line 735 in main
    conv.parse_file(input_filename)
  • File "/sw/bin/gtk-builder-convert", line 161 in parse_file
    self._parse()
  • File "/sw/bin/gtk-builder-convert", line 274 in _parse
    reverse=True)
TypeError: sort() takes no keyword arguments

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.
Comment 3 Johan (not receiving bugmail) Dahlin 2008-11-09 16:26:24 UTC
>objects.sort(key=lambda n: n.getAttribute('id'))

can be written as:

objects.sort(lambda a, b: cmp(a.getAttribute('id'),
                              b.getAttribute('id')))

Comment 4 Johan (not receiving bugmail) Dahlin 2008-11-25 13:09:42 UTC
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.
Comment 5 Daniel Macks 2009-01-13 02:00:15 UTC
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):
  • File "/sw/bin/gtk-builder-convert", line 751 in ?
    sys.exit(main(sys.argv))
  • File "/sw/bin/gtk-builder-convert", line 739 in main
    conv.parse_file(input_filename)
  • File "/sw/bin/gtk-builder-convert", line 161 in parse_file
    self._parse()
  • File "/sw/bin/gtk-builder-convert", line 259 in _parse
    self._convert(node.getAttribute("class"), node)
  • File "/sw/bin/gtk-builder-convert", line 296 in _convert
    self._default_widget_converter(node)
  • File "/sw/bin/gtk-builder-convert", line 316 in _default_widget_converter
    self._convert_adjustment(prop)
  • File "/sw/bin/gtk-builder-convert", line 533 in _convert_adjustment
    page_size=page_size)
TypeError: update() takes no keyword arguments

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.
Comment 6 Daniel Macks 2009-01-13 05:05:20 UTC
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})
Comment 7 Yitz Gale 2009-04-26 18:39:46 UTC
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.
Comment 8 Yitz Gale 2009-04-27 12:31:16 UTC
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.
Comment 9 Javier Jardón (IRC: jjardon) 2011-06-01 10:33:40 UTC
gtk-builder-convert has been removed from GTK+.

Also, using Glade is the prefered methos to convert files from libglade to GtkBuilder format