-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
[AIRFLOW-5373] Super fast pre-commit check for basic python2 compatib… #5979
[AIRFLOW-5373] Super fast pre-commit check for basic python2 compatib… #5979
Conversation
Running |
6067491
to
8bcd287
Compare
I also figured that we can simply do py_compile on all files. It works great too. |
I think both together works beautifully and can save us many hours https://travis-ci.org/apache/airflow/jobs/579595829 - if you configure them as pre-commit checks especially all those problems will not even leave your local sources (I have both pre-commit and pre-push configured and it works great as long as we merge #5972 |
We can even add python3 py_compile in master as well - I think it's rather nice way of catching basic syntax errors. |
8bcd287
to
b6df089
Compare
@@ -198,7 +198,7 @@ def compare_result(ds, **kwargs): | |||
|
|||
/** Computes an approximation to pi */ | |||
object SparkPi { | |||
def main(args: Array[String]) { | |||
def main(args) { |
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 is a false positive -- this is Scala code :D
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.
Aaaaah indeed. So I need to add a a possibility to exclude such false positives. Will do soon.
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.
Looks like https://pre-commit.com/#regular-expressions to exclude the whole file is the only way to do this one. A bit overly broad but this file isn't changed very often so that's probably okay. That or adjust the regex to not allow ) {
on the line (trickier regex to get that working)
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.
Actually I thought about writing a bit more complex regex to exclude lines which have the standard # noqa
in the same line - so that you can explicitly disable it if needed.
Here is the regex that will likely work :)
^(?!.*# noqa)(.*\.super\(\)|^\s*def\s*\S*\([^):]*:.*|^\sdef\s*\S*\(.*\):\s*\-\>\s*\S*).*$
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.
And likely with (?x) I can write in multiple lines to make it easier to read :)
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.
But I also remember about "you have one problem - introduce regexp - then you will have two problems" saying, so maybe it's even worth to write our own simple hook for that purpose if you think it's too "nerdy" with the regexp.
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.
I used to work as a Perl developer for about 5 years, so I am in favour of regeps :D You can take the programmer out of perl, but not the perl out of the programmer.
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.
If each pygrep test is quick, might it be easier to split the super case from the type annotation case into separate rules?
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.
Actually if you are a perl programmer - then you will find the final result well.. refreshing :).
I found that with (?x) extension you can not only write elegant and pretty "modular" code but also one that can contain comments (!).
Also the exclusion rules can be rather elegant :).
Surprisingly I have now regexp that I am actually proud of!
b6df089
to
b748328
Compare
Hold on. Just checking super() matching :) |
b748328
to
c11c4f8
Compare
Now it's perfect. It detects 846 Python3-specific lines in master and 0 in v1-10-test :) |
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
…ility
Make sure you have checked all steps below.
Jira
Description
Tests
Commits
Documentation
Code Quality
flake8