[Biopython-dev] Python 3 porting

Tiago Antão tiagoantao at gmail.com
Sun Jul 11 09:30:04 UTC 2010


2010/7/11 Eric Talevich <eric.talevich at gmail.com>:
> NumPy is keeping notes on what they did to make their code work on Python 3.
> Have you seen this?
> http://projects.scipy.org/numpy/browser/trunk/doc/Py3K.txt
>
> They use 2to3 in setup.py, too.

I did not know about that link, many thanks.

But their use of 2to3 on setup.py seems very good (BTW, the setup that
I've sent you in a previous message does that and is inspired in
numpy).

Inspired on numpy, here is a suggestion on how things might work in a
biopython version that is both 2 and 3 compatible:

1. There is a single code base written in Python 2. This code base is
"3-aware" (just check Peter's commits in the last few days for lots of
examples of this) in the sense that some constructs are not possible.
A few (very rare?) if sys.version_info[0]==3 do exist.
2. On setup.py, if python3 is detected 2to3 is called and the code is
converted. As the code base was sensibly prepared, the code will
compile on 3 with just 2to3 (no need for manual intervention at all).

This means a single code base (no branching). Let me repeat this, as I
think it is important from a maintenance perspective: no need for
different branches!
Also note that my prototype setup.py (anyone interested please send me
an email and I will send a copy out of list - just to avoid
attachments to the list) is both 2 and 3 compatible (runs on both
versions unchanged) but it still has some flaws: no doctest conversion
and no test conversion. But it illustrates the point that a setup.py
(2to3 based) like numpy works for biopython.

This means development proceeds in 2.x (code is converted from 2 to 3,
not the opposite).

I was thinking in doing a small script that every night does a git
pull, runs the tests in python3 and, if something that was py3k
compatible in the past does break, then it sends an email to
biopython-dev. The point of this would be to make development the
least cumbersome possible: people do not want to have to test
everything in BOTH 2 and 3 (just 2). They only have to intervene (and
are only informed) if there is a new problem.

Best,
Tiago



More information about the Biopython-dev mailing list