15
15
# $ ./ci/code_checks.sh code # checks on imported code
16
16
# $ ./ci/code_checks.sh doctests # run doctests
17
17
# $ ./ci/code_checks.sh docstrings # validate docstring errors
18
- # $ ./ci/code_checks.sh dependencies # check that dependencies are consistent
19
18
# $ ./ci/code_checks.sh typing # run static type analysis
20
19
21
- [[ -z " $1 " || " $1 " == " lint" || " $1 " == " patterns" || " $1 " == " code" || " $1 " == " doctests" || " $1 " == " docstrings" || " $1 " == " dependencies " || " $1 " == " typing" ]] || \
22
- { echo " Unknown command $1 . Usage: $0 [lint|patterns|code|doctests|docstrings|dependencies| typing]" ; exit 9999; }
20
+ [[ -z " $1 " || " $1 " == " lint" || " $1 " == " patterns" || " $1 " == " code" || " $1 " == " doctests" || " $1 " == " docstrings" || " $1 " == " typing" ]] || \
21
+ { echo " Unknown command $1 . Usage: $0 [lint|patterns|code|doctests|docstrings|typing]" ; exit 9999; }
23
22
24
23
BASE_DIR=" $( dirname $0 ) /.."
25
24
RET=0
@@ -38,6 +37,12 @@ function invgrep {
38
37
return $(( ! $EXIT_STATUS ))
39
38
}
40
39
40
+ function check_namespace {
41
+ local -r CLASS=" ${1} "
42
+ grep -R -l --include " *.py" " ${CLASS} (" pandas/tests | xargs grep -n " pd\.${CLASS} ("
43
+ test $? -gt 0
44
+ }
45
+
41
46
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
42
47
FLAKE8_FORMAT=" ##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
43
48
INVGREP_PREPEND=" ##[error]"
48
53
# ## LINTING ###
49
54
if [[ -z " $CHECK " || " $CHECK " == " lint" ]]; then
50
55
51
- echo " black --version"
52
- black --version
53
-
54
- MSG=' Checking black formatting' ; echo $MSG
55
- black . --check
56
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
57
-
58
- # `setup.cfg` contains the list of error codes that are being ignored in flake8
59
-
60
- echo " flake8 --version"
61
- flake8 --version
62
-
63
- # pandas/_libs/src is C code, so no need to search there.
64
- MSG=' Linting .py code' ; echo $MSG
65
- flake8 --format=" $FLAKE8_FORMAT " .
66
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
67
-
68
- MSG=' Linting .pyx and .pxd code' ; echo $MSG
69
- flake8 --format=" $FLAKE8_FORMAT " pandas --append-config=flake8/cython.cfg
70
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
71
-
72
- MSG=' Linting .pxi.in' ; echo $MSG
73
- flake8 --format=" $FLAKE8_FORMAT " pandas/_libs --append-config=flake8/cython-template.cfg
74
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
75
-
76
- echo " flake8-rst --version"
77
- flake8-rst --version
78
-
79
- MSG=' Linting code-blocks in .rst documentation' ; echo $MSG
80
- flake8-rst doc/source --filename=* .rst --format=" $FLAKE8_FORMAT "
81
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
82
-
83
56
# Check that cython casting is of the form `<type>obj` as opposed to `<type> obj`;
84
57
# it doesn't make a difference, but we want to be internally consistent.
85
58
# Note: this grep pattern is (intended to be) equivalent to the python
@@ -132,19 +105,6 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
132
105
fi
133
106
RET=$(( $RET + $? )) ; echo $MSG " DONE"
134
107
135
- echo " isort --version-number"
136
- isort --version-number
137
-
138
- # Imports - Check formatting using isort see setup.cfg for settings
139
- MSG=' Check import format using isort' ; echo $MSG
140
- ISORT_CMD=" isort --quiet --check-only pandas asv_bench scripts web"
141
- if [[ " $GITHUB_ACTIONS " == " true" ]]; then
142
- eval $ISORT_CMD | awk ' {print "##[error]" $0}' ; RET=$(( $RET + ${PIPESTATUS[0]} ))
143
- else
144
- eval $ISORT_CMD
145
- fi
146
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
147
-
148
108
fi
149
109
150
110
# ## PATTERNS ###
@@ -187,14 +147,6 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
187
147
invgrep -r -E --include ' *.py' " [[:space:]] pytest.raises" pandas/tests/
188
148
RET=$(( $RET + $? )) ; echo $MSG " DONE"
189
149
190
- MSG=' Check for python2-style file encodings' ; echo $MSG
191
- invgrep -R --include=" *.py" --include=" *.pyx" -E " # -\*- coding: utf-8 -\*-" pandas scripts
192
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
193
-
194
- MSG=' Check for python2-style super usage' ; echo $MSG
195
- invgrep -R --include=" *.py" -E " super\(\w*, (self|cls)\)" pandas
196
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
197
-
198
150
MSG=' Check for use of builtin filter function' ; echo $MSG
199
151
invgrep -R --include=" *.py" -P ' (?<!def)[\(\s]filter\(' pandas
200
152
RET=$(( $RET + $? )) ; echo $MSG " DONE"
@@ -213,35 +165,15 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
213
165
invgrep -R --include=" *.py" --include=" *.pyx" -E " (DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)" pandas
214
166
RET=$(( $RET + $? )) ; echo $MSG " DONE"
215
167
216
- MSG=' Check for python2 new-style classes and for empty parentheses' ; echo $MSG
217
- invgrep -R --include=" *.py" --include=" *.pyx" -E " class\s\S*\((object)?\):" pandas asv_bench/benchmarks scripts
218
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
219
-
220
168
MSG=' Check for backticks incorrectly rendering because of missing spaces' ; echo $MSG
221
169
invgrep -R --include=" *.rst" -E " [a-zA-Z0-9]\`\` ?[a-zA-Z0-9]" doc/source/
222
170
RET=$(( $RET + $? )) ; echo $MSG " DONE"
223
171
224
- MSG=' Check for incorrect sphinx directives' ; echo $MSG
225
- invgrep -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
226
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
227
-
228
172
# Check for the following code in testing: `unittest.mock`, `mock.Mock()` or `mock.patch`
229
173
MSG=' Check that unittest.mock is not used (pytest builtin monkeypatch fixture should be used instead)' ; echo $MSG
230
174
invgrep -r -E --include ' *.py' ' (unittest(\.| import )mock|mock\.Mock\(\)|mock\.patch)' pandas/tests/
231
175
RET=$(( $RET + $? )) ; echo $MSG " DONE"
232
176
233
- MSG=' Check for wrong space after code-block directive and before colon (".. code-block ::" instead of ".. code-block::")' ; echo $MSG
234
- invgrep -R --include=" *.rst" " .. code-block ::" doc/source
235
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
236
-
237
- MSG=' Check for wrong space after ipython directive and before colon (".. ipython ::" instead of ".. ipython::")' ; echo $MSG
238
- invgrep -R --include=" *.rst" " .. ipython ::" doc/source
239
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
240
-
241
- MSG=' Check for extra blank lines after the class definition' ; echo $MSG
242
- invgrep -R --include=" *.py" --include=" *.pyx" -E ' class.*:\n\n( )+"""' .
243
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
244
-
245
177
MSG=' Check for use of {foo!r} instead of {repr(foo)}' ; echo $MSG
246
178
invgrep -R --include=* .{py,pyx} ' !r}' pandas
247
179
RET=$(( $RET + $? )) ; echo $MSG " DONE"
@@ -266,15 +198,16 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
266
198
invgrep -R --include=* .{py,pyx} ' \.__class__' pandas
267
199
RET=$(( $RET + $? )) ; echo $MSG " DONE"
268
200
269
- MSG=' Check for use of xrange instead of range ' ; echo $MSG
270
- invgrep -R --include=* .{py,pyx} ' xrange ' pandas
201
+ MSG=' Check code for instances of os.remove ' ; echo $MSG
202
+ invgrep -R --include=" *.py* " --exclude " common.py " --exclude " test_writers.py " --exclude " test_store.py " -E " os\.remove " pandas/tests/
271
203
RET=$(( $RET + $? )) ; echo $MSG " DONE"
272
204
273
- MSG=' Check that no file in the repo contains trailing whitespaces' ; echo $MSG
274
- INVGREP_APPEND=" <- trailing whitespaces found"
275
- invgrep -RI --exclude=\* .{svg,c,cpp,html,js} --exclude-dir=env " \s$" *
276
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
277
- unset INVGREP_APPEND
205
+ MSG=' Check for inconsistent use of pandas namespace in tests' ; echo $MSG
206
+ check_namespace " Series"
207
+ RET=$(( $RET + $? ))
208
+ check_namespace " DataFrame"
209
+ RET=$(( $RET + $? ))
210
+ echo $MSG " DONE"
278
211
fi
279
212
280
213
# ## CODE ###
@@ -395,15 +328,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
395
328
396
329
fi
397
330
398
- # ## DEPENDENCIES ###
399
- if [[ -z " $CHECK " || " $CHECK " == " dependencies" ]]; then
400
-
401
- MSG=' Check that requirements-dev.txt has been generated from environment.yml' ; echo $MSG
402
- $BASE_DIR /scripts/generate_pip_deps_from_conda.py --compare --azure
403
- RET=$(( $RET + $? )) ; echo $MSG " DONE"
404
-
405
- fi
406
-
407
331
# ## TYPING ###
408
332
if [[ -z " $CHECK " || " $CHECK " == " typing" ]]; then
409
333
@@ -415,5 +339,4 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then
415
339
RET=$(( $RET + $? )) ; echo $MSG " DONE"
416
340
fi
417
341
418
-
419
342
exit $RET
0 commit comments