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 Python 3 compatibility #32

Merged
merged 15 commits into from Jul 12, 2014

Conversation

Projects
None yet
5 participants
@dan-blanchard
Member

dan-blanchard commented Jul 11, 2014

This PR makes streamparse Python 3 compatible (issue #9) by:

  • Using six for iteritems and reraise
  • Adding from __future__ import absolute_import, print_function, unicode_literals to the top of nearly every .py file.
  • Replacing the few remaining print statements with print functions.
  • Explicitly decoding/encoding all strings sent to/from spouts and bolts using UTF-8.
  • Adding 3.3 to .travis.yml.
  • Relying on a Python 3.3 compatible fork of Fabric referred to in fabric/fabric#1050 until the official Python 3 compatible version of Fabric comes out in the next few weeks.
  • Removing unittest2 from test_requires when on Python 3.

I also fixed a few pylint issues and other general correctness things like:

I have not extensively tested this beyond making sure all the unit tests pass on 2.7 and 3.3 on Travis, so let me know if I missed something.

@amontalenti

This comment has been minimized.

Show comment
Hide comment
@amontalenti

amontalenti Jul 11, 2014

Member

This looks really nice and complete, @dan-blanchard. Thank you for the contribution. We'll make sure to review in detail tomorrow and assuming all is good, we'll merge promptly and cut a release!

Member

amontalenti commented Jul 11, 2014

This looks really nice and complete, @dan-blanchard. Thank you for the contribution. We'll make sure to review in detail tomorrow and assuming all is good, we'll merge promptly and cut a release!

@dfdeshom

View changes

Show outdated Hide outdated setup.py
@dan-blanchard

This comment has been minimized.

Show comment
Hide comment
@dan-blanchard

dan-blanchard Jul 11, 2014

Member

I've switched to using a regular expression for extracting the version number like you suggested.

Member

dan-blanchard commented Jul 11, 2014

I've switched to using a regular expression for extracting the version number like you suggested.

@amontalenti

View changes

Show outdated Hide outdated README.rst
_stdout.buffer.flush()
_stdout.buffer.write(wrapped_msg)
else:
_stdout.write(wrapped_msg)

This comment has been minimized.

@amontalenti

amontalenti Jul 11, 2014

Member

This is an interesting branch. Why is it that in Py3 we need to flush first?

@amontalenti

amontalenti Jul 11, 2014

Member

This is an interesting branch. Why is it that in Py3 we need to flush first?

This comment has been minimized.

@dan-blanchard

dan-blanchard Jul 11, 2014

Member

I'm just being extra cautious. On Python 3 you can't write bytes directly to sys.stdout, but you can write to the underlying buffer, which is what I'm doing.

I cannot for the life of me find where I saw it, but somewhere I had read that when writing to the buffer directly, you should always flush first in case there are str things buffered (from using sys.stdout.write directly). In our case, I'm not sure that would ever happen, but I was just trying to be safe.

We can certainly take it out if you think it could cause performance issues or something.

@dan-blanchard

dan-blanchard Jul 11, 2014

Member

I'm just being extra cautious. On Python 3 you can't write bytes directly to sys.stdout, but you can write to the underlying buffer, which is what I'm doing.

I cannot for the life of me find where I saw it, but somewhere I had read that when writing to the buffer directly, you should always flush first in case there are str things buffered (from using sys.stdout.write directly). In our case, I'm not sure that would ever happen, but I was just trying to be safe.

We can certainly take it out if you think it could cause performance issues or something.

This comment has been minimized.

@amontalenti

amontalenti Jul 11, 2014

Member

Ah hah, interesting. I didn't know about this buffer vs direct writing difference between 2 and 3.

The official docs say:

if you are writing a library (and do not control in which context its code will be executed), be aware that the standard streams may be replaced with file-like objects like io.StringIO which do not support the buffer attribute.

But I guess in this situation, we do "control the environment", so checking for the existence of buffer isn't necessary. I think your code is good as-is, let's go with that.

@amontalenti

amontalenti Jul 11, 2014

Member

Ah hah, interesting. I didn't know about this buffer vs direct writing difference between 2 and 3.

The official docs say:

if you are writing a library (and do not control in which context its code will be executed), be aware that the standard streams may be replaced with file-like objects like io.StringIO which do not support the buffer attribute.

But I guess in this situation, we do "control the environment", so checking for the existence of buffer isn't necessary. I think your code is good as-is, let's go with that.

@amontalenti

This comment has been minimized.

Show comment
Hide comment
@amontalenti

amontalenti Jul 11, 2014

Member

I reviewed and everything looks good to me. @msukmanowsky if you approve, I'll merge this.

Member

amontalenti commented Jul 11, 2014

I reviewed and everything looks good to me. @msukmanowsky if you approve, I'll merge this.

@dan-blanchard

This comment has been minimized.

Show comment
Hide comment
@dan-blanchard

dan-blanchard Jul 11, 2014

Member

Just noticed one remaining issue: SocketServer instead of socketserver in contextmanagers.py. I'll fix that.

Member

dan-blanchard commented Jul 11, 2014

Just noticed one remaining issue: SocketServer instead of socketserver in contextmanagers.py. I'll fix that.

@dan-blanchard

This comment has been minimized.

Show comment
Hide comment
@dan-blanchard

dan-blanchard Jul 11, 2014

Member

Okay, that should be fixed now.

Member

dan-blanchard commented Jul 11, 2014

Okay, that should be fixed now.

@msukmanowsky

View changes

Show outdated Hide outdated setup.py
@msukmanowsky

View changes

Show outdated Hide outdated setup.py
@@ -226,7 +245,7 @@ def process_batch(self, key, tups):
"""
raise NotImplementedError()
def _batcher(self):
def _batch_entry(self):

This comment has been minimized.

@msukmanowsky

msukmanowsky Jul 11, 2014

Member

Continue the renaming to docstring mentions of batcher please.

@msukmanowsky

msukmanowsky Jul 11, 2014

Member

Continue the renaming to docstring mentions of batcher please.

This comment has been minimized.

@dan-blanchard

dan-blanchard Jul 12, 2014

Member

_batcher is still the name of thread, it's just that now there's no longer a naming clash where there is an attribute called _batcher that is a thread and a method called _batcher. Now the _batcher thread runs the _batch_entry method. I'm not sure the doc strings need to be updated. It depends on whether you think they should be talking about the method or the thread.

@dan-blanchard

dan-blanchard Jul 12, 2014

Member

_batcher is still the name of thread, it's just that now there's no longer a naming clash where there is an attribute called _batcher that is a thread and a method called _batcher. Now the _batcher thread runs the _batch_entry method. I'm not sure the doc strings need to be updated. It depends on whether you think they should be talking about the method or the thread.

@msukmanowsky

View changes

Show outdated Hide outdated streamparse/bolt.py
@@ -69,17 +69,17 @@ def test_3_multi_ack(self):
"task": 0,
"tuple": ["snow white and the seven dwarfs", "field2", 3, 4.252],
}
for i in xrange(5):
for i in range(5):

This comment has been minimized.

@msukmanowsky

msukmanowsky Jul 11, 2014

Member

Is there a six import we can do for the xrange -> range conversion? Minor thing.

@msukmanowsky

msukmanowsky Jul 11, 2014

Member

Is there a six import we can do for the xrange -> range conversion? Minor thing.

This comment has been minimized.

@dan-blanchard

dan-blanchard Jul 11, 2014

Member

Yes, six does have such a thing. I figured it didn't really matter since it was only 5 items, but I'll switch to using six.

@dan-blanchard

dan-blanchard Jul 11, 2014

Member

Yes, six does have such a thing. I figured it didn't really matter since it was only 5 items, but I'll switch to using six.

@msukmanowsky

This comment has been minimized.

Show comment
Hide comment
@msukmanowsky

msukmanowsky Jul 11, 2014

Member

Had a look through @dan-blanchard and overall, things look great! Just a few small knitpicks really. Thanks for moving streamparse into the future! :)

Member

msukmanowsky commented Jul 11, 2014

Had a look through @dan-blanchard and overall, things look great! Just a few small knitpicks really. Thanks for moving streamparse into the future! :)

@dan-blanchard

This comment has been minimized.

Show comment
Hide comment
@dan-blanchard

dan-blanchard Jul 12, 2014

Member

I made all the requested changes (except for the batcher thing, which I've commented on above).

Member

dan-blanchard commented Jul 12, 2014

I made all the requested changes (except for the batcher thing, which I've commented on above).

@msukmanowsky

This comment has been minimized.

Show comment
Hide comment
@msukmanowsky

msukmanowsky Jul 12, 2014

Member

Awesome! Thanks again @dan-blanchard, great work and contribution.

Member

msukmanowsky commented Jul 12, 2014

Awesome! Thanks again @dan-blanchard, great work and contribution.

msukmanowsky added a commit that referenced this pull request Jul 12, 2014

@msukmanowsky msukmanowsky merged commit 011c670 into Parsely:master Jul 12, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@amontalenti

This comment has been minimized.

Show comment
Hide comment
@amontalenti

amontalenti Jul 17, 2014

Member

@dan-blanchard @msukmanowsky sorry for the delay on this, but I did cut a new streamparse release, 0.0.13, that includes Storm 0.9.2 support & Python 3 support. https://github.com/Parsely/streamparse/releases/tag/v0.0.13 (it's up on PyPI and the Clojar dependency has been updated, too)

Member

amontalenti commented Jul 17, 2014

@dan-blanchard @msukmanowsky sorry for the delay on this, but I did cut a new streamparse release, 0.0.13, that includes Storm 0.9.2 support & Python 3 support. https://github.com/Parsely/streamparse/releases/tag/v0.0.13 (it's up on PyPI and the Clojar dependency has been updated, too)

@dan-blanchard

This comment has been minimized.

Show comment
Hide comment
@dan-blanchard
Member

dan-blanchard commented Jul 17, 2014

Thanks @amontalenti!

@apogre

This comment has been minimized.

Show comment
Hide comment
@apogre

apogre Mar 31, 2015

Trouble of python 2.7 users!!

apogre commented on e288785 Mar 31, 2015

Trouble of python 2.7 users!!

This comment has been minimized.

Show comment
Hide comment
@dan-blanchard

dan-blanchard Mar 31, 2015

Member

Is this actually not working for you on 2.7? We're using six to make sure this works with both.

Member

dan-blanchard replied Mar 31, 2015

Is this actually not working for you on 2.7? We're using six to make sure this works with both.

This comment has been minimized.

Show comment
Hide comment
@apogre

apogre Mar 31, 2015

yeah, I had to change it to older version to get it running on 2.7

apogre replied Mar 31, 2015

yeah, I had to change it to older version to get it running on 2.7

This comment has been minimized.

Show comment
Hide comment
@dan-blanchard

dan-blanchard Mar 31, 2015

Member

Could you please file an issue with a stacktrace?

Member

dan-blanchard replied Mar 31, 2015

Could you please file an issue with a stacktrace?

This comment has been minimized.

Show comment
Hide comment
@apogre

apogre Mar 31, 2015

out of workstation. Will do it tomorrow!

apogre replied Mar 31, 2015

out of workstation. Will do it tomorrow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment