Skip to content

Commit 96894b9

Browse files
d4l3kfacebook-github-bot
authored andcommitted
enable flake8 lint (pytorch#14)
Summary: This enables flake8 linting with a similar config to pytorch https://github.com/pytorch/pytorch/blob/master/.flake8 Pull Request resolved: pytorch#14 Reviewed By: tierex Differential Revision: D28686729 Pulled By: d4l3k fbshipit-source-id: 3f6ab1034554490e3bc039437404389218989fcd
1 parent 5707d33 commit 96894b9

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

.flake8

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[flake8]
2+
select = B,C,E,F,P,T4,W,B9
3+
max-line-length = 120
4+
# C408 ignored because we like the dict keyword argument syntax
5+
# E501 is not flexible enough, we're using B950 instead
6+
ignore =
7+
E203,E305,E402,E501,E721,E741,F405,F821,F841,F999,W503,W504,C408,E302,W291,E303,
8+
# shebang has extra meaning in fbcode lints, so I think it's not worth trying
9+
# to line this up with executable bit
10+
EXE001,
11+
# these ignores are from flake8-bugbear; please fix!
12+
B007,B008,
13+
# these ignores are from flake8-comprehensions; please fix!
14+
C400,C401,C402,C403,C404,C405,C407,C411,C413,C414,C415
15+
optional-ascii-coding = True
16+
exclude =
17+
./.git,
18+
./docs
19+
./build
20+
./scripts,
21+
./venv,
22+
*.pyi

.github/workflows/lint.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
set -eux
2323
pip install isort==4.3.21
2424
pip install black
25+
pip install flake8==3.9.0
2526
- name: Run Lint
2627
run: |
2728
git config --global url."https://${{ secrets.GITHUB_TOKEN }}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

dev-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ pytorch-lightning>=0.5.3
88
torch>=1.8.1
99
torchvision>=0.9.1
1010
classy-vision>=0.5.0
11+
flake8==3.9.0

scripts/lint.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ then
1717
echo "Please install isort."
1818
exit 1
1919
fi
20+
if [ ! "$(flake8 --version)" ]
21+
then
22+
echo "Please install flake8."
23+
exit 1
24+
fi
2025

2126
# cd to the project directory
2227
cd "$(dirname "$0")/.." || exit 1
@@ -51,8 +56,9 @@ then
5156
do
5257
echo "Checking $file"
5358
isort "$file" --recursive --multi-line 3 --trailing-comma --force-grid-wrap 0 \
54-
--line-width 88 --lines-after-imports 2 --combine-as --section-default THIRDPARTY
55-
black "$file"
59+
--line-width 88 --lines-after-imports 2 --combine-as --section-default THIRDPARTY -q
60+
black "$file" -q
61+
flake8 "$file" || LINT_ERRORS=1
5662
done
5763
else
5864
echo "No changes made to any Python files. Nothing to do."
@@ -62,7 +68,7 @@ fi
6268
# Check if any files were modified by running isort + black
6369
# If so, then the files were formatted incorrectly (e.g. did not pass lint)
6470
CHANGED_FILES="$(git diff --name-only | grep '\.py$' | tr '\n' ' ')"
65-
if [ "$CHANGED_FILES" != "" ]
71+
if [ "$CHANGED_FILES" != "" ] || [ "$LINT_ERRORS" != "" ]
6672
then
6773
# need this so that CircleCI fails
6874
exit 1

0 commit comments

Comments
 (0)