-
-
Notifications
You must be signed in to change notification settings - Fork 25.5k
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
[MRG+3] Add flake8 linting of the diff in Travis #7127
Conversation
# reported by Travis will match with the local code. | ||
BRANCH_NAME=travis_pr_$TRAVIS_PULL_REQUEST | ||
git fetch $REMOTE pull/$TRAVIS_PULL_REQUEST/head:$BRANCH_NAME | ||
git checkout $BRANCH_NAME |
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 assume there are no concurrency issues with modifying the working copy in the current directory? The rest of this script only modifies .git
. And I don't actually see why a working copy is needed.
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 my mind these lines were supposed of doing the same as what Travis does by default, but with the branch as it is on the PR author's machine instead of at is is after the merge into master. This way the line numbers on Travis and on the PR author machine match.
I assume there are no concurrency issues with modifying the working copy in the current directory? The rest of this script only modifies .git. And I don't actually see why a working copy is needed.
Note this only happens on Travis (not if you run the command locally) so I am not sure about which concurrency issue you are talking about. It may be true that we may not need a working copy but again this happens only on Travis so is it such a big problem ?
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.
It's not a big problem. I suppose Travis can't reuse working copies for the various tests, so I'm thinking nonsense.
I think this is a good idea. Pity flake8 doesn't cover Cython. |
|
||
# Conservative approach: diff without context so that code that was | ||
# not changed does not create failures | ||
git diff --unified=0 $COMMIT | flake8 --diff --show-source |
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 assume this takes care to only do things to .py
files. I also assume it does not handle rst
, pyx
, pxd
.
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 assume this takes care to only do things to .py files. I also assume it does not handle rst, pyx, pxd.
Only .py files are taken into account indeed.
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'm not sure I understand what's happening here. flake8 is only run on the added lines, right? So how can it detect undefined names? Or does it parse the diff and use the whole file as context?
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.
From some tests I ran a long time ago it only uses the diff, I agree that the non PEP8 stuff (e.g. unused variable) is mostly limited to new file (or at least when a significant amount of code is added).
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.
Hm I'm not sure if that is how flake8 --diff is meant to be used? I think you just have to remove the =0
and it does the right thing.
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.
ok never mind. my test show that your line does the right thing, though I have no idea how it works.
LGTM |
@@ -53,11 +53,11 @@ if [[ "$DISTRIB" == "conda" ]]; then | |||
if [[ "$INSTALL_MKL" == "true" ]]; then | |||
conda create -n testenv --yes python=$PYTHON_VERSION pip nose \ | |||
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION numpy scipy \ | |||
cython=$CYTHON_VERSION libgfortran mkl | |||
cython=$CYTHON_VERSION libgfortran mkl flake8 |
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.
not sure if it's worth moving this to the if below because we only need it in the one test? Actually the two kinds of tests have pretty different requirements, right? The flake8 test doesn't even need numpy and scipy I guess? But maybe that doesn't matter so much and we should keep it simple.
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.
Yeah you only need the source code, I went for the smallest change but I agree it could be simplified.
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 think the concern here is that if flake8, now or in the future, has other dependencies, then we are installing dependencies that may give us false green CI icons in the future. Seems unlikely, but I don't think it's a great hassle to set this up separately.
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 fixed this: now flake8 is only installed when needed (i.e. "$RUN_FLAKE8" == "true").
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 see that in the code. Can you please point it out?
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.
@jnothman I didn't understand you comment. My concern was more that we are burning travis time by installing numpy, scipy and cython, thought it was a minor concern.
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 was saying that when we're actually running tests, installing deps that aren't on our deps list may confound test results.
can we get a make target to run that locally (and add it to the developer docs)? |
@@ -0,0 +1,72 @@ | |||
#!/bin/bash |
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.
the file should start with the explanation of what's happening as you gave in this PR, I think.
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.
Will do.
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.
Done.
Why don't we use https://flake8-diff.readthedocs.io/en/latest/ instead? Hm I guess it looks a bit abandoned. But it seems like something that should be factored out into it's own project.... (it sounds like you just copied a non-trivial bash script among 3 projects with no shared tracking). |
I did not bump into this when I looked for a solution for this problem I have to admit. Will look into it a bit more.
Yep my brain is the only place the shared tracking is happening at the moment ;-). |
LGTM but I think a standalone solution at some point would be nice ;) |
521cad2
to
396f604
Compare
# ancestor | ||
# | ||
# Additional features: | ||
# - the line numbers in Travis matches the local branch on the PR |
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.
matches -> match
LGTM |
with respect to common ancestor of branch and scikit-learn/scikit-learn remote. Add a flake8-diff target in the Makefile and mention it in the doc.
396f604
to
867df05
Compare
@amueller any more comments on this PR? |
Thanks @NelleV for bumping this PR for me :) |
And yes, thank you, @NelleV, this will be great to have. |
so that the flake8 build stands out more on the Travis website.
LGTM |
Now it's time to watch all those PRs get crosses next to them... muhuhahaha |
Thanks a lot @lesteve |
* Add flake8 linting on the diff with respect to common ancestor of branch and scikit-learn/scikit-learn remote. Add a flake8-diff target in the Makefile and mention it in the doc. * Only install flake8 when needed
python setup.py develop | ||
fi | ||
|
||
if [[ "$RUN_FLAKE8" == "true" ]]; then |
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.
Hi @lesteve
I am working on a similar PR for matplotlib, and I was wondering why you used strings and not booleans here?
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 know nothing about bash booleans in case they do exist. Is there any clear advantage of using them? Also I guess INSTALL_MKL was used like this so I just copied it.
* Add flake8 linting on the diff with respect to common ancestor of branch and scikit-learn/scikit-learn remote. Add a flake8-diff target in the Makefile and mention it in the doc. * Only install flake8 when needed
What does this implement/fix? Explain your changes.
This allows to check that PRs do not add obvious flake8 violations. The main things behind it are:
flake8 --diff
on the diff between the branch and the common ancestorThis approach has been used in joblib and nilearn for a little while and works fine.
Additional features:
An example output for a PR adding flake 8 violations:
https://travis-ci.org/joblib/joblib/jobs/149138375
Creating a PR was motivated by https://travis-ci.org/joblib/joblib/jobs/149138375. As I said in this issue:
ping @agramfort @GaelVaroquaux