9
9
from sys import exit
10
10
from textwrap import dedent
11
11
import subprocess
12
+ import sys
12
13
13
14
PROJECT_ROOT = path .dirname (path .dirname (path .realpath (__file__ )))
14
15
PYLINT_RCFILE = f"{ PROJECT_ROOT } /scripts/pylintrc"
18
19
19
20
def pylint_all_filenames (dev_mode , rootdirs ):
20
21
""" Performs pylint on all python files within given root directory (recursively). """
22
+
23
+ BARE_COMMAND = [
24
+ "pylint" ,
25
+ f"--rcfile={ PYLINT_RCFILE } " ,
26
+ ]
27
+
21
28
filenames = []
22
29
for rootdir in rootdirs :
23
30
for rootpath , _ , filenames_w in walk (rootdir ):
24
31
for filename in filenames_w :
25
32
if filename .endswith ('.py' ):
26
33
filenames .append (path .join (rootpath , filename ))
27
34
28
- checked_count = 0
29
- failed = []
30
- for filename in filenames :
31
- checked_count += 1
32
- command_line = [
33
- "pylint" ,
34
- f"--rcfile={ PYLINT_RCFILE } " ,
35
- f"{ filename } " ,
36
- ]
35
+ if not dev_mode :
36
+ # NOTE: We could just give pylint the directories and it would find the files on its
37
+ # own but it would treat them as packages, which would result in lots of import errors.
38
+ command_line = BARE_COMMAND + filenames
39
+ return subprocess .run (command_line , check = False ).returncode == 0
40
+
41
+ for i , filename in enumerate (filenames ):
42
+ command_line = BARE_COMMAND + [filename ]
37
43
print (
38
44
f"{ SGR_INFO } "
39
- f"[{ checked_count } /{ len (filenames )} ] "
45
+ f"[{ i + 1 } /{ len (filenames )} ] "
40
46
f"Running pylint on file: { filename } { SGR_CLEAR } "
41
47
)
42
48
43
- process = subprocess .run (command_line )
49
+ process = subprocess .run (command_line , check = False )
44
50
45
51
if process .returncode != 0 :
46
- if dev_mode :
47
- return 1 , checked_count
48
- failed .append (filename )
52
+ return False
49
53
50
- return len (failed ), len (filenames )
54
+ print ()
55
+ return True
51
56
52
57
53
58
def parse_command_line ():
@@ -64,7 +69,10 @@ def parse_command_line():
64
69
dest = 'dev_mode' ,
65
70
default = False ,
66
71
action = 'store_true' ,
67
- help = "Abort on first error."
72
+ help = (
73
+ "Abort on first error. "
74
+ "In this mode every script is passed to pylint separately. "
75
+ )
68
76
)
69
77
return parser .parse_args ()
70
78
@@ -77,12 +85,12 @@ def main():
77
85
f"{ PROJECT_ROOT } /scripts" ,
78
86
f"{ PROJECT_ROOT } /test" ,
79
87
]
80
- ( failed_count , total_count ) = pylint_all_filenames (options .dev_mode , rootdirs )
88
+ success = pylint_all_filenames (options .dev_mode , rootdirs )
81
89
82
- if failed_count != 0 :
83
- exit (f"pylint failed on { failed_count } / { total_count } files." )
90
+ if not success :
91
+ exit (1 )
84
92
else :
85
- print (f"Successfully tested { total_count } files ." )
93
+ print ("No problems found ." )
86
94
87
95
88
96
if __name__ == "__main__" :
0 commit comments