-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-3761] Define cmp() in Python 3 #5843
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
Conversation
|
So I’d still rather remove them long term, but I agree in the short term hopefully this is easier to get a committer to sign off on. That being said having 3 copies of the function isn’t great, how about moving it somewhere common? |
|
Agreed. When I thought about centralizing it but the three files are not near each other in the hierarchy (io, testing, transforms) but I suppose we could do something like from apache_beam.utils.compat import cmp It also stuck me as a bit weird (in legacy Python) to import a builtin from another file so that made the try/except block essential which in turn means that just one line per file is actually saved. I will make the change if that seems like the best approach. |
|
|
||
| # pylint: enable=ungrouped-imports | ||
|
|
||
| try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one-liner has the same effect:
from past.bulitins import cmpThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@superbobry A perfect suggestion. Thanks much. Done.
holdenk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
It seems that there were failures in Cython: https://builds.apache.org/job/beam_PreCommit_Python_Commit/166/console |
|
You can run this test locally via |
9c2fcbc to
d9d8689
Compare
|
I'm curious, why does Cython fail on Jenkins? I've tried locally with both Python 2.7 and 3.6 and Cython 0.28.1, and the following imports fine: from past.builtins import unicode
print(unicode)Could it be that |
|
You could try updating tox.ini to explicitly mention that as a dep? |
|
The current approach is safer... Only redefine cmp() when it is necessary. We only have 18 more months to get this done. |
|
No, I'm not suggesting you change your approach I'm talking about addressing the jenkins build issues? |
|
There are no Jenkins build issues using my approach ;-) Besides, I think you already put futurize in all appropriate places in tox.ini |
|
Isn't https://builds.apache.org/job/beam_PreCommit_Python_Commit/166/console from your approach or am I looking at the wrong build logs? |
|
The build ran once more after d9d8689 was pushed. See: https://builds.apache.org/job/beam_PreCommit_Python_Commit/199/ |
|
Yes. The commits were squashed into a single commit. |
|
Ah ok, sorry for my confusion then :) |
No, but your approach introduces boilerplate. I think this is worth fixing given that a) there seem to be no issue with importing from |
|
OK. Can you please create a new PR that solves the problem and when it is checked in then I will gladly close this one. I have zero pride of ownership on these fixes... I merely want them resolved. |
|
Sure, will do! I actually have a PR open which addresses similar patterns in the code (see #5869). |
18741b5 to
d318ec4
Compare
As soon as apache#5843 and apache#5900 are closed, we should add F821 (undefined names) tests to the flake8 tests on Python 3. This should flag commits that contain unqualified past.builtin imports such as basestring, cmp, raw_input, reload, unicode, xrange, etc.
Signed-off-by: cclauss <cclauss@bluewin.ch>
4b614e0 to
f9242ca
Compare
|
@charlesccychen Your review please? |
|
Run Python PostCommit |
|
Thanks! This LGTM. Will merge once tests pass. |
|
Can someone please help me to decipher what went wrong? |
|
Strange, looks like it crashed / timed out in the middle. |
|
Run Python SDK PostCommit |
|
Run Python Dataflow ValidatesRunner |
|
I am even more confused. |
|
This looks fine, and the ValidatesRunner tests pass, so I'm going to merge even though Jenkins seems to buggy right now for the PostSubmit run. |
|
Thanks all! |
Signed-off-by: cclauss cclauss@bluewin.ch
Please add a meaningful description for your change here
Define cmp() function that was removed in Python 3. A more straight ahead approach to #4774 that should be easier to review. Fixes the following issues:
flake8 testing of https://github.com/apache/beam on Python 3.6.3
$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
Follow this checklist to help us incorporate your contribution quickly and easily:
[BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replaceBEAM-XXXwith the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.It will help us expedite review of your Pull Request if you tag someone (e.g.
@username) to look at it.Post-Commit Tests Status (on master branch)