root / ci / pep8.py @ 09f7ad00
History | View | Annotate | Download (1.7 kB)
1 |
#!/usr/bin/env python
|
---|---|
2 |
|
3 |
"""
|
4 |
Check for pep8 error in a list of files
|
5 |
|
6 |
Get a list of files as command line arguments.
|
7 |
Of these files, invoke pep8 only for the ones that
|
8 |
actually exists, their name ends with .py, and doesn't
|
9 |
belong to our exclude list.
|
10 |
|
11 |
"""
|
12 |
|
13 |
import os |
14 |
import sys |
15 |
|
16 |
|
17 |
EXCLUDE = [ |
18 |
"distribute_setup.py",
|
19 |
"setup.py",
|
20 |
"rapi.py",
|
21 |
"dictconfig.py",
|
22 |
"ordereddict.py",
|
23 |
"parsedate.py",
|
24 |
] |
25 |
|
26 |
|
27 |
def filter_files(files): |
28 |
"""Filter our non-useful files
|
29 |
|
30 |
We want to keep only python files (ending with .py),
|
31 |
that actually exists and are not in our exclude list
|
32 |
"""
|
33 |
|
34 |
# Remove duplicated file names
|
35 |
files = list(set(files)) |
36 |
|
37 |
py_files = [] |
38 |
for f in files: |
39 |
# Check if file is a python file
|
40 |
if not f.endswith(".py"): |
41 |
continue
|
42 |
#Check if file is to be excluded
|
43 |
if os.path.basename(f) in EXCLUDE: |
44 |
continue
|
45 |
# Check if file existsw
|
46 |
if not os.path.isfile(f): |
47 |
continue
|
48 |
# Append file name
|
49 |
py_files.append(f) |
50 |
|
51 |
return py_files
|
52 |
|
53 |
|
54 |
def run_pep8(files): |
55 |
"""Invoke pep8
|
56 |
|
57 |
Return the exit code
|
58 |
|
59 |
"""
|
60 |
if files:
|
61 |
print "Invoke pep8 for the following files:\n %s\n\n" \ |
62 |
% "\n ".join(files)
|
63 |
return os.system("pep8 %s" % " ".join(files)) |
64 |
else:
|
65 |
print "No files to check.. aborting" |
66 |
return 0 |
67 |
|
68 |
|
69 |
def main(): |
70 |
"""Our main program
|
71 |
|
72 |
Read command line arguments.
|
73 |
Filter out non-useful files.
|
74 |
Invoke pep8.
|
75 |
|
76 |
"""
|
77 |
files = sys.argv[1:]
|
78 |
py_files = filter_files(files) |
79 |
exit_code = run_pep8(py_files) |
80 |
if exit_code != 0: |
81 |
status = "exit with status %s" % exit_code
|
82 |
sys.exit(status) |
83 |
|
84 |
|
85 |
if __name__ == "__main__": |
86 |
main() |