File: lint.sh

package info (click to toggle)
pandas 0.23.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 167,704 kB
  • sloc: python: 230,826; ansic: 11,317; sh: 682; makefile: 133
file content (181 lines) | stat: -rwxr-xr-x 5,602 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash

echo "inside $0"

source activate pandas

RET=0

if [ "$LINT" ]; then

    # pandas/_libs/src is C code, so no need to search there.
    echo "Linting *.py"
    flake8 pandas --filename=*.py --exclude pandas/_libs/src
    if [ $? -ne "0" ]; then
        RET=1
    fi
    echo "Linting *.py DONE"

    echo "Linting setup.py"
    flake8 setup.py
    if [ $? -ne "0" ]; then
        RET=1
    fi
    echo "Linting setup.py DONE"

    echo "Linting asv_bench/benchmarks/"
    flake8 asv_bench/benchmarks/  --exclude=asv_bench/benchmarks/*.py --ignore=F811
    if [ $? -ne "0" ]; then
        RET=1
    fi
    echo "Linting asv_bench/benchmarks/*.py DONE"

    echo "Linting scripts/*.py"
    flake8 scripts --filename=*.py
    if [ $? -ne "0" ]; then
        RET=1
    fi
    echo "Linting scripts/*.py DONE"

    echo "Linting doc scripts"
    flake8 doc/make.py doc/source/conf.py
    if [ $? -ne "0" ]; then
        RET=1
    fi
    echo "Linting doc scripts DONE"

    echo "Linting *.pyx"
    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
    if [ $? -ne "0" ]; then
        RET=1
    fi
    echo "Linting *.pyx DONE"

    echo "Linting *.pxi.in"
    for path in 'src'
    do
        echo "linting -> pandas/$path"
        flake8 pandas/$path --filename=*.pxi.in --select=E501,E302,E203,E111,E114,E221,E303,E231,E126,F403
        if [ $? -ne "0" ]; then
            RET=1
        fi
    done
    echo "Linting *.pxi.in DONE"

    echo "Linting *.pxd"
    for path in '_libs'
    do
        echo "linting -> pandas/$path"
        flake8 pandas/$path --filename=*.pxd --select=E501,E302,E203,E111,E114,E221,E303,E231,E126,F403
        if [ $? -ne "0" ]; then
            RET=1
        fi
    done
    echo "Linting *.pxd DONE"

    # readability/casting: Warnings about C casting instead of C++ casting
    # runtime/int: Warnings about using C number types instead of C++ ones
    # build/include_subdir: Warnings about prefacing included header files with directory

    # We don't lint all C files because we don't want to lint any that are built
    # from Cython files nor do we want to lint C files that we didn't modify for
    # this particular codebase (e.g. src/headers, src/klib, src/msgpack). However,
    # we can lint all header files since they aren't "generated" like C files are.
    echo "Linting *.c and *.h"
    for path in '*.h' 'period_helper.c' 'datetime' 'parser' 'ujson'
    do
        echo "linting -> pandas/_libs/src/$path"
        cpplint --quiet --extensions=c,h --headers=h --filter=-readability/casting,-runtime/int,-build/include_subdir --recursive pandas/_libs/src/$path
        if [ $? -ne "0" ]; then
            RET=1
        fi
    done
    echo "Linting *.c and *.h DONE"

    echo "Check for invalid testing"

    # Check for the following code in testing:
    #
    # np.testing
    # np.array_equal
    grep -r -E --include '*.py' --exclude testing.py '(numpy|np)(\.testing|\.array_equal)' pandas/tests/

    if [ $? = "0" ]; then
        RET=1
    fi

    # Check for pytest.warns
    grep -r -E --include '*.py' 'pytest\.warns' pandas/tests/

    if [ $? = "0" ]; then
        RET=1
    fi

    # Check for the following code in the extension array base tests
    # tm.assert_frame_equal
    # tm.assert_series_equal
    grep -r -E --include '*.py' --exclude base.py 'tm.assert_(series|frame)_equal' pandas/tests/extension/base

    if [ $? = "0" ]; then
        RET=1
    fi

    echo "Check for invalid testing DONE"

    # Check for imports from pandas.core.common instead
    # of `import pandas.core.common as com`
    echo "Check for non-standard imports"
    grep -R --include="*.py*" -E "from pandas.core.common import " pandas
    if [ $? = "0" ]; then
        RET=1
    fi
    echo "Check for non-standard imports DONE"

    echo "Check for use of lists instead of generators in built-in Python functions"

    # Example: Avoid `any([i for i in some_iterator])` in favor of `any(i for i in some_iterator)`
    #
    # Check the following functions:
    # any(), all(), sum(), max(), min(), list(), dict(), set(), frozenset(), tuple(), str.join()
    grep -R --include="*.py*" -E "[^_](any|all|sum|max|min|list|dict|set|frozenset|tuple|join)\(\[.* for .* in .*\]\)" pandas

    if [ $? = "0" ]; then
        RET=1
    fi
    echo "Check for use of lists instead of generators in built-in Python functions DONE"

    echo "Check for incorrect sphinx directives"
    SPHINX_DIRECTIVES=$(echo \
       "autosummary|contents|currentmodule|deprecated|function|image|"\
       "important|include|ipython|literalinclude|math|module|note|raw|"\
       "seealso|toctree|versionadded|versionchanged|warning" | tr -d "[:space:]")
    for path in './pandas' './doc/source'
    do
        grep -R --include="*.py" --include="*.pyx" --include="*.rst" -E "\.\. ($SPHINX_DIRECTIVES):[^:]" $path
        if [ $? = "0" ]; then
            RET=1
        fi
    done
    echo "Check for incorrect sphinx directives DONE"

    echo "Check for deprecated messages without sphinx directive"
    grep -R --include="*.py" --include="*.pyx" -E "(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)" pandas

    if [ $? = "0" ]; then
        RET=1
    fi
    echo "Check for deprecated messages without sphinx directive DONE"

    echo "Check for old-style classes"
    grep -R --include="*.py" -E "class\s\S*[^)]:" pandas scripts

    if [ $? = "0" ]; then
        RET=1
    fi
    echo "Check for old-style classes DONE"
    
else
    echo "NOT Linting"
fi

exit $RET