1
1
#! /usr/bin/env python3
2
2
3
3
"""
4
- Performs pylint on all python files in the project repo's {test,script,docs} directory recursively.
5
-
6
- This script is meant to be run from the CI but can also be easily in local dev environment,
7
- where you can optionally pass `-d` as command line argument to let this script abort on first error.
4
+ Runs pylint on all Python files in project directories known to contain Python scripts.
8
5
"""
9
6
7
+ from argparse import ArgumentParser
10
8
from os import path , walk , system
11
- from sys import argv , exit as exitwith
9
+ from sys import exit as exitwith
10
+ from textwrap import dedent
12
11
13
12
PROJECT_ROOT = path .dirname (path .realpath (__file__ ))
14
13
PYLINT_RCFILE = "{}/pylintrc" .format (PROJECT_ROOT )
@@ -40,11 +39,29 @@ def pylint_all_filenames(dev_mode, rootdirs):
40
39
41
40
return len (failed ), len (filenames )
42
41
42
+
43
+ def parse_command_line ():
44
+ script_description = dedent ("""
45
+ Runs pylint on all Python files in project directories known to contain Python scripts.
46
+
47
+ This script is meant to be run from the CI but can also be easily used in the local dev
48
+ environment.
49
+ """ )
50
+
51
+ parser = ArgumentParser (description = script_description )
52
+ parser .add_argument (
53
+ '-d' , '--dev-mode' ,
54
+ dest = 'dev_mode' ,
55
+ default = False ,
56
+ action = 'store_true' ,
57
+ help = "Abort on first error."
58
+ )
59
+ return parser .parse_args ()
60
+
61
+
43
62
def main ():
44
- """ Collects all python script root dirs and runs pylint on them. You can optionally
45
- pass `-d` as command line argument to let this script abort on first error. """
46
- dev_mode = len (argv ) == 2 and argv [1 ] == "-d"
47
- failed_count , total_count = pylint_all_filenames (dev_mode , [
63
+ options = parse_command_line ()
64
+ failed_count , total_count = pylint_all_filenames (options .dev_mode , [
48
65
path .abspath (path .dirname (__file__ ) + "/../docs" ),
49
66
path .abspath (path .dirname (__file__ ) + "/../scripts" ),
50
67
path .abspath (path .dirname (__file__ ) + "/../test" )])
@@ -53,5 +70,6 @@ def main():
53
70
else :
54
71
print ("Successfully tested {} files." .format (total_count ))
55
72
73
+
56
74
if __name__ == "__main__" :
57
75
main ()
0 commit comments