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
Compatibility For Python3 #122
Conversation
Awesome, thanks Dan. Going apply this soon. I've not done much with Python 3 yet, so I'm using your changes to familiarize myself with Python 3. |
Thanks! I think its a little clearer what is happening in python3 vs python2 when done this way versus 2to3. The differences really boil down to just a few type changes. |
I'll be merging this stuff in once the connection_refactor branch goes in. Thanks again for the work on this Dan. |
Sweet! I'll check out the connection_refactor too since it probably effects code I have |
connection_refactor has been merged to master and rolled into redis-py 2.4.0. I'd like to get to adding Python 3 support next. I'll start looking at your patch over the next couple days. |
sounds good. there shouldnt be any issues, but there might be some changes that are needed in the connection_refactor branch. |
I attempted a merge today and got multiple conflicts. It will require a little work to merge this in with the connection refactor. |
Why not |
Well, since this patch will certainly not apply cleanly to the redis-py/master, something has to be done to bring in python3 compatibility. However, I've never been happy with 2_to_3's results. This patch was a very small amount of code to manage the compatibility without having to compile code at deployment time; a small amount of code which I have not had the time to maintain. We did look at the 2_to_3 option initially and we would likely need fixers for 2_to_3 to apply correctly which means maintaining code anyway. I'm not sure where that comes out as cleaner. Anyway, if you present a patch, I'm open to new ideas. I do like the idea of using Tox for testing; any help getting that setup is greatly appreciated since I have little experience with it and little time. |
I can`t write bytes to database import redis Writes: |
@atomAltera What version of redis-py are you using? And are you running on Python 3? |
@andymccurdy Why redis-py trys to decode binary data to utf-8 string? |
I've implemented python3 compatibility in my fork: https://github.com/bluepeppers/redis-py All tests but one pass on python 3 (and I'm not sure what's up with the failing one), and all pass on python 2. |
And what about this one dcolish@63e3414 ? |
That's someone else's repo. I don't know about it, but it seems to be the one you had problems with bytes on. My implementation doesn't call decode on user data, so all commands return |
Test suite seems to have to be run using tox. It helps tests to be run on multiple environments (various Python versions e.g. Python 2.6, 2.7, 3.2 and various Python implementations e.g. PyPy, Jython). |
I Can't install it on python3.2 (Windows XP) Traceback (most recent call last): On Debian with python3.1 works |
@atom, I think that's a problem with your python 3 install, try doing 'import socket' in your python 3 repl. @dahlia, I'll try using tox, I was just using nose with cpython 2.7 and stackless 3.2. Have you/redis-py concidered using Travis-ci to automatically run the tests over a fairly large range of cpython versions? |
Travis-ci would definitely help things here. One of the reasons I haven't merged this previously is I don't have a Python 3 environment that I actively use, so committing to supporting it has been a challenge. Punting that over to Travis-ci would certainly lessen the burden. |
@bluepeppers finely, it`s work. Thanks |
@andymccurdy, Travis-ci supports redis out of the box, so setting it up shouldn't be hard. Also, I've only tested my port on python 2.7, what's the lowest version of python that redis-py supports? |
@bluepeppers Currently 2.5. It needs the |
I've abandoned work on my branch. It was working at the time I ported it but has been left to diverge greatly from the current redis-py. I cannot make any guarantees that it would still work. |
Ok, my fork now works from 2.5 to 3.2, and I've set up travis ci on my repo: http://travis-ci.org/#!/bluepeppers/redis-py. It should be fine to merge now if you want to. Things to note going forward are that when comparing between responses from redis and string literals, the string literal will need to have |
@bluepeppers how you convert input values to bytes? str(value).encode()? |
Input values are automatically encoded here: https://github.com/bluepeppers/redis-py/blob/master/redis/connection.py#L287 Basically, test if they're bytes already, if not then call unicode on them (if they are already unicode this will have no effect), then encode them with the given encoding. |
@bluepeppers nice. |
There are no differences in the API other than the bytes/unicode issue that I can see. |
Maybe it will be better to create separate package named e.g. redis-py3 not compatible with python 2.x? |
Python 3.x support has landed in redis-py master. It will be officially released in 2.6.1. Would love to hear feedback from anyone who would like to help test against master. |
Python 3.x support has been officially released as of 2.6.2. Closing this issue. |
I've completed the changes required to have redis-py work with python 2 and python 3. The only issue outstanding is that hiredis-py will not work with python 3. I have begun that port and made some good progress, but there are still a few unfinished items. I'm not sure its a blocker for us.