Overview
CloudBolt is aiming to support Python 3 by version 8.0, and any custom Plug-ins or Actions must also be updated before upgrading. Here is a brief guide to updating your Python code to be compatible with both Python 2 and 3.
Considerations
One of the easiest tools to automatically check your plugin compatibility is 2to3. Run it on the source files of your Plug-ins, and a diff against the original source file is printed.
Most Plug-ins and Actions won't be using methods or syntax that have significant changes. But there are a few common differences that you should review.
Procedure
Step 1: Print statements need to be a method:
Step 2: Raising exceptions should also use a method to set a specific error message:
Step 3: Catching exceptions need to use 'as' instead of a comma:
Step 4 Unicode changes will impact how data is read from external sources like the 'requests' library:
Step 5: String formatting has changed, and the old % formatting is no longer allowed:
Additional information
Here are a few excellent resources on the topic that can provide more detailed information:
https://docs.djangoproject.com/en/1.11/topics/python3/
https://docs.python.org/3/howto/pyporting.html#pyporting-howto
http://python-future.org/compatible_idioms.html#strings-and-bytes
If you have any trouble updating your code, please review those resources, and feel free to contact CloudBolt support at support@cloudboltsoftware.com.
0 Comments