Python 2 no longer supported

dm-dev
Tags: #<Tag:0x00007fd88e944fa8>

(Tim Jenness) #1

Now that v15.0 has been released and following the previously announced timeline, DM code no longer needs to work with Python 2. This week the Python 2 jobs will be removed from Jenkins and the python EUPS package will be updated to refuse to allow Python 2.

This means that developers can now start to use Python 3.6 features. As discussed here all Python 3.6 features are allowed. The one exception is type and function annotations. These need to be discussed to see how they interact with our numpydoc usage (and pybind11).

We will begin to remove the use of future from the DM code but there is no requirement to do this immediately. Any code that does from builtins import... is a no-op on Python 3 and can be removed at any time if you notice it. Usage of past.builtins will require explicit fix ups to remove usage of long, basestring, unicode, and execfile and this work will be scheduled.

There are many resources online describing Python 3. For example:

I also recommend the Fluent Python O’Reilly book. If people have other recommendations please reply to this topic.


(John Swinbank) #2

As of today, we build and deploy weekly releases for both Python 2 and 3 on the “shared stacks” on developer hardware (refer to the Developer Guide for details).

I don’t plan to turn off the Python 2 build until it actually breaks (the latest weekly at time of writing, w_2018_15, seems fine). However, when we get a Python 2 failure, I’ll simply turn off the build scripts. The old stack will remain in place for (at least) a few months for historical purposes. (Ultimately, it may have to be removed to save disk space.)


(John Parejko) #3

Related to this, the one thing that developers might have to be careful about when removing builtins imports is from future.utils import with_metaclass. When removing this line, you have to change the class declaration as well. For example:

from future.utils import with_metaclass

class FooTask(with_metaclass(abc.ABCMeta, pipeBase.Task)):
    pass

would become

class FooTask(pipeBase.Task, metaclass=abc.ABCMeta)):
    pass

Because pipeBase.Task isn’t a metaclass itself, but ABCMeta is.


(Krzysztof Findeisen) #4

I’m pretty sure removing anything that came from future.utils requires code changes.


(Tim Jenness) #5

Yes. future.utils and past.builtins indicate you have to update your code. from builtins import blah is a no-op and can be removed without affecting the rest of the file.