Jump to: navigation, search

Difference between revisions of "Python3"

(OpenStack clients)
(OpenStack clients)
Line 92: Line 92:
 
| python-ironicclient      || style="background-color: red;" | No || Yes || ? ||  
 
| python-ironicclient      || style="background-color: red;" | No || Yes || ? ||  
 
|-
 
|-
| python-keystoneclient || style="background-color: orange;" | In progress || Yes || HTTPretty ||  
+
| python-keystoneclient || style="background-color: lightgreen;" | OK || style="background-color:lightgreen;" | OK ||
 
|-
 
|-
 
| python-marconiclient      || style="background-color: lightgreen;" | Yes || Yes ||  ||  
 
| python-marconiclient      || style="background-color: lightgreen;" | Yes || Yes ||  ||  
Line 107: Line 107:
 
* Minor 2to3 issues
 
* Minor 2to3 issues
 
* python-keystoneclient
 
* python-keystoneclient
 +
|| See patches at https://review.openstack.org/#/dashboard/8122
 
|-
 
|-
 
| python-swiftclient        || style="background-color: orange;" | In progress || Yes  || Differences between Python 2 and 3  ||  
 
| python-swiftclient        || style="background-color: orange;" | In progress || Yes  || Differences between Python 2 and 3  ||  

Revision as of 01:56, 13 February 2014

This page tracks the progress of Python 3 effort porting for OpenStack.

Python 3

Why should OpenStack move to Python 3 right now?

Python 3 is usually seen as the new Python version which breaks compatibility and raises new Unicode issues. Python 3 is much more than that. It’s a new clean language which has a more consistent syntax. It has many new features, not less than 15 new modules. Python 3 is already well supported by major Linux distributions, whereas Python 2.7 reached its end-of-life. Slowly, some bugs cannot be fixed in Python 2.7 anymore and are only fixed in the latest Python 3 release. Python 3 is now 5 years old and considered as a mature programming language.

Port Python 2 code to Python 3

OpenStack project chose to use the same code base for Python 2 and Python 3. The Six: Python 2 and 3 Compatibility Library helps to write code working on both versions.

References to port Python 2 code to Python 3

Common pitfalls

What is a string ?

You should definitely not talk about "strings" in your commit logs/reviews. In Python 2, a 'string' is bytes; in Python 3, it's a Unicode text string. The following code snippet may help in understanding the difference:

Python 2:

   >>> type('foo')
   <type 'str'>
   >>> type(u'foo')
   <type 'unicode'>
   >>> type(b'foo')
   <type 'str'>
   >>> isinstance('foo', six.text_type)
   False
   >>> isinstance(u'foo', six.text_type)
   True
   >>> bytes is str
   True
   >>> b'foo'[0]
   'f'

Python 3:

   >>> type('foo')
   <class 'str'>
   >>> type(u'foo')
   <class 'str'>
   >>> type(b'foo')
   <class 'bytes'>
   >>> isinstance('foo', six.text_type)
   True
   >>> isinstance(b'foo', six.text_type)
   False
   >>> bytes is str
   False
   >>> b'foo'[0]
   102

Python 3 of OpenStack Dependencies

Blocker Pointer: it's not yet possible to specify different list of dependencies for Python 2 and Python 3. For example, mox only works on Python 2, mox3 can be used on Python 3.

OpenStack Dependencies:

  • mox: use mox3 or port tests on mock which works on Python 3 (mock has been integrated in Python 3.3 as unittest.mock)
  • eventlet: not available on Python 3 yet, alternatives: asyncio (Tulip for Python 3.3+/Trollius for Python 2), Tornado

Portage in progress

  • Oslo Messaging: Portage in Progress by Victor Stinner (dashboard)
  • keystoneclient: Portage in Progress by Cyril Roelandt (dashboard)
  • glanceclient: Portage in Progress by Yassine Lamgarchal (dashboard)

Python 3 Status of OpenStack projects

See also Python3Deps.

OpenStack clients

Project Python 3 compatibility CI tests running? Blocked by Comment
python-ceilometerclient In Progress Yes python-keystoneclient
python-cinderclient Yes Yes  ?
python-ganttclient  ?  ?  ?
python-glanceclient In Progress Yes python-keystoneclient
python-heatclient In progress Yes python-keystoneclient
python-ironicclient No Yes  ?
python-keystoneclient OK OK
python-marconiclient Yes Yes
python-melangeclient  ?  ?  ?
python-novaclient OK YES
python-neutronclient In progress No Differences between Python 2 and 3
python-openstackclient No Yes  ?
python-savannaclient In progress Yes
  • Minor 2to3 issues
  • python-keystoneclient
See patches at https://review.openstack.org/#/dashboard/8122
python-swiftclient In progress Yes Differences between Python 2 and 3
python-tuskarclient In Progress Yes python-keystoneclient
python-troveclient Yes Yes

Others

Project Python 3 compatibility CI tests running? Blocked by Comment
Ceilometer NO NO mysql-python
Neutron NO NO
  • eventlet
  • python-neutronclient
Nova NO NO
oslo.config OK Yes
oslo-incubator In progress No
  • eventlet and greenlet not py3 compatible
  • qpid not py3 compatible
  • mysql-python not py3 compatible
  • pyzmq not py3 compatible
  • sqlalchemy-migrate not py3 compatible
  • mox not compatible but pymox3 works fine
Being worked on by Chuck Short and Julien Danjou
pbr OK Yes
trove NO NO mysql-python

Reports at OpenStack Summits

Dependencies

This is an attempt to document which OpenStack dependencies work under Python 3. We're starting with oslo, since it's the base of everything else, then gradually including other projects.

oslo.config

pip-requires

  • argparse - included with Python 2.7+. The separate package is only needed for 2.6.

test-requires

  • mox - mox3 supports Python, or replace mox with mock (which is now included in python 3.3)
  • nose - supports Python 3
  • nose-exclude - 2.6-2.7, 3.1-3.3
  • testtools - 2.6-2.7, 3.2-3.3
  • coverage - supports 2.3-3.3
  • sphinx - supports Python 3

oslo-incubator

pip-requires

  • PasteDeploy: supports 2.5-3.3
  • WebOb: support Python 3
  • eventlet: NO (MAJOR PAIN POINT) (gevent doesn't either, though there are some old forks that tried)
  • greenlet: supports 2.4-3.2 (lack of 3.3 may be false negative)
  • lxml: supports 2.4-3.3
  • routes: supports 2.6-3.3
  • iso8601: NO (perhaps try python-dateutil, specifically the parser module?)
  • anyjson: 2.4-3.1 (lack of 3.2-3.3 may be false negatives)
  • kombu: supports Python 3 (exact version not given)
  • argparse: included in Python 2.7+
  • stevedore: supports 2.7, 3.2, and 3.3
  • SQLAlchemy: supports Python 3 (exact version not given)
  • qpid-python: NO

test-requires

  • distribute: 2.4-3.3
  • coverage: 2.3-3.3
  • fixtures: supports Python 3 (exact version not given)
  • mock: 2.5-3.3
  • mox: use mox3, or replace mox with mock (which is now included in python 3.3)
  • mysql-python: NO (maybe try pymysql instead?)
  • nose: Supports Python 3
  • nose-exclude: 2.6-2.7, 3.1-3.3
  • nosexcover: NO (bug in tracker from 2012-05; no comments)
  • nosehtmloutput: ?
  • pep8: Supports Python 3
  • pyflakes: Supports Python 3
  • pylint: Supports Python 3 (tested with Python 3.2)
  • pyzmq: Supports 2.6-2.7, 3.2+
  • redis: Supports 2.5-2.7, 3.2+
  • setuptools-git: 2.4-2.7, 3.1-3.3
  • sphinx: Supports Python 3
  • testtools: 2.6-2.7, 3.2-3.3
  • webtest: 2.6-2.7, 3.2-3.3