Having a library working under Python 2.X and Python 3.X is not easy.
Having unittest, doctest, scripts, documentation and packaging working under both Python 2.x and 3.x is a lot of work.
This is what I did with pyzmail.
A good way to start, is to use distribute to release your package.
Start by reading Supporting both Python 2 and Python 3 with Distribute.
The idea is to have unittest working for both 2.x and 3.x. Distribute provides a nice way to test your unittest on both python 2.x and 3.x,
it convert your 2.x source into 3.x using 2to3 and run your test suite on it.
Every time you have a failure or a stack trace, correct the 2.x source and re-run the unittest on both.
When it works, use options use_2to3 in your setup.py and distribute will use 2to3 automatically to convert your sources when installing on 3.x platforms.
The main problem when migration to 3.x is when you mix bytes-strings, strings and unicode strings. The solution is often to use the b'' notation and use explicit .encode() and .decode() when required.
Good luck.
Add new comment