Version 1 (modified by Cas, 10 years ago) (diff)

--

Python 3 Port

This page provides more detailed information on porting to Python 3 started in ticket #1328.

The current consensus is that the core and common files should be prepared for a future Twisted release with full Python 3 support and UI's worked on at a later date.

References

It is best to read these other documents on Python 3 porting

Django https://wiki.ubuntu.com/Python/3 https://twistedmatrix.com/trac/wiki/Plan/Python3

Twisted

Deluge relies on all dependant packages supporting Python 3 with twisted being the most crucial. At the time of writing there is minimal Python 3 support in Twisted >= 12.3 but work is still ongoing: Twisted Python 3 Plan.

2to3

Although 2to3 will highlight areas requiring changes it cannot be relied upon to make the correct decisions especially concerting bytes and unicode strings so do not commit code changes generated by it.

Required changes

  • Change setup.py from setuptools to distribute
  • Magic Method __cmp__ in common.py replaced with __lt__
  • Found at least one instance of raise with three args in Blocklist plugin
  • peerguardian.py in Blocklist plugin - Rename next() to __next__() and add next = __next__ to class
  • iteritems() where needed replace with try/except: http://python3porting.com/differences.html#dictionary-methods

Future Imports

from __future__ import unicode_literals
Likely to be applied to all files to ensure byte, Unicode string separation
from __future__ import division and from __future__ import print_function
Added to files where required
from __future__ import absolute_import
Should not be required if the imports are properly set up. See: http://python3porting.com/differences.html#imports

Six Module

It might be easier and simpler to add this module but should first determine how much of the code can be converted without using it.