8000 MAINT simplify linting by running flake8 on the whole project (#23846) · scikit-learn/scikit-learn@ac52fe1 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac52fe1

Browse files
authored
MAINT simplify linting by running flake8 on the whole project (#23846)
1 parent 652a627 commit ac52fe1

File tree

6 files changed

+46
-190
lines changed

6 files changed

+46
-190
lines changed

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,3 @@ doc-noplot: inplace
6363
code-analysis:
6464
flake8 sklearn | grep -v __init__ | grep -v external
6565
pylint -E -i y sklearn/ -d E1103,E0611,E1101
66-
67-
flake8-diff:
68-
git diff upstream/main -u -- "*.py" | flake8 --diff

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
black --check --diff .
4141
displayName: Run black
4242
- bash: |
43-
./build_tools/circle/linting.sh
43+
./build_tools/azure/linting.sh
4444
displayName: Run linting
4545
- bash: |
4646
mypy sklearn/

build_tools/azure/linting.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
set -e
4+
# pipefail is necessary to propagate exit codes
5+
set -o pipefail
6+
7+
flake8 --show-source .
8+
echo -e "No problem detected by flake8\n"
9+
10+
# For docstrings and warnings of deprecated attributes to be rendered
11+
# properly, the property decorator must come before the deprecated decorator
12+
# (else they are treated as functions)
13+
14+
# do not error when grep -B1 "@property" finds nothing
15+
set +e
16+
bad_deprecation_property_order=`git grep -A 10 "@property" -- "*.py" | awk '/@property/,/def /' | grep -B1 "@deprecated"`
17+
18+
if [ ! -z "$bad_deprecation_property_order" ]
19+
then
20+
echo "property decorator should come before deprecated decorator"
21+
echo "found the following occurrencies:"
22+
echo $bad_deprecation_property_order
23+
exit 1
24+
fi
25+
26+
# Check for default doctest directives ELLIPSIS and NORMALIZE_WHITESPACE
27+
28+
doctest_directive="$(git grep -nw -E "# doctest\: \+(ELLIPSIS|NORMALIZE_WHITESPACE)")"
29+
30+
if [ ! -z "$doctest_directive" ]
31+
then
32+
echo "ELLIPSIS and NORMALIZE_WHITESPACE doctest directives are enabled by default, but were found in:"
33+
echo "$doctest_directive"
34+
exit 1
35+
fi
36+
37+
joblib_import="$(git grep -l -A 10 -E "joblib import.+delayed" -- "*.py" ":!sklearn/utils/_joblib.py" ":!sklearn/utils/fixes.py")"
38+
39+
if [ ! -z "$joblib_import" ]; then
40+
echo "Use from sklearn.utils.fixes import delayed instead of joblib delayed. The following files contains imports to joblib.delayed:"
41+
echo "$joblib_import"
42+
exit 1
43+
fi

build_tools/circle/linting.sh

Lines changed: 0 additions & 179 deletions
This file was deleted.

doc/developers/contributing.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,11 @@ complies with the following rules before marking a PR as ``[MRG]``. The
435435
`editor integration documentation <https://black.readthedocs.io/en/stable/integrations/editors.html>`_
436436
to configure your editor to run `black`.
437437

438-
6. **Make sure that your PR does not add PEP8 violations**. To check the
439-
code that you changed, you can run the following command (see
440-
:ref:`above <upstream>` to set up the ``upstream`` remote):
438+
6. Run `flake8` to make sure you followed the project coding conventions.
441439

442440
.. prompt:: bash $
443441

444-
git diff upstream/main -u -- "*.py" | flake8 --diff
445-
446-
or `make flake8-diff` which should work on Unix-like systems.
442+
flake8 .
447443

448444
7. Follow the :ref:`coding-guidelines`.
449445

sklearn/decomposition/tests/test_nmf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def test_parameter_checking():
5454
# automatically tested in the common tests.
5555

5656
A = np.ones((2, 2))
57-
name = "spam"
5857

5958
msg = "Invalid beta_loss parameter: solver 'cd' does not handle beta_loss = 1.0"
6059
with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)
0