wiki:WikiStart
Last modified 4 years ago Last modified on 02/21/10 17:29:35

2to3c

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

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@…)