Skip to content

Commit f52f4fd

Browse files
plaesmitsuhiko
authored andcommitted
Added initial version of 'setup.py audit'
1 parent 549af62 commit f52f4fd

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

setup.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,44 @@ def hello():
3838
<http://github.com/mitsuhiko/flask/zipball/master#egg=Flask-dev>`_
3939
4040
"""
41-
from setuptools import setup
42-
41+
from setuptools import Command, setup
42+
43+
class run_audit(Command):
44+
"""Audits source code using PyFlakes for following issues:
45+
- Names which are used but not defined or used before they are defined.
46+
- Names which are redefined without having been used.
47+
"""
48+
description = "Audit source code with PyFlakes"
49+
user_options = []
50+
51+
def initialize_options(self):
52+
all = None
53+
54+
def finalize_options(self):
55+
pass
56+
57+
def run(self):
58+
import os, sys
59+
try:
60+
import pyflakes.scripts.pyflakes as flakes
61+
except ImportError:
62+
print "Audit requires PyFlakes installed in your system."""
63+
sys.exit(-1)
64+
65+
dirs = ['flask', 'tests']
66+
# Add example directories
67+
for dir in ['flaskr', 'jqueryexample', 'minitwit']:
68+
dirs.append(os.path.join('examples', dir))
69+
# TODO: Add test subdirectories
70+
warns = 0
71+
for dir in dirs:
72+
for filename in os.listdir(dir):
73+
if filename.endswith('.py') and filename != '__init__.py':
74+
warns += flakes.checkPath(os.path.join(dir, filename))
75+
if warns > 0:
76+
print ("Audit finished with total %d warnings." % warns)
77+
else:
78+
print ("No problems found in sourcecode.")
4379

4480
def run_tests():
4581
import os, sys
@@ -75,5 +111,6 @@ def run_tests():
75111
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
76112
'Topic :: Software Development :: Libraries :: Python Modules'
77113
],
114+
cmdclass={'audit': run_audit},
78115
test_suite='__main__.run_tests'
79116
)

0 commit comments

Comments
 (0)