Skip to content

Commit 1811954

Browse files
Refactoring lint.sh, wrong path pandas/src corrected, and made more compact and readable
1 parent d115900 commit 1811954

File tree

1 file changed

+93
-187
lines changed

1 file changed

+93
-187
lines changed

ci/lint.sh

Lines changed: 93 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -1,196 +1,102 @@
11
#!/bin/bash
22

33
echo "inside $0"
4+
[[ $LINT ]] || { echo "NOT Linting"; exit 0; }
45

56
source activate pandas
6-
77
RET=0
88

9-
if [ "$LINT" ]; then
10-
11-
# We're ignoring the following codes across the board
12-
#E402, # module level import not at top of file
13-
#E731, # do not assign a lambda expression, use a def
14-
#E741, # do not use variables named 'l', 'O', or 'I'
15-
#W503, # line break before binary operator
16-
#C406, # Unnecessary (list/tuple) literal - rewrite as a dict literal.
17-
#C408, # Unnecessary (dict/list/tuple) call - rewrite as a literal.
18-
#C409, # Unnecessary (list/tuple) passed to tuple() - (remove the outer call to tuple()/rewrite as a tuple literal).
19-
#C410 # Unnecessary (list/tuple) passed to list() - (remove the outer call to list()/rewrite as a list literal).
20-
21-
# pandas/_libs/src is C code, so no need to search there.
22-
echo "Linting *.py"
23-
flake8 pandas --filename=*.py --exclude pandas/_libs/src --ignore=C406,C408,C409,E402,E731,E741,W503
24-
if [ $? -ne "0" ]; then
25-
RET=1
26-
fi
27-
28-
flake8 scripts/tests --filename=*.py
29-
if [ $? -ne "0" ]; then
30-
RET=1
31-
fi
32-
echo "Linting *.py DONE"
33-
34-
echo "Linting setup.py"
35-
flake8 setup.py --ignore=E402,E731,E741,W503
36-
if [ $? -ne "0" ]; then
37-
RET=1
38-
fi
39-
echo "Linting setup.py DONE"
40-
41-
echo "Linting asv_bench/benchmarks/"
42-
flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/*.py --ignore=F811,C406,C408,C409,C410
43-
if [ $? -ne "0" ]; then
44-
RET=1
45-
fi
46-
echo "Linting asv_bench/benchmarks/*.py DONE"
47-
48-
echo "Linting scripts/*.py"
49-
flake8 scripts --filename=*.py --ignore=C408,E402,E731,E741,W503
50-
if [ $? -ne "0" ]; then
51-
RET=1
52-
fi
53-
echo "Linting scripts/*.py DONE"
54-
55-
echo "Linting doc scripts"
56-
flake8 doc/make.py doc/source/conf.py --ignore=E402,E731,E741,W503
57-
if [ $? -ne "0" ]; then
58-
RET=1
59-
fi
60-
echo "Linting doc scripts DONE"
61-
62-
echo "Linting *.pyx"
63-
flake8 pandas --filename=*.pyx --select=E501,E302,E203,E111,E114,E221,E303,E128,E231,E126,E265,E305,E301,E127,E261,E271,E129,W291,E222,E241,E123,F403,C400,C401,C402,C403,C404,C405,C406,C407,C408,C409,C410,C411
64-
if [ $? -ne "0" ]; then
65-
RET=1
66-
fi
67-
echo "Linting *.pyx DONE"
68-
69-
echo "Linting *.pxi.in"
70-
for path in 'src'
71-
do
72-
echo "linting -> pandas/$path"
73-
flake8 pandas/$path --filename=*.pxi.in --select=E501,E302,E203,E111,E114,E221,E303,E231,E126,F403
74-
if [ $? -ne "0" ]; then
75-
RET=1
76-
fi
77-
done
78-
echo "Linting *.pxi.in DONE"
79-
80-
echo "Linting *.pxd"
81-
for path in '_libs'
82-
do
83-
echo "linting -> pandas/$path"
84-
flake8 pandas/$path --filename=*.pxd --select=E501,E302,E203,E111,E114,E221,E303,E231,E126,F403
85-
if [ $? -ne "0" ]; then
86-
RET=1
87-
fi
88-
done
89-
echo "Linting *.pxd DONE"
90-
91-
# readability/casting: Warnings about C casting instead of C++ casting
92-
# runtime/int: Warnings about using C number types instead of C++ ones
93-
# build/include_subdir: Warnings about prefacing included header files with directory
94-
95-
# We don't lint all C files because we don't want to lint any that are built
96-
# from Cython files nor do we want to lint C files that we didn't modify for
97-
# this particular codebase (e.g. src/headers, src/klib, src/msgpack). However,
98-
# we can lint all header files since they aren't "generated" like C files are.
99-
echo "Linting *.c and *.h"
100-
for path in '*.h' 'parser' 'ujson'
101-
do
102-
echo "linting -> pandas/_libs/src/$path"
103-
cpplint --quiet --extensions=c,h --headers=h --filter=-readability/casting,-runtime/int,-build/include_subdir --recursive pandas/_libs/src/$path
104-
if [ $? -ne "0" ]; then
105-
RET=1
106-
fi
107-
done
108-
echo "linting -> pandas/_libs/tslibs/src/datetime"
109-
cpplint --quiet --extensions=c,h --headers=h --filter=-readability/casting,-runtime/int,-build/include_subdir --recursive pandas/_libs/tslibs/src/datetime
110-
if [ $? -ne "0" ]; then
111-
RET=1
112-
fi
113-
echo "Linting *.c and *.h DONE"
114-
115-
echo "Check for invalid testing"
116-
117-
# Check for the following code in testing:
118-
#
119-
# np.testing
120-
# np.array_equal
121-
grep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/
122-
123-
if [ $? = "0" ]; then
124-
RET=1
125-
fi
126-
127-
# Check for pytest.warns
128-
grep -r -E --include '*.py' 'pytest\.warns' pandas/tests/
129-
130-
if [ $? = "0" ]; then
131-
RET=1
132-
fi
133-
134-
# Check for the following code in the extension array base tests
135-
# tm.assert_frame_equal
136-
# tm.assert_series_equal
137-
grep -r -E --include '*.py' --exclude base.py 'tm.assert_(series|frame)_equal' pandas/tests/extension/base
138-
139-
if [ $? = "0" ]; then
140-
RET=1
141-
fi
142-
143-
echo "Check for invalid testing DONE"
144-
145-
# Check for imports from pandas.core.common instead
146-
# of `import pandas.core.common as com`
147-
echo "Check for non-standard imports"
148-
grep -R --include="*.py*" -E "from pandas.core.common import " pandas
149-
if [ $? = "0" ]; then
150-
RET=1
151-
fi
152-
echo "Check for non-standard imports DONE"
153-
154-
echo "Check for incorrect sphinx directives"
155-
SPHINX_DIRECTIVES=$(echo \
156-
"autosummary|contents|currentmodule|deprecated|function|image|"\
157-
"important|include|ipython|literalinclude|math|module|note|raw|"\
158-
"seealso|toctree|versionadded|versionchanged|warning" | tr -d "[:space:]")
159-
for path in './pandas' './doc/source'
160-
do
161-
grep -R --include="*.py" --include="*.pyx" --include="*.rst" -E "\.\. ($SPHINX_DIRECTIVES):[^:]" $path
162-
if [ $? = "0" ]; then
163-
RET=1
164-
fi
165-
done
166-
echo "Check for incorrect sphinx directives DONE"
167-
168-
echo "Check for deprecated messages without sphinx directive"
169-
grep -R --include="*.py" --include="*.pyx" -E "(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)" pandas
170-
171-
if [ $? = "0" ]; then
172-
RET=1
173-
fi
174-
echo "Check for deprecated messages without sphinx directive DONE"
175-
176-
echo "Check for old-style classes"
177-
grep -R --include="*.py" -E "class\s\S*[^)]:" pandas scripts
178-
179-
if [ $? = "0" ]; then
180-
RET=1
181-
fi
182-
echo "Check for old-style classes DONE"
183-
184-
echo "Check for backticks incorrectly rendering because of missing spaces"
185-
grep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/
186-
187-
if [ $? = "0" ]; then
188-
RET=1
189-
fi
190-
echo "Check for backticks incorrectly rendering because of missing spaces DONE"
191-
192-
else
193-
echo "NOT Linting"
194-
fi
9+
10+
### LINTING ###
11+
12+
# We're ignoring the following codes across the board
13+
# E402 module level import not at top of file
14+
# E731 do not assign a lambda expression, use a def
15+
# E741 do not use variables named 'l', 'O', or 'I'
16+
# W503 line break before binary operator
17+
# C406 Unnecessary (list/tuple) literal - rewrite as a dict literal.
18+
# C408 Unnecessary (dict/list/tuple) call - rewrite as a literal.
19+
# C409 Unnecessary (list/tuple) passed to tuple() - (remove the outer call to tuple()/rewrite as a tuple literal).
20+
# C410 Unnecessary (list/tuple) passed to list() - (remove the outer call to list()/rewrite as a list literal).
21+
22+
# pandas/_libs/src is C code, so no need to search there.
23+
MSG='Linting .py code' ; echo $MSG
24+
flake8 pandas --filename=*.py --exclude pandas/_libs/src --ignore=C406,C408,C409,E402,E731,E741,W503
25+
RET=$(($RET + $?)) ; echo $MSG "DONE"
26+
27+
MSG='Linting .pyx code' ; echo $MSG
28+
flake8 pandas --filename=*.pyx --select=E501,E302,E203,E111,E114,E221,E303,E128,E231,E126,E265,E305,E301,E127,E261,E271,E129,W291,E222,E241,E123,F403,C400,C401,C402,C403,C404,C405,C406,C407,C408,C409,C410,C411
29+
RET=$(($RET + $?)) ; echo $MSG "DONE"
30+
31+
MSG='Linting .pxd and .pxi.in' ; echo $MSG
32+
flake8 pandas/_libs --filename=*.pxi.in,*.pxd --select=E501,E302,E203,E111,E114,E221,E303,E231,E126,F403
33+
RET=$(($RET + $?)) ; echo $MSG "DONE"
34+
35+
MSG='Linting setup.py' ; echo $MSG
36+
flake8 setup.py --ignore=E402,E731,E741,W503
37+
RET=$(($RET + $?)) ; echo $MSG "DONE"
38+
39+
MSG='Linting scripts' ; echo $MSG
40+
flake8 scripts --filename=*.py --ignore=C408,E402,E731,E741,W503
41+
RET=$(($RET + $?)) ; echo $MSG "DONE"
42+
43+
MSG='Linting asv benchmarks' ; echo $MSG
44+
flake8 asv_bench/benchmarks/ --exclude=asv_bench/benchmarks/*.py --ignore=F811,C406,C408,C409,C410
45+
RET=$(($RET + $?)) ; echo $MSG "DONE"
46+
47+
MSG='Linting doc scripts' ; echo $MSG
48+
flake8 doc/make.py doc/source/conf.py --ignore=E402,E731,E741,W503
49+
RET=$(($RET + $?)) ; echo $MSG "DONE"
50+
51+
# readability/casting: Warnings about C casting instead of C++ casting
52+
# runtime/int: Warnings about using C number types instead of C++ ones
53+
# build/include_subdir: Warnings about prefacing included header files with directory
54+
55+
# We don't lint all C files because we don't want to lint any that are built
56+
# from Cython files nor do we want to lint C files that we didn't modify for
57+
# this particular codebase (e.g. src/headers, src/klib, src/msgpack). However,
58+
# we can lint all header files since they aren't "generated" like C files are.
59+
MSG='Linting .c and .h' ; echo $MSG
60+
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/ujson pandas/_libs/tslibs/src/datetime
61+
RET=$(($RET + $?)) ; echo $MSG "DONE"
62+
63+
64+
### CHECKS ###
65+
66+
# Check for imports from pandas.core.common instead of `import pandas.core.common as com`
67+
MSG='Check for non-standard imports' ; echo $MSG
68+
! grep -R --include="*.py*" -E "from pandas.core.common import " pandas
69+
RET=$(($RET + $?)) ; echo $MSG "DONE"
70+
71+
MSG='Check for pytest warns' ; echo $MSG
72+
! grep -r -E --include '*.py' 'pytest\.warns' pandas/tests/
73+
RET=$(($RET + $?)) ; echo $MSG "DONE"
74+
75+
# Check for the following code in testing: `np.testing` and `np.array_equal`
76+
MSG='Check for invalid testing' ; echo $MSG
77+
! grep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/
78+
RET=$(($RET + $?)) ; echo $MSG "DONE"
79+
80+
# Check for the following code in the extension array base tests: `tm.assert_frame_equal` and `tm.assert_series_equal`
81+
MSG='Check for invalid EA testing' ; echo $MSG
82+
! grep -r -E --include '*.py' --exclude base.py 'tm.assert_(series|frame)_equal' pandas/tests/extension/base
83+
RET=$(($RET + $?)) ; echo $MSG "DONE"
84+
85+
MSG='Check for deprecated messages without sphinx directive' ; echo $MSG
86+
! grep -R --include="*.py" --include="*.pyx" -E "(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)" pandas
87+
RET=$(($RET + $?)) ; echo $MSG "DONE"
88+
89+
MSG='Check for old-style classes' ; echo $MSG
90+
! grep -R --include="*.py" -E "class\s\S*[^)]:" pandas scripts
91+
RET=$(($RET + $?)) ; echo $MSG "DONE"
92+
93+
MSG='Check for backticks incorrectly rendering because of missing spaces' ; echo $MSG
94+
! grep -R --include="*.rst" -E "[a-zA-Z0-9]\`\`?[a-zA-Z0-9]" doc/source/
95+
RET=$(($RET + $?)) ; echo $MSG "DONE"
96+
97+
MSG='Check for incorrect sphinx directives' ; echo $MSG
98+
! grep -R --include="*.py" --include="*.pyx" --include="*.rst" -E "\.\. (autosummary|contents|currentmodule|deprecated|function|image|important|include|ipython|literalinclude|math|module|note|raw|seealso|toctree|versionadded|versionchanged|warning):[^:]" ./pandas ./doc/source
99+
RET=$(($RET + $?)) ; echo $MSG "DONE"
100+
195101

196102
exit $RET

0 commit comments

Comments
 (0)