Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Python 3 #379

Merged
merged 5 commits into from
Dec 9, 2014
Merged

Add Support for Python 3 #379

merged 5 commits into from
Dec 9, 2014

Conversation

hazen
Copy link

@hazen hazen commented Nov 13, 2014

This is a wide-sweeping change which allows the Python client to run on these versions:

  • 2.6.9
  • 2.7.8
  • 3.3.6
  • 3.4.2

The six module is critical in supporting both Python 2 and Python 3 and is used whenever appropriate.
In other places conditions have been added with the six.PY2 and six.PY3 constants to run the appropriate code.

Here are a few changes from Python 2 to 3 which were addressed:

  • print is now a function
  • Relative module pathnames are no longer supported
  • All strings are now Unicode by default
  • PBC library requires binary (bytes) instead of strings
  • dicts return iterators, not lists in iterable contexts
  • long type has been deprecated and int is now 64-bit
  • Libraries have been reorganized, especially HTTP and exceptions, so imports have changed
  • next() in the iterable interface is now __next()__
  • Socket library is greatly different, so for security the native ssl library is used instead of PyOpenSSL to support HTTP
  • Python 3.3 ssl library is not as mature as Python 3.4 so lacks a few features (like TLS 1.2)
  • Python 3 ssl library only allows certificate files, not bytes treams, to be added so the SecurityCreds class does not support cached files like it does in Python 2
  • Some unit test assertions were renamed, so test_six.py was introduced to hand the renames
  • xrange() was retired so range() was used in its stead
  • Tests for riak_object were adjusted in Python 3 since strings need to be encoded before sent to the transport layer
  • The built-in unit tests in Python 3.4.2 actually don't test CRLs, so for now they are not supported in Python 3.x client
  • Python 3 client supports Unicode key and bucket names, unlike Python 2
  • The file open interface changed slightly

NOTE: This PR is dependent upon riak_pb basho/riak_pb#104

@@ -104,13 +104,17 @@ def next(self):
else:
if self.rehearse:
gc.collect()
print ("-" * 59)
print
print("-" * 59)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For safety, shouldn't the Python 2 version from __future__ import print_function?

- actually return from __next()__
- use isinstance instead == to determine object type
- import print_function from __future__ for Python 2
- port assertItemsEqual() from Python2 to Python3
- actually run the YZ tests 😲
@hazen hazen force-pushed the bch/feature/python3 branch from 702cb3e to 5b006f7 Compare November 13, 2014 23:20
@@ -1,12 +1,21 @@
#!/usr/bin/env python
import platform
from six import PY2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not having this installed was my first roadblock, and there doesn't seem to be anything that requires it in the setup file, commands or version. Since this is only used to detect Python 2, can you change it to the simpler version like on line 20?

It'd be reasonable to include it as a dependency in the package, however, since it's used in so many places.

@seancribbs
Copy link

👍 533aea5

borshop added a commit that referenced this pull request Dec 9, 2014
Add Support for Python 3

Reviewed-by: seancribbs
@hazen
Copy link
Author

hazen commented Dec 9, 2014

@borshop merge

@borshop borshop merged commit 533aea5 into master Dec 9, 2014
@hazen hazen deleted the bch/feature/python3 branch December 9, 2014 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants