Skip to content

Commit

Permalink
MAINT simplify linting by running flake8 on the whole project (scikit…
Browse files Browse the repository at this point in the history
  • Loading branch information
lesteve authored Jul 6, 2022
1 parent 652a627 commit ac52fe1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 190 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,3 @@ doc-noplot: inplace
code-analysis:
flake8 sklearn | grep -v __init__ | grep -v external
pylint -E -i y sklearn/ -d E1103,E0611,E1101

flake8-diff:
git diff upstream/main -u -- "*.py" | flake8 --diff
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
black --check --diff .
displayName: Run black
- bash: |
./build_tools/circle/linting.sh
./build_tools/azure/linting.sh
displayName: Run linting
- bash: |
mypy sklearn/
Expand Down
43 changes: 43 additions & 0 deletions build_tools/azure/linting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e
# pipefail is necessary to propagate exit codes
set -o pipefail

flake8 --show-source .
echo -e "No problem detected by flake8\n"

# For docstrings and warnings of deprecated attributes to be rendered
# properly, the property decorator must come before the deprecated decorator
# (else they are treated as functions)

# do not error when grep -B1 "@property" finds nothing
set +e
bad_deprecation_property_order=`git grep -A 10 "@property" -- "*.py" | awk '/@property/,/def /' | grep -B1 "@deprecated"`

if [ ! -z "$bad_deprecation_property_order" ]
then
echo "property decorator should come before deprecated decorator"
echo "found the following occurrencies:"
echo $bad_deprecation_property_order
exit 1
fi

# Check for default doctest directives ELLIPSIS and NORMALIZE_WHITESPACE

doctest_directive="$(git grep -nw -E "# doctest\: \+(ELLIPSIS|NORMALIZE_WHITESPACE)")"

if [ ! -z "$doctest_directive" ]
then
echo "ELLIPSIS and NORMALIZE_WHITESPACE doctest directives are enabled by default, but were found in:"
echo "$doctest_directive"
exit 1
fi

joblib_import="$(git grep -l -A 10 -E "joblib import.+delayed" -- "*.py" ":!sklearn/utils/_joblib.py" ":!sklearn/utils/fixes.py")"

if [ ! -z "$joblib_import" ]; then
echo "Use from sklearn.utils.fixes import delayed instead of joblib delayed. The following files contains imports to joblib.delayed:"
echo "$joblib_import"
exit 1
fi
179 changes: 0 additions & 179 deletions build_tools/circle/linting.sh

This file was deleted.

8 changes: 2 additions & 6 deletions doc/developers/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,11 @@ complies with the following rules before marking a PR as ``[MRG]``. The
`editor integration documentation <https://black.readthedocs.io/en/stable/integrations/editors.html>`_
to configure your editor to run `black`.

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

.. prompt:: bash $

git diff upstream/main -u -- "*.py" | flake8 --diff
or `make flake8-diff` which should work on Unix-like systems.
flake8 .

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

Expand Down
1 change: 0 additions & 1 deletion sklearn/decomposition/tests/test_nmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def test_parameter_checking():
# automatically tested in the common tests.

A = np.ones((2, 2))
name = "spam"

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

0 comments on commit ac52fe1

Please sign in to comment.