Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 8 commits into from
Nov 14, 2017

Conversation

siftikha
Copy link
Contributor

@siftikha siftikha commented Nov 6, 2017

Pulled ignore flags from build_tools/travis/flake8_diff.sh into setup.cfg.

Left --diff and --show-source flags in build_tools/travis/flake8_diff.sh since it seemed unwise to separate them from the actual call to flake8. If they should be merged into setup.cfg as well I can do that.

fixes #10067

@jnothman
Copy link
Member

jnothman commented Nov 6, 2017 via email

# 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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@lesteve lesteve Nov 8, 2017

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 ...

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 😞

Copy link
Contributor Author

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
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@jnothman
Copy link
Member

jnothman commented Nov 8, 2017 via email

@siftikha
Copy link
Contributor Author

siftikha commented Nov 8, 2017

So after looking into the --diff options a bit more (thank you @lesteve ) what I've done here isn't going to work, nor is it likely to be a decent base for moving forward. So I'm going to close this pull request to avoid wasting more time on it.

@siftikha siftikha closed this Nov 8, 2017
@jnothman
Copy link
Member

jnothman commented Nov 8, 2017

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!

@siftikha
Copy link
Contributor Author

siftikha commented Nov 9, 2017

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.

@siftikha siftikha reopened this Nov 9, 2017
@lesteve
Copy link
Member

lesteve commented Nov 9, 2017

My personal preferences:

  • E226 (whitespace around operator) should be ignored. z = x*x + y*y reads a lot better than its counterpart with additional spaces (same thing for x = 1/3 if you ask me)
  • we should only have a flake8 section in setup.cfg if we do something different from the flake8 defaults. Given the previous bullet point, I don't think we should have a flake8 section in setup.cfg.
  • it's fine having a .flake8 config file in examples and using this config explicitly with --config in flake8_diff.sh.

@siftikha
Copy link
Contributor Author

siftikha commented Nov 9, 2017

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.

@jnothman
Copy link
Member

jnothman commented Nov 9, 2017 via email

@agramfort
Copy link
Member

indeed I have been "formated" to respect E226 and I think that most of the code base respects it.

@lesteve
Copy link
Member

lesteve commented Nov 10, 2017

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.
Yes:

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.

@rth
Copy link
Member

rth commented Nov 10, 2017

indeed I have been "formated" to respect E226 and I think that most of the code base respects it.

There are only 74 occurrences of this linting error,

flake8 --ignore E121,E123,E126,E24,E704,W503,W504 sklearn | grep E226

which yields flake8_E226.txt. So most of the current code base does currently respect it.

Not ignoring E226 would partially revert #9123 btw.

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.

+1

The same argument is used by pycodestyle (and flake8) to define default errors:

In the default configuration, the checks E121, E123, E126, E133, E226, E241, E242, E704 and W503 are ignored because they are not rules unanimously accepted, and PEP 8 does not enforce them.

@agramfort
Copy link
Member

agramfort commented Nov 10, 2017 via email

@codecov
Copy link

codecov bot commented Nov 14, 2017

Codecov Report

Merging #10080 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
sklearn/cluster/_feature_agglomeration.py 100% <0%> (ø) ⬆️
...klearn/cluster/tests/test_feature_agglomeration.py 100% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abb43c1...db4b40a. Read the comment docs.

@siftikha siftikha changed the title move flake8 options from shell script to setup.cfg fixes #10067 [MRG] move flake8 options from shell script to setup.cfg fixes #10067 Nov 14, 2017
@siftikha siftikha changed the title [MRG] move flake8 options from shell script to setup.cfg fixes #10067 move flake8 options from shell script to setup.cfg fixes #10067 Nov 14, 2017
@siftikha siftikha changed the title move flake8 options from shell script to setup.cfg fixes #10067 [MRG] move flake8 options from shell script to setup.cfg fixes #10067 Nov 14, 2017
@lesteve
Copy link
Member

lesteve commented Nov 14, 2017

@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.

@lesteve
Copy link
Member

lesteve commented Nov 14, 2017

No need to wait for AppVeyor so merging this one. Thanks a lot @dilutedsauce!

@lesteve lesteve merged commit 62eda82 into scikit-learn:master Nov 14, 2017
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
…arn#10080)

Also add examples/.flake8 for examples specific flake8 configuration
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
…arn#10080)

Also add examples/.flake8 for examples specific flake8 configuration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move flake8 options to setup.cfg
5 participants