Skip to content
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

Closed
wants to merge 17 commits into from
Closed

Enable flake8 #3224

wants to merge 17 commits into from

Conversation

hmaarrfk
Copy link
Member

@hmaarrfk hmaarrfk commented Jun 27, 2018

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

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

@pep8speaks

This comment has been minimized.

@codecov-io
Copy link

codecov-io commented Jun 27, 2018

Codecov Report

Merging #3224 into master will decrease coverage by 0.99%.
The diff coverage is 66.66%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
skimage/viewer/plugins/overlayplugin.py 91.07% <ø> (ø) ⬆️
skimage/draw/draw.py 98.94% <ø> (ø) ⬆️
skimage/morphology/grey.py 94.33% <ø> (ø) ⬆️
skimage/filters/_frangi.py 97.05% <ø> (ø) ⬆️
skimage/setup.py 8.1% <0%> (ø)
skimage/_shared/utils.py 86.66% <100%> (ø) ⬆️
skimage/viewer/qt.py 88.57% <100%> (ø) ⬆️
skimage/_shared/version_requirements.py 83.05% <100%> (ø) ⬆️
skimage/segmentation/random_walker_segmentation.py 92.01% <100%> (-1.88%) ⬇️
skimage/viewer/plugins/lineprofile.py 96.42% <100%> (ø) ⬆️
... and 48 more

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 133aa70...b15243e. Read the comment docs.

@hmaarrfk
Copy link
Member Author

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RUN_FLAKE8 or smth?

Copy link
Member Author

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

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?

Copy link
Member Author

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

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.

Copy link
Member Author

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.

CPU_COUNT = multiprocessing.cpu_count()
except:
CPU_COUNT = 2
import multiprocessing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already in. #3434

Copy link
Member Author

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.

@soupault soupault added the 🔧 type: Maintenance Refactoring and maintenance of internals label Oct 2, 2018
@hmaarrfk hmaarrfk force-pushed the flake8 branch 3 times, most recently from e2b3d73 to d0c9522 Compare October 2, 2018 18:48
@hmaarrfk
Copy link
Member Author

hmaarrfk commented Oct 2, 2018

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

Copy link
Member

@soupault soupault left a 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?

@hmaarrfk
Copy link
Member Author

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.

@soupault
Copy link
Member

@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.
You're right, flake8 is PR-agnostic in this case, and may lead to a chain of red builds.

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 =
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? How?

Copy link
Contributor

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_*,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why excluding tests?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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 *
Copy link
Contributor

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?

Copy link
Member Author

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):
Copy link
Contributor

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

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

Copy link
Member

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?

Copy link
Member Author

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 ;)

@stefanv
Copy link
Member

stefanv commented Dec 6, 2019

Love this; thanks @hmaarrfk! Needs a quick rebase, hopefully not too honerous (err, may well be).

Reminds me about the conversations around black, @jni. I'd be okay with the way it's used in Napari, e.g.

blank lines
non multiple of 4 tabbing
trailing white space
@jni
Copy link
Member

jni commented Dec 6, 2019

Yeah, pre-commit hooks are the right way to implement these things. Unfortunately, though, it makes it harder to get started developing for skimage...

@hmaarrfk
Copy link
Member Author

hmaarrfk commented Dec 7, 2019

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

@stefanv
Copy link
Member

stefanv commented Dec 7, 2019

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. make lint-install (or, perhaps, python .tools/install-lint.py.

doc/release/contribs.py Outdated Show resolved Hide resolved
@grlee77
Copy link
Contributor

grlee77 commented Oct 29, 2020

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.

Base automatically changed from master to main February 18, 2021 18:23
@grlee77 grlee77 added the 🤖 type: Infrastructure CI, packaging, tools and automation label Apr 5, 2021
@stefanv
Copy link
Member

stefanv commented Feb 6, 2023

Implemented using ruff in #6729

@stefanv stefanv closed this Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 type: Infrastructure CI, packaging, tools and automation 🔧 type: Maintenance Refactoring and maintenance of internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants