-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG + 1] CI some improvements to the flake8 CI #8036
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
- Examples now cannot fail due to 'E402 module level import not at top of file' Changed files are checked for unused imports regardless of diff
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.
In general, I find flake8 --diff somewhat deficient: it's not able to check for things like unused names. I think we therefore rely on it excessively.
I agree it has shortcomings but it is still a lot better than nothing.
echo "$files" | ||
echo $options | ||
git diff --unified=0 $COMMIT -- $files | flake8 --diff --show-source $options | ||
} | ||
|
||
if [[ "$MODIFIED_FILES" == "no_match" ]]; then | ||
echo "No file outside sklearn/externals and doc/sphinxext/sphinx_gallery has been modified" | ||
else | ||
# Conservative approach: diff without context so that code that |
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.
You want to move this comment before the git diff --unified=0 $COMMIT ...
line. Basically this was an explanation why we use --unified=0
in the git diff
command.
|
||
if [[ "$MODIFIED_FILES" == "no_match" ]]; then | ||
echo "No file outside sklearn/externals and doc/sphinxext/sphinx_gallery has been modified" | ||
else | ||
8000 | # Conservative approach: diff without context so that code that | |
# was not changed does not create failures | ||
git diff --unified=0 $COMMIT -- $MODIFIED_FILES | flake8 --diff --show-source | ||
check_files "$(echo "$MODIFIED_FILES" | grep -v ^examples)" | ||
# Examples are allowed to not have imports at top of file due to print(__doc__) |
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 would remove due to print(__doc__)
. This is not the main reason, this happens most of the time because examples are written in a "interactive mode" where you only import stuff when you need it rather than at the top of the file.
check_files() { | ||
files="$1" | ||
options="$2" | ||
echo "$files" |
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.
Do we want to keep this debugging echo statements?
check_files "$(echo "$MODIFIED_FILES" | grep -v ^examples)" | ||
# Examples are allowed to not have imports at top of file due to print(__doc__) | ||
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" --ignore=E402 | ||
check_files "$MODIFIED_FILES" |
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 don't get this last line ... You have already checked the non-examples files above and the example files ignoring E402.
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.
Sorry, I basically fell asleep while testing this and left in a few debug statements! thanks for your patience!
matplotlib has a simplified version of it which checks (if I understood correctly) the number of flake8 errors by file and make sure that they do not go up. They are not all super happy with this though and at one point a PR was opened to copy the functionality of flake8_diff.sh: matplotlib/matplotlib#7403. All in all I think this is a matter of 80/20 rule. |
How about we error on all violations within a changed file? That'll reduce testing complexity at the cost of annoying committers for a little while. Alternatively, we can can fix all pep8 violations (or mark them to be ignored by the linter if we don't like the fix) "once and for all" and then run flake8 on the changed files and not annoy future committers, but make everybody rebase their PRs once. |
It really shouldn't be that hard to do something that adjusts the line
numbers to see new errors that have been introduced. I just don't have the
capacity to focus on it right now...
…On 13 December 2016 at 04:28, Andreas Mueller ***@***.***> wrote:
How about we error on all violations within a changed file? That'll reduce
testing complexity at the cost of annoying committers for a little while.
Alternatively, we can can fix all pep8 violations (or mark them to be
ignored by the linter if we don't like the fix) "once and for all" and then
run flake8 on the changed files and not annoy future committers, but make
everybody rebase their PRs once.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8036 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6_IaJZLxQY8hq9NLB5Op1qvARqzSks5rHYQkgaJpZM4LJ6o7>
.
|
but it's trying to solve a problem that will go away soon anyhow, right? |
how so?
…On 13 December 2016 at 11:53, Andreas Mueller ***@***.***> wrote:
but it's trying to solve a problem that will go away soon anyhow, right?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8036 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz60lhtffkO6lQkT3d5Emj7fEmudXmks5rHexxgaJpZM4LJ6o7>
.
|
well if we solve all pep8 in the codebase then we don't need to worry about checking only the diff, right? |
Do we have plans to solve all PEP8 in the codebase??
…On 13 December 2016 at 12:15, Andreas Mueller ***@***.***> wrote:
well if we solve all pep8 in the codebase then we don't need to worry
about checking only the diff, right?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8036 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz65HCrH9AQDP8-_WsME5fteafEE6Gks5rHfGggaJpZM4LJ6o7>
.
|
Well if we only merge prs that don't introduce pep8 errors that will happen at some point, right? Unless we want to not enforce that and just use the continuous integration as a reminder. |
Only if the entire codebase is rewritten...?
…On 13 December 2016 at 12:28, Andreas Mueller ***@***.***> wrote:
Well if we only merge prs that don't introduce pep8 errors that will
happen at some point, right? Unless we want to not enforce that and just
use the continuous integration as a reminder.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#8036 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6986vpc4x9pXGFTJar4furw4YJqAks5rHfTHgaJpZM4LJ6o7>
.
|
I tested this locally and this works fine, so I am +1 for merging this. I don't have a strong opinion about pep8-fying the full code but I think that can be discussed in a separate issue. |
lgtm. Btw, can we please ignore W503? Do we have ignores setup somewhere? Or is our flake8 just old? |
Merging this one, thanks @jnothman! |
I'm never convinced when measures are based on number of commits. Surely this is highly influenced by the projects' policies about commit atomicity. I wonder how robust those half lives are to filtering commits to, say, a minimum number of lines changed. |
it's about how long it takes until a line changes, commits don't matter, I think. |
Examples now cannot fail due to 'E402 module level import not at top of file'
Examples now cannot fail due to 'E402 module level import not at top of file'
Examples now cannot fail due to 'E402 module level import not at top of file'
Examples now cannot fail due to 'E402 module level import not at top of file'
Examples now cannot fail due to 'E402 module level import not at top of file'
In general, I find
flake8 --diff
somewhat deficient: it's not able to check for things like unused names. I think we therefore rely on it excessively.Ideally we would:
If anyone wants to implement that, they're welcome!