-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[RFC] [ci] Enforce flake8 on Python code #5566
Comments
I agree with this, as you pointed out it's been several times where we miss unused imports in reviews that would've been caught by it. Unused variables is also a good catch because sometimes they're just typos and are easy to miss in reviews if they manage to get past the tests. |
This issue has been automatically locked since there has not been any recent activity since it was closed. |
Created based on this conversation with @jmoralez : #5559 (review).
Proposal
LightGBM should use
flake8
in CI.Motivation
flake8
is a static analyzer for Python that I've found very useful in catching efficiency and correctness issues like:And many more! ([full list of error codes])
flake8
by default has 4 types of checks:pycodestyle
)pyflakes
)mccabe
)It also has a rich ecosystem of optional plugins (see e.g. https://github.com/DmytroLitvinov/awesome-flake8-extensions).
LightGBM already enforces
pycodestyle
LightGBM/.ci/test.sh
Line 80 in 0c0eb2a
So integrating this wouldn't change any of LightGBM's expectations for code style.
We've also had several instances over the last few years where
flake8
was use to catch issues. Enforcing it in CI could have prevented those issues from being introduced at all:flake8
can also be adopted gradually, via:#noqa
commments--ignore
command-line flagDescription
If this is accepted, the work would look like:
flake8
warnings onmaster
pycodestyle
withflake8
in thelint
CI taskflake8
configuration for--ignore
and--exclude
in a file, instead of in CI scripts, for easier local development (docs for reference)References
As of 0c0eb2a and the latest version of
flake8
(v4.0.1), the followingflake8 \ --ignore=E501,W503 \ --exclude=./.nuget,./external_libs,./python-package/build/,./python-package/compile \ .
Returns the following.
Request for Comment
@jmoralez @StrikerRUS will you please comment on this proposal when you have time?
I think LightGBM would benefit from adopting more static analyzers, and that
flake8
is a powerful and easy one to add next.The text was updated successfully, but these errors were encountered: