2to3c is a tool to help with porting Python 2 extensions written in C so that they will compile against both 2.6 and 3.1 (and possibly other versions of CPython)
It uses the Coccinelle tool to apply a series of "semantic patches" to .c files.
The aim of 2to3c is to simplify the porting process and reduce the amount of effort needed. Unfortunately it's impossible to fully automate this process: typically you will need to decide whether your Python 2 "str" instances are bytes or encoded string data (Hopefully 2to3c makes the process much easier)
The project is in an early stage of development; it may or may not work, but has already saved time on at least one port to python 3 (dbus-python).
If 2to3c helps you please let me know (dmalcolm@…) - ideally there'll eventually be a list of "success stories" here. You can file bugs in this Trac instance (I believe you'll need a Fedora account to log in).
Fixes that 2to3c can make
- Changes to module initialization API (see also https://fedorahosted.org/2to3c/browser/fixes/initmodule.py)
- Replacement of the PyInt with PyLong
- Changes to the location of the ob_type field within PyObject subclasses
- tp_repr methods should now return PyUnicode
- Eliminate usage of the #define alias RO for READONLY in structmember.h
- Use the PyVarObject_HEAD_INIT macro when initializing PyTypeObject instances to cope with a change in the layout of these structures.
Getting the code
Sources are in a git repository. To check out the code, run:
git clone git://git.fedorahosted.org/2to3c.git cd 2to3c python 2to3c --help
Usage: 2to3c [options] filenames... Options: -h, --help show this help message and exit -w, --write Write back modified files
(Not properly packaged yet; patches welcome: send to dmalcolm@…)