UtilitiesPython2/CodeStyleChecker.py

Tue, 17 Jun 2014 19:48:58 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 17 Jun 2014 19:48:58 +0200
branch
5_4_x
changeset 3639
5234afd7a6d7
parent 3165
400234200cd6
permissions
-rw-r--r--

Added code to the multi project 'Add Project' dialog to ensure, that the filename returned is absolute. If a relative one is entered it is concatenated with the path of the multi project file or the 'workspace', if it hasn't been saved yet.

842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
3 # Copyright (c) 2011 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Class implementing the PEP 8 checker for Python2.
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import sys
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import getopt
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from Tools import readEncodedFile, normalizeCode
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import pep8
2983
f2f33024b001 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
16 from NamingStyleCheckerPy2 import NamingStyleChecker
2896
9fa71ee50b3d Finished the pEP-8 naming checker implementation by doing the Py2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2864
diff changeset
17
9fa71ee50b3d Finished the pEP-8 naming checker implementation by doing the Py2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2864
diff changeset
18 # register the name checker
2983
f2f33024b001 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
19 pep8.register_check(NamingStyleChecker, NamingStyleChecker.Codes)
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
2983
f2f33024b001 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
21 from DocStyleCheckerPy2 import DocStyleChecker
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2896
diff changeset
22
843
522c8befcf49 Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 842
diff changeset
23
2983
f2f33024b001 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
24 class CodeStyleReport(pep8.BaseReport):
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
26 Class implementing a special report to be used with our dialog.
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
28 def __init__(self, options):
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Constructor
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
32 @param options options for the report (optparse.Values)
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
2983
f2f33024b001 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
34 super(CodeStyleReport, self).__init__(options)
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
36 self.__repeat = options.repeat
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
37 self.errors = []
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
39 def error_args(self, line_number, offset, code, check, *args):
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Public method to collect the error messages.
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @param line_number line number of the issue (integer)
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @param offset position within line of the issue (integer)
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @param code message code (string)
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @param check reference to the checker function (function)
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @param args arguments for the message (list)
2965
d133c7edd88a Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2958
diff changeset
48 @return error code (string)
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
2983
f2f33024b001 Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2965
diff changeset
50 code = super(CodeStyleReport, self).error_args(
2896
9fa71ee50b3d Finished the pEP-8 naming checker implementation by doing the Py2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2864
diff changeset
51 line_number, offset, code, check, *args)
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
52 if code and (self.counters[code] == 1 or self.__repeat):
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
53 self.errors.append(
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
54 (self.filename, line_number, offset, code, args)
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 )
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
56 return code
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
57
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 if __name__ == "__main__":
843
522c8befcf49 Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 842
diff changeset
60 repeat = False
522c8befcf49 Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 842
diff changeset
61 select = ""
522c8befcf49 Continued implementing a PRP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 842
diff changeset
62 ignore = ""
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 filename = ""
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
64 max_line_length = 79
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
65 hang_closing = False
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
66 docType = "pep257"
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if "-f" not in sys.argv:
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 print "ERROR"
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 print ""
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 print "No file name given."
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 else:
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 try:
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
74 optlist, args = getopt.getopt(sys.argv[1:], "d:f:hi:m:rs:")
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 except getopt.GetoptError:
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 print "ERROR"
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 print ""
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 print "Wrong arguments given"
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 sys.exit(1)
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 for opt, arg in optlist:
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if opt == "-r":
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 repeat = True
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 elif opt == "-f":
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 filename = arg
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 elif opt == "-i":
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 ignore = arg
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 elif opt == "-s":
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 select = arg
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
90 elif opt == "-m":
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
91 try:
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
92 max_line_length = int(arg)
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
93 except ValueError:
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
94 # ignore silently
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
95 pass
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
96 elif opt == "-h":
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
97 hang_closing = True
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
98 elif opt == "-d":
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
99 if arg in ("pep257", "eric"):
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
100 docType = arg
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 try:
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2896
diff changeset
103 source = readEncodedFile(filename)[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2896
diff changeset
104 source = normalizeCode(source)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2896
diff changeset
105 source = source.splitlines(True)
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 except IOError, msg:
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 print "ERROR"
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 print filename
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 print "I/O Error: %s" % unicode(msg)
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 sys.exit(1)
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
2864
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
112 if select:
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
113 select = [s.strip() for s in select.split(',')
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
114 if s.strip()]
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
115 else:
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
116 select = []
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
117 if ignore:
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
118 ignore = [i.strip() for i in ignore.split(',')
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
119 if i.strip()]
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
120 else:
d973dab8b715 Upgraded the Py2 part of the pep8 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
121 ignore = []
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2896
diff changeset
122
3165
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
123 try:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
124 # check coding style
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
125 styleGuide = pep8.StyleGuide(
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
126 reporter=CodeStyleReport,
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
127 repeat=repeat,
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
128 select=select,
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
129 ignore=ignore,
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
130 max_line_length=max_line_length,
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
131 hang_closing=hang_closing,
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
132 )
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
133 report = styleGuide.check_files([filename])
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
134
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
135 # check documentation style
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
136 docStyleChecker = DocStyleChecker(
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
137 source, filename, select, ignore, [], repeat,
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
138 maxLineLength=max_line_length, docType=docType)
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
139 docStyleChecker.run()
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
140
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
141 errors = report.errors + docStyleChecker.errors
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
142
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
143 if len(errors) > 0:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
144 errors.sort(key=lambda a: a[1])
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
145 for error in errors:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
146 fname, lineno, position, code, args = error
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
147 print "PEP8"
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
148 print fname
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
149 print lineno
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
150 print position
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
151 print code
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
152 print len(args)
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
153 for a in args:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
154 print a
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
155 print "PEP8_STATISTICS"
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
156 for key in report.counters:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
157 if key.startswith(("E", "N", "W")):
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
158 print key, report.counters[key]
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
159 for key in docStyleChecker.counters:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
160 if key.startswith("D"):
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
161 print key, docStyleChecker.counters[key]
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
162 else:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
163 print "NO_PEP8"
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
164 print filename
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
165 except StandardError, msg:
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
166 import traceback
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
167 print "EXCEPTION"
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
168 print ""
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
169 print "Error in eric5 code:"
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
170 print traceback.format_exc()
400234200cd6 Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
171 sys.exit(1)
842
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 #
984b5535cd26 Started to add the PEP 8 checker for Python2.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 # eflag: FileType = Python2

eric ide

mercurial