-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Enable flake8 #3224
Enable flake8 #3224
Conversation
This comment has been minimized.
This comment has been minimized.
e0f42e1
to
1d78e82
Compare
Codecov Report
@@ Coverage Diff @@
## master #3224 +/- ##
========================================
- Coverage 87.82% 86.82% -1%
========================================
Files 325 340 +15
Lines 27317 27486 +169
========================================
- Hits 23992 23866 -126
- Misses 3325 3620 +295
Continue to review full report at Codecov.
|
4b0a6c4
to
101c0e7
Compare
@scikit-image/core I don't know if you care about flake8, but I find it gives much better error message than running code through python when you have a syntax error. The commit message are now much improved compared to the first version I submitted a few months ago. |
.travis.yml
Outdated
@@ -38,7 +38,7 @@ matrix: | |||
include: | |||
- os: linux | |||
python: 3.5 | |||
env: OPTIONAL_DEPS=1 WITH_PYSIDE=1 BUILD_DOCS=1 | |||
env: OPTIONAL_DEPS=1 WITH_PYSIDE=1 BUILD_DOCS=1 TEST_FLAKE8=1 |
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.
RUN_FLAKE8
or smth?
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.
.travis.yml
Outdated
# catching it. | ||
# Therefore, it is best to run flake8 first, on a single build | ||
# with the oldest version of python we support | ||
- if [[ $TEST_FLAKE8 == "1" ]]; 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.
Should all of this be in a dedicated tools\flake8.py
?
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. flake8.sh
.travis.yml
Outdated
# with the oldest version of python we support | ||
- if [[ $TEST_FLAKE8 == "1" ]]; then | ||
pip install flake8; | ||
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.
You probably need to keep the same flake8 arguments as before.
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 it is all in the setup.cfg
. I added a dummy commit to trip up flake8 to test it.
skimage/io/_plugins/util.py
Outdated
CPU_COUNT = multiprocessing.cpu_count() | ||
except: | ||
CPU_COUNT = 2 | ||
import multiprocessing |
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.
Already in. #3434
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, that was cherry picked from here. Rebasing got rid of it.
e2b3d73
to
d0c9522
Compare
@soupault see this build https://travis-ci.org/scikit-image/scikit-image/jobs/436291887#L905 showing we don't need to setup any flake8 command line arguments. |
7cb9161
to
3b8fe83
Compare
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 good to me! Mark, could you rebase?
Yeah. Let me think about this again. Flake8 is a little bit of an annoyance when it causes something to fail for no reason. This is especially true when they change their mind about the style guide and whatnot. The worst part about this script, is that if somebody else introduces a flake8 error, all future contributors would see red. My goal is to have contributors get to green as easily as possible. The goal of these tests should be to guide contributors through the mundane stuff (style, and test infrastructure), while helping them with the technical parts. |
@hmaarrfk well, a build failing with a redundant whitespace is not what I would like to see either. But having flake8 executed during the early phase of CI routine is pretty useful. What is we adjust pep8speaks bot to perform only the most significant checks (as, currently, specified in the PR), and remove flake8 completely (or, at least, disable its influence on the build status)? Other changes in the PR are very welcome. |
@@ -1,2 +1,47 @@ | |||
[metadata] | |||
license_file = LICENSE.txt | |||
|
|||
[flake8] | |||
ignore = |
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 can use full names instead of shortcuts
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.
??? How?
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.
my bad, it seems that it works only for pylint
W391 | ||
|
||
exclude = | ||
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.
why excluding tests?
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.
Tests often include many data arrays, that are well justified not to follow pep8.
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.
@hmaarrfk this is true, but test functions themselves should follow PEP8. I'd prefer finer-grained control here. Maybe it's not doable but I prefer to ignore these warnings rather than silence them completely.
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 really believe that warnings should be set to 0, except when they would add more noise (like in examples).
The idea is that currently the flake8 stuff is just fully being ignore.
from .manage_plugins import * | ||
from .manage_plugins import (use_plugin, call_plugin, plugin_info, | ||
plugin_order, reset_plugins, | ||
find_available_plugins, available_plugins) | ||
from .sift import * |
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.
why here is not the names list too?
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 could. I think i gave up on changing style, I mostly like flake8 to find python typos, and not imposing style.
@@ -134,10 +134,11 @@ def search_line(lines, refline, start=0): | |||
|
|||
|
|||
|
|||
def getLutNames(prefix): | |||
def getLutNames(prefix, luts): |
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 the review scope, it is not clear but luts
does not seems to be used
@@ -30,7 +30,7 @@ def new_del(self): | |||
pass | |||
umfpack.UmfpackContext.__del__ = new_del | |||
UmfpackContext = umfpack.UmfpackContext() | |||
except: | |||
except: # noqa |
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.
an exception should be specified et leas by Exception
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 agree, and here we can probably do even better. @JDWarner might have some thoughts?
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.
These kind of maintenance changes really require 3 devs working according to our policies. Will not work with such large sweeping changes without focused effort ;)
blank lines non multiple of 4 tabbing trailing white space
getLutNames is still untested or uncalled in the whole codebase though
Yeah, pre-commit hooks are the right way to implement these things. Unfortunately, though, it makes it harder to get started developing for skimage... |
THe flake8 changes I had to actually enact are things like tabulation, and trailing whitespace, I see these as "minor" and better to deal with near the end of the PR, instead of upfront with a pre-commit hook |
Agreed, for now. My suggestion was for the long term, where I think we would benefit from enforced compliance that simultaneously relieves the burden on the contributor. I don't think it's much of a problem to help new users with this. For other projects, I have a single command they can run to install the commit hook, e.g. |
This now needs a rebase, but I would be fine with merging once the CI is green. We can always refine things again later as needed. |
Implemented using ruff in #6729 |
Flake8 was enabled, but we were ignoring the output so it might as well have been removed.
That said, it is useful to check unused variables, and undefined variables.
I disabled most of the style options that don't make sense when you write mathematical code,
added a few
# noqa
to keep the useful warnings for future code.Things are mostly split by logical modifications in a few different commits
I setup flake8 such that it would be much less strict than before and only run on a single build
For reviewers
(Don't remove the checklist below.)
later.
__init__.py
.doc/release/release_dev.rst
.@meeseeksdev backport to v0.14.x