[Biopython-dev] Python 2 and 3 migration thoughts

Peter Cock p.j.a.cock at googlemail.com
Thu May 30 13:33:22 UTC 2013


Splitting off from this thread:
http://lists.open-bio.org/pipermail/biopython/2013-May/008601.html

On Thu, May 30, 2013 at 2:13 PM, Peter Cock <p.j.a.cock at googlemail.com> wrote:
> Thank you for all the comments so far, don't stop yet :)
>
> On Thu, May 30, 2013 at 1:51 PM, Wibowo Arindrarto
> <w.arindrarto at gmail.com> wrote:
>> Hi everyone,
>>
>> I'm leaning towards insisting on Python >=3.3 support (I'm running
>> 3.3.2). I suppose that even if Python3.3 is not available on a machine
>> or through the default package manager, it's always installable on its
>> own. If that's not the case, I imagine Python2.x is most likely
>> present in these machines (so Biopython can still be used).
>
> True.
>
> So far everyone who has replied (including some off list) have said
> they are using Python 3.3 which is encouraging. Thank you for
> the comments so far.
>
> It looks like we can forget about Python 3.1, and just need to
> decide if it is worth including Python 3.2.5 in the short term.
>
>> On a related note, do we have a defined timeline on when we
>> would drop support for Python2.x? Are there any plans to have
>> our codebase written in Python3.x instead of Python2.x?
>
> Nothing concrete planned, no. I'll reply in more detail on the
> biopython-dev list as I do have some thoughts about this.

Good question Bow,

I think people will still be using Python 2 a year or two from
now, so we must support both for some time.

Biopython 1.62 (next week perhaps?)
- Final release with Python 2.5 support
- Official support for Python 2.5, 2.6, 2.7 and 3.3
- Possibly official support for Python 3.2.5+ as well?

(Exactly which versions of Python 3 we'll include to be
decided, see the other thread for that discussion.)

Short term we will continue with developing using Python 2
syntax and running 2to3 for Python 3. As far as I know,
the reverse process with 3to2 is not well established. If
anyone wants to investigate that would be useful as
another option. However, dropping Python 2.5 support
makes things more flexible...

Medium term I believe it would be possible to have a single
code base which is both valid Python 2 and 3 at the same
time. This may require us to target 2.7 and 3.3+ only - we'll
have to try it and see if Python 2.6 will hold us back.

I've actually done this with lzma.backports, a small but
non-trivial module with Python and C code:

https://pypi.python.org/pypi/backports.lzma/
https://github.com/peterjc/backports.lzma

Python 3.3 reintroduces some features designed to make
this more straightforward, like unicode literals (missing in
the early versions of Python 3). This is why I'd like to drop
Python 3.2 as soon as possible.

What I was thinking is we can start migrating modules on a
case by case basis from "Python 2 syntax" to "Dual syntax"
one by one, with a white-list in the do2to3.py script. That
way over time less and less modules need to be converted
via 2to3, and "python3 setup.py install" will get faster,
until eventually we can stop using 2to3 at all.

This conversion could consider the code and doctests
separately. However, using using print(example) we can
hopefully get most of the doctests and Tutorial examples
to work under both Python 2 and 3 at the same time.

That's my current thinking anyway - and I think the fact
that it would be a gradual migration from writing Python 2
specific code to writing dual 2/3 code makes it low risk
(as long as we're continuing to run regular testing).

Regards,

Peter



More information about the Biopython-dev mailing list