| 1 | = Python 3 Port = |
| 2 | |
| 3 | This page provides more detailed information on porting to Python 3 started in ticket #1328. |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | == References == |
| 8 | |
| 9 | It is best to read these other documents on Python 3 porting |
| 10 | |
| 11 | [https://docs.djangoproject.com/en/dev/topics/python3/ Django] |
| 12 | [https://wiki.ubuntu.com/Python/3] |
| 13 | [https://twistedmatrix.com/trac/wiki/Plan/Python3] |
| 14 | |
| 15 | == Twisted == |
| 16 | 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: [https://twistedmatrix.com/trac/wiki/Plan/Python3 Twisted Python 3 Plan]. |
| 17 | |
| 18 | |
| 19 | == 2to3 == |
| 20 | |
| 21 | 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. |
| 22 | |
| 23 | |
| 24 | == Required changes == |
| 25 | |
| 26 | * Change setup.py from `setuptools` to `distribute` |
| 27 | * Magic Method `__cmp__` in `common.py` replaced with `__lt__` |
| 28 | * Found at least one instance of raise with three args in Blocklist plugin |
| 29 | * peerguardian.py in Blocklist plugin - Rename `next()` to `__next__()` and add `next = __next__` to class |
| 30 | * `iteritems()` where needed replace with try/except: http://python3porting.com/differences.html#dictionary-methods |
| 31 | |
| 32 | == Future Imports == |
| 33 | |
| 34 | `from __future__ import unicode_literals`:: |
| 35 | Likely to be applied to all files to ensure byte, Unicode string separation |
| 36 | |
| 37 | `from __future__ import division` ''and'' `from __future__ import print_function`:: |
| 38 | Added to files where required |
| 39 | |
| 40 | `from __future__ import absolute_import`:: |
| 41 | Should not be required if the imports are properly set up. See: http://python3porting.com/differences.html#imports |
| 42 | |
| 43 | == Six Module == |
| 44 | |
| 45 | 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. |