-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG] move flake8 options from shell script to setup.cfg fixes #10067 #10080
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
We now need to check that flake8_diff.sh runs flake8 in a context where
setup.cfg is read.
Yes, not moving --diff and --show-source is the right thing to do.
… |
build_tools/travis/flake8_diff.sh
Outdated
# Examples are allowed to not have imports at top of file | ||
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" \ | ||
--ignore $DEFAULT_IGNORED_PEP8 --ignore E402 | ||
check_files "$(echo "$MODIFIED_FILES" | grep ^examples)" --ignore 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.
We had a problem a while ago that --ignore
replaces rather than adds on top of the default, this is why we have DEFAULT_IGNORED_PEP8 env variable. You can probably use git blame and look at the commit message or PR for more details. Can you please check the behaviour?
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 I realized this would be the issue as I was going to bed last night. I will see if there is a way to avoid that issue.
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.
We had a problem a while ago that --ignore replaces rather than adds on top of the default, this is why we have DEFAULT_IGNORED_PEP8 env variable. You can probably use git blame and look at the commit message or PR for more details. Can you please check the behaviour?
So I checked and this matches my expectation: --ignore
flag overrides whatever is in setup.cfg, so you need to duplicate what is in setup.cfg if you want to add an additional warning to ignore. All in all I am not sure what to do with this issue/PR ...
If we had at least one non-default flake8 warning that we wanted to ignore, it would be worth to have a flake8 section in setup.cfg but it is not even the case ...
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.
After looking into it a bit more, I think it would make the most sense to move a flake8 config file into the examples directory with the --ignore flags for that directory and just use the default --ignore flags for the rest of the project.
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.
Can you actually have a per-folder flake8 config file? I would not think so from just looking at the flake8 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.
afaik when flake8 checks a file like /example_proj/examples/example.py
it will check for config info in /example_proj/examples
then in /example_proj
with the info further up in the directory structure taking priority. so if you don't have a config file in /example_proj
and you have one in /example_proj/examples
the file in /example_proj/examples
will take precedence.
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 definitely not aware of this, nice! The problem is that the per-folder config file does not seem to be taken into account by flake8 --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.
Ah the --diff thing is true. Hmm. This seems like it is probably not going to work.
setup.cfg
Outdated
@@ -38,6 +38,9 @@ artifact_indexes= | |||
# https://ci.appveyor.com/project/sklearn-ci/scikit-learn/ | |||
http://windows-wheels.scikit-learn.org/ | |||
|
|||
[flake8] | |||
ignore=E121,E123,E126,E24,E704,W503,W504 |
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.
Are they actually needed in the sense that they should correspond to the default ignore flake8 settings if I believe the comment in master?
# Default ignore PEP8 violations are from flake8 3.3.0
DEFAULT_IGNORED_PEP8=E121,E123,E126,E226,E24,E704,W503,W504
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 issue that lead me to do this pr, I think these are truly project wide settings in that they are not something that the maintainers feel are worth worrying about.
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.
@lesteve the default ignored list can change from version to version so its better to be explicit. Additionally, the current default for the most recent version ignores e226 which is something worth enforcing according to the issue this pr was in response to.
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 am not 100% convinced, I would rather trust that flake8 default is a good default. As an example: it could well be that flake8 add a completely new kind of violations that they don't want to be shown by default. Setting ignore
explicitly is not the best thing to do in this case.
The reason for putting the ignores explicitly in setup.cfg is that
different versions of flake8 have had different defaults. Putting them in
there means user experience will match the version of flake8 we have in CI.
|
So after looking into the |
Hey, this doesn't mean the issue is irrelevant. The point of the issue is that users contributing to scikit-learn should have the same config as our CI. So we might need to duplicate these settings in build_tools and in setup.cfg, but we still want them in setup.cfg! |
I had intended to do a different pr with a .flake8 config in both the base directory and in /examples but I guess I might as well just include that in this one. |
My personal preferences:
|
I agree about e226, but that's something you and @jnothman should talk about since the original issue he opened mentioned wanting to enforce that. I disagree about not including a .cfg file for flake8 though, even if it is just the defaults. The defaults can change from version to version and without a config file in the folder if a user has a system wide flake8 file, the config could accidentally be overriden. It seems better to be explicit here. |
@agramfort was quite pro-E226
|
indeed I have been "formated" to respect E226 and I think that most of the code base respects it. |
I assume everybody is aware that PEP8 recommend against E226. From https://www.python.org/dev/peps/pep-0008/#other-recommendations: If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies). Use your own judgment; however, never use more than one space, and always have the same amount of whitespace on both sides of a binary operator. i = i + 1
submitted += 1
x = x*2 - 1
hypot2 = x*x + y*y
c = (a+b) * (a-b) No: i=i+1
submitted +=1
x = x * 2 - 1
hypot2 = x * x + y * y
c = (a + b) * (a - b) All in all, I think we should have flake8 warnings only for things that are uncontroversial. E226 is controversial, so we should keep ignoring it. |
There are only 74 occurrences of this linting error,
which yields flake8_E226.txt. So most of the current code base does currently respect it. Not ignoring E226 would partially revert #9123 btw.
+1 The same argument is used by pycodestyle (and flake8) to define default errors:
|
I won't fight for it. +0 for E226. I will just keep using it myself :)
|
Codecov Report
@@ Coverage Diff @@
## master #10080 +/- ##
==========================================
+ Coverage 96.19% 96.19% +<.01%
==========================================
Files 336 337 +1
Lines 62739 62772 +33
==========================================
+ Hits 60353 60386 +33
Misses 2386 2386
Continue to review full report at Codecov.
|
@dilutedsauce I pushed some minor tweaks. With these I am fine to merge. I'll wait for the CIs and merge this one, given that there seem to be consensus, e.g. by @agramfort and @rth. |
No need to wait for AppVeyor so merging this one. Thanks a lot @dilutedsauce! |
…arn#10080) Also add examples/.flake8 for examples specific flake8 configuration
…arn#10080) Also add examples/.flake8 for examples specific flake8 configuration
Pulled ignore flags from
build_tools/travis/flake8_diff.sh
intosetup.cfg
.Left
--diff
and--show-source
flags inbuild_tools/travis/flake8_diff.sh
since it seemed unwise to separate them from the actual call toflake8
. If they should be merged intosetup.cfg
as well I can do that.fixes #10067