Making KDE applications Python 3 friendly
By einar
- CommentsWhen I’m not on forum duty or handling openSUSE-related contributions, I try to improve my code contributions to KDE, even though I’m by no means an experienced programmer (I program all day long in Python, but I’m still a biologist after all). For the upcoming 4.10 release I’ve been polishing up Python 3 support.
As you may know, Python 3 isn’t the standard in many distributions (Arch Linux excluded), but despite the slow start, it is slowly gaining steam. PyKDE4 was built keeping in mind Python 3 support, so theoretically we supported it right from the start.
When I wanted to package PyKDE4 for Python 3 in openSUSE, I stumbled upon some quirks: the CMake build system was not finding Python 3 properly. After some investigation, I noticed that the Python macros responsible for finding the Python library had some assumptions that worked fine for Python 2, but not for Python 3 (a lot of distributions name libypthon3 with a suffix, like mu). Since 4.10 was bumping the minimum required CMake version to 2.8.8, I moved in and rewrote the macros making use of the new functionality offered by upstream CMake (with a big help from Rolf Eike Beer).
As I worked more on PyKDE4, I hit a second snag: i18n() calls were chocking on Unicode. As QString is Unicode-aware, that was really difficult to debug. The root cause was actually a SNAFU of my own caused by swapping lines, and will be fixed in 4.9.4 and 4.10.
Lastly, I got word that Kate’s Pate was not building on Python 3. This caused a huge back and forth of mails and IRC conversations between me and Pate’s developer, Shaheed Haque. I initially fixed building with a very crude patch, which Shaheed improved afterwards. Then the product built under Python 3.3, but kept on crashing. After some debugging, two different issues were found (module not found when imported, and string conversions). With those fixed, Pate would load in Kate but crash when any plugin documentation was loaded. A few more rounds of discussion and commits, and I’m happy to report that everything works as intended!
[![]({{ site.url }}/images/2012/12/pate_py3-300x205.png)]({{ site.url }}/images/2012/12/pate_py3.png)
In short, 4.10 should be a good release for Python 3 users. I have some ideas for 4.11 as well: time will tell if I get around to doing them.