Python 2to3

Project Introduction

Sugar currently uses Python 2. Since support for python 2 is being drawn, we are porting our code to Python 3.

It is one of the goals for Sugar Labs for 2018, with a suggested timeframe of ~12-16 months for completing the project.

The project was taken up by Sugar Labs in Google Summer of Code 2018

Project Summary

The project progress can be tracked here.

Sugar
Target: Port entirely to Python 3
WIP: https://github.com/Pro-Panda/sugar/tree/python3
Status: While some critical issues still persist, most of the functionality is running and tested.
Sugar-Toolkit-Gtk3
Target: Should be compatible with both Python 2 and Python 3, to support the large number of activities currently in Python 2
WIP: https://github.com/Pro-Panda/sugar-toolkit-gtk3/tree/python3-port
Status: Mostly Complete; what remains is an entire project in itself of porting the Telepathy Bindings.
Critical changes implelmented:
  • Python 3 activities must be instantiated with sugar-activity3 instead of sugar-activity
  • sugar-activity-web will call the Python 3 version of the toolkit and will be installed only with the same
  • warning logged if activity is not ported to Python 3

Note: To test the toolkit without porting the telepathy bindings, please use the Python 3 bindings (not for release), https://github.com/pro-panda/telepathy3


Sugar-Datastore
Target: Port entirely to Python 3
WIP: https://github.com/Pro-Panda/sugar-datastore/tree/python3-port
Status: Complete(possible fix patches do come up while porting sugar); Fedora packaging and testing remains
Sugar-Artwork
Target: Port entirely to Python 3 (use system empy bindings for Python 3)
WIP: https://github.com/Pro-Panda/sugar-artwork/tree/python3-port
Status: Complete; Fedora packaging and testing remains
Sugar Desktop Activities
Guide to porting activities to Python 3 is here
Activity Status [WIP/Ported] Pull Request
Log Ported PR link
JukeBox Ported PR link
Abacus Ported PR link
Calculate Ported PR link
Chat Ported PR link
CowBulls Ported PR link
Finance Ported PR link
Hello-world Ported PR link
Imageviewer Ported PR link
Read Ported PR link
Spirolaterals Ported PR link
Terminal Ported PR link
Write Ported PR link
Nutrition Ported PR link

Contributing to the Project

There are several ways of contributing to the project

Port Telepathy bindings
Telepathy does not have python 3 bindings and needs to be ported to its PyGObject bindings as a prerequisite for porting to Python 3
See https://github.com/orgs/sugarlabs/projects/4
Test Debian Packages
Debian packages for core modules here: https://github.com/Pro-Panda/sugar-packages
Please install, test and report bugs, (or better, submit fix patches)
Fedora Packaging
Make Fedora packages of core modules (WIP links above) and test them
Port Sugar Desktop Activities to Python 3
See the guide to port activities to Python 3: https://github.com/sugarlabs/sugar-docs/blob/master/src/python-porting-guide.md
Improve test coverage
Sugar and the components lack in testing mechanisms and scripts. Our current test coverage is very basic and minimal. Improving the same is critical and the best time would be to so while Porting and testing the components
Some test scripts are here - https://github.com/Pro-Panda/sugar-python3-tests


Notes

  • httplib.HTTP is not available in Python 3; use http.client.HTTPConnection instead
  • cmp function does not exist in Python 3, use the cmp_to_key function; see https://docs.python.org/3/howto/sorting.html#sortinghowto
  • list.sort function requires named parameters in Python 3
  • hashlib.md5 requires bytes as an argument in Python 3
  • sha_hash.update requires bytes as an argument in Python 3
  • statvfs does not exist in Python 3, verify the Python 2 constant values and use them instead