1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
23 # depends on pep8, pyflakes, pylint
26 # sudo apt-get install pylint pyflakes
28 # sudo apt-get install python-setuptools python-pip
29 # sudo pip install pep8
31 # in debian install pylint pyflakes pep8 with apt-get/aptitude/etc
34 # python source/tests/pep8.py > pep8_error.txt 2>&1
36 # how many lines to read into the file, pep8 comment
37 # should be directly after the licence header, ~20 in most cases
38 PEP8_SEEK_COMMENT = 40
39 SKIP_PREFIX = "./tools", "./config", "./scons", "./extern"
42 def file_list_py(path):
43 for dirpath, dirnames, filenames in os.walk(path):
44 for filename in filenames:
45 if filename.endswith(".py"):
46 yield os.path.join(dirpath, filename)
51 if open(path, 'rb').read(3) == b'\xef\xbb\xbf':
52 print("\nfile contains BOM, remove first 3 bytes: %r\n" % path)
54 # templates dont have a header but should be pep8
55 for d in ("presets", "templates", "examples"):
56 if ("%s%s%s" % (os.sep, d, os.sep)) in path:
59 f = open(path, 'r', encoding="utf8")
60 for i in range(PEP8_SEEK_COMMENT):
62 if line.startswith("# <pep8"):
63 if line.startswith("# <pep8 compliant>"):
65 elif line.startswith("# <pep8-80 compliant>"):
74 for f in file_list_py("."):
75 if [None for prefix in SKIP_PREFIX if f.startswith(prefix)]:
78 pep8_type = is_pep8(f)
81 # so we can batch them for each tool.
82 files.append((os.path.abspath(f), pep8_type))
86 print("\nSkipping...")
91 print("\n\n\n# running pep8...")
93 import_check = re.compile(r"\s*from\s+[A-z\.]+\s+import \*\s*")
94 for f, pep8_type in files:
95 for i, l in enumerate(open(f, 'r', encoding='utf8')):
96 if import_check.match(l):
97 print("%s:%d:0: global import bad practice" % (f, i + 1))
99 print("\n\n\n# running pep8...")
100 for f, pep8_type in files:
102 # E501:80 line length
103 os.system("pep8 --repeat --ignore=E501 '%s'" % (f))
105 os.system("pep8 --repeat '%s'" % (f))
108 print("\n\n\n# running pyflakes...")
109 for f, pep8_type in files:
110 os.system("pyflakes '%s'" % f)
112 print("\n\n\n# running pylint...")
113 for f, pep8_type in files:
114 # let pep8 complain about line length
115 os.system("pylint --reports=n --max-line-length=1000 '%s'" % f)
117 if __name__ == "__main__":