5
5
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
6
7
7
"""
8
- Check for specified flake8 and mypy warnings in python files.
8
+ Check for specified mypy warnings in python files.
9
9
"""
10
10
11
11
import os
12
12
from pathlib import Path
13
13
import subprocess
14
- import sys
15
14
16
15
from importlib .metadata import metadata , PackageNotFoundError
17
16
18
17
# Customize mypy cache dir via environment variable
19
18
cache_dir = Path (__file__ ).parent .parent / ".mypy_cache"
20
19
os .environ ["MYPY_CACHE_DIR" ] = str (cache_dir )
21
20
22
- DEPS = ['flake8' , 'lief' , 'mypy' , 'pyzmq' ]
23
-
24
- # All .py files, except those in src/ (to exclude subtrees there)
25
- FLAKE_FILES_ARGS = ['git' , 'ls-files' , '*.py' , ':!:src/*.py' ]
21
+ DEPS = ['lief' , 'mypy' , 'pyzmq' ]
26
22
27
23
# Only .py files in test/functional and contrib/devtools have type annotations
28
24
# enforced.
29
25
MYPY_FILES_ARGS = ['git' , 'ls-files' , 'test/functional/*.py' , 'contrib/devtools/*.py' ]
30
26
31
- ENABLED = (
32
- 'E101,' # indentation contains mixed spaces and tabs
33
- 'E401,' # multiple imports on one line
34
- 'E402,' # module level import not at top of file
35
- 'E701,' # multiple statements on one line (colon)
36
- 'E702,' # multiple statements on one line (semicolon)
37
- 'E703,' # statement ends with a semicolon
38
- 'E711,' # comparison to None should be 'if cond is None:'
39
- 'E714,' # test for object identity should be "is not"
40
- 'E721,' # do not compare types, use "isinstance()"
41
- 'E722,' # do not use bare 'except'
42
- 'E742,' # do not define classes named "l", "O", or "I"
43
- 'E743,' # do not define functions named "l", "O", or "I"
44
- 'F401,' # module imported but unused
45
- 'F402,' # import module from line N shadowed by loop variable
46
- 'F403,' # 'from foo_module import *' used; unable to detect undefined names
47
- 'F404,' # future import(s) name after other statements
48
- 'F405,' # foo_function may be undefined, or defined from star imports: bar_module
49
- 'F406,' # "from module import *" only allowed at module level
50
- 'F407,' # an undefined __future__ feature name was imported
51
- 'F601,' # dictionary key name repeated with different values
52
- 'F602,' # dictionary key variable name repeated with different values
53
- 'F621,' # too many expressions in an assignment with star-unpacking
54
- 'F631,' # assertion test is a tuple, which are always True
55
- 'F632,' # use ==/!= to compare str, bytes, and int literals
56
- 'F811,' # redefinition of unused name from line N
57
- 'F821,' # undefined name 'Foo'
58
- 'F822,' # undefined name name in __all__
59
- 'F823,' # local variable name … referenced before assignment
60
- 'F841,' # local variable 'foo' is assigned to but never used
61
- 'W191,' # indentation contains tabs
62
- 'W291,' # trailing whitespace
63
- 'W292,' # no newline at end of file
64
- 'W293,' # blank line contains whitespace
65
- 'W605,' # invalid escape sequence "x"
66
- )
67
-
68
27
69
28
def check_dependencies ():
70
29
for dep in DEPS :
@@ -78,20 +37,6 @@ def check_dependencies():
78
37
def main ():
79
38
check_dependencies ()
80
39
81
- if len (sys .argv ) > 1 :
82
- flake8_files = sys .argv [1 :]
83
- else :
84
- flake8_files = subprocess .check_output (FLAKE_FILES_ARGS ).decode ("utf-8" ).splitlines ()
85
-
86
- flake8_args = ['flake8' , '--ignore=B,C,E,F,I,N,W' , f'--select={ ENABLED } ' ] + flake8_files
87
- flake8_env = os .environ .copy ()
88
- flake8_env ["PYTHONWARNINGS" ] = "ignore"
89
-
90
- try :
91
- subprocess .check_call (flake8_args , env = flake8_env )
92
- except subprocess .CalledProcessError :
93
- exit (1 )
94
-
95
40
mypy_files = subprocess .check_output (MYPY_FILES_ARGS ).decode ("utf-8" ).splitlines ()
96
41
mypy_args = ['mypy' , '--show-error-codes' ] + mypy_files
97
42
0 commit comments