Upgrade to current stable Python 3.x release
Links
- Link to pull request: https://github.com/PBSPro/pbspro/pull/1227
Overview
Current Python version = 2.7
Target Python version = 3.6
- Major changes in Python 3:
https://docs.python.org/3.6/howto/pyporting.html
http://python3porting.com/bookindex.html
- Using lib2to3:
2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code. The standard library contains a rich set of fixers that will handle almost all code. 2to3 supporting librarylib2to3
is, however, a flexible and generic library, so it is possible to write your own fixers for 2to3.lib2to3
could also be adapted to custom applications in which Python code needs to be edited automatically.
Usage: /usr/bin/python3.6 -m lib2to3 -f all -f buffer -f idioms -f set_literal -f ws_comma -w -W <python file path>
-f all : Apply all default fixers
-f <name of fixer>: Apply a specific fixer
-w: Write changes to a file
-W: always write output files even if no changes were required to the file - A list python APIs which we have used in C files of PBSPro and have changes in Python 3 (Not a complete list):
API in Python 2 | API in Python 3 |
---|---|
|
|
char* PyString_AsString(PyObject *string) | char* PyUnicode_AsUTF8(PyObject *unicode) |
int PyString_Check(PyObject *o) | int PyUnicode_Check(PyObject *o) |
PyObject* PyString_InternFromString(const char *v) | PyObject* PyUnicode_InternFromString(const char *v) |
PyObject* PyString_FromString(const char *v) | PyObject *PyUnicode_FromString(const char *u) |
PyObject* Py_InitModule3(char *name, PyMethodDef *methods, char *doc) | PyObject* PyModule_Create(PyModuleDef *def) |
struct _inittab | struct _inittab |
PyObject* PyInt_FromLong(long ival) | PyObject* PyLong_FromLong(long v) |
PyObject* PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE*)) | PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const char *encoding, const char *errors, const char *newline, int closefd) |
unsigned PY_LONG_LONG PyInt_AsUnsignedLongLongMask(PyObject *io) | unsigned long long PyLong_AsUnsignedLongLongMask(PyObject *obj) |
PyObject_HEAD_INIT(type) | PyVarObject_HEAD_INIT(type, size) |
PyTypeObject *tp = obj->ob_type; | PyTypeObject *tp = Py_Type(obj);[3] |
PyTypeObject structure | Some fields are deprecated and new fields are added to PyTypeObject structure. |
void init_pbs_ifl(void) | PyObject * PyInit__pbs_ifl(void) |
Project Documentation Main Page