Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleChecker.py

changeset 4218
f542ad1f76c5
parent 4021
195a471c327b
child 4221
c9fdc07753a7
equal deleted inserted replaced
4217:38e8903f9c2f 4218:f542ad1f76c5
6 """ 6 """
7 Module implementing the code style checker. 7 Module implementing the code style checker.
8 """ 8 """
9 9
10 import sys 10 import sys
11 import multiprocessing
11 12
12 import pep8 13 import pep8
13 from NamingStyleChecker import NamingStyleChecker 14 from NamingStyleChecker import NamingStyleChecker
14 15
15 # register the name checker 16 # register the name checker
23 Initialize the service and return the entry point. 24 Initialize the service and return the entry point.
24 25
25 @return the entry point for the background client (function) 26 @return the entry point for the background client (function)
26 """ 27 """
27 return codeStyleCheck 28 return codeStyleCheck
29
30
31 def initBatchService():
32 """
33 Initialize the batch service and return the entry point.
34
35 @return the entry point for the background client (function)
36 """
37 return codeStyleBatchCheck
28 38
29 39
30 class CodeStyleCheckerReport(pep8.BaseReport): 40 class CodeStyleCheckerReport(pep8.BaseReport):
31 """ 41 """
32 Class implementing a special report to be used with our dialog. 42 Class implementing a special report to be used with our dialog.
85 95
86 96
87 def codeStyleCheck(filename, source, args): 97 def codeStyleCheck(filename, source, args):
88 """ 98 """
89 Do the code style check and/ or fix found errors. 99 Do the code style check and/ or fix found errors.
100
101 @param filename source filename (string)
102 @param source string containing the code to check (string)
103 @param args arguments used by the codeStyleCheck function (list of
104 excludeMessages (str), includeMessages (str), repeatMessages
105 (bool), fixCodes (str), noFixCodes (str), fixIssues (bool),
106 maxLineLength (int), hangClosing (bool), docType (str), errors
107 (list of str), eol (str), encoding (str), backup (bool))
108 @return tuple of stats (dict) and results (tuple for each found violation
109 of style (tuple of lineno (int), position (int), text (str), ignored
110 (bool), fixed (bool), autofixing (bool), fixedMsg (str)))
111 """
112 return __checkCodeStyle(filename, source, args)
113
114
115 def codeStyleBatchCheck(argumentsList, send, fx):
116 """
117 Module function to check code style for a batch of files.
118
119 @param argumentsList list of arguments tuples as given for codeStyleCheck
120 @param send reference to send method
121 @param fx registered service name (string)
122 """
123 try:
124 NumberOfProcesses = multiprocessing.cpu_count()
125 except NotImplementedError:
126 NumberOfProcesses = 4
127
128 # Create queues
129 taskQueue = multiprocessing.Queue()
130 doneQueue = multiprocessing.Queue()
131
132 # Submit tasks
133 for task in argumentsList:
134 taskQueue.put(task)
135
136 # Start worker processes
137 for i in range(NumberOfProcesses):
138 multiprocessing.Process(target=worker, args=(taskQueue, doneQueue))\
139 .start()
140
141 # Get and send results
142 for i in range(len(argumentsList)):
143 filename, result = doneQueue.get()
144 send(fx, filename, result)
145
146 # Tell child processes to stop
147 for i in range(NumberOfProcesses):
148 taskQueue.put('STOP')
149
150
151 def worker(input, output):
152 """
153 Module function acting as the parallel worker for the style check.
154
155 @param input input queue (multiprocessing.Queue)
156 @param output output queue (multiprocessing.Queue)
157 """
158 for filename, source, args in iter(input.get, 'STOP'):
159 result = __checkCodeStyle(filename, source, args)
160 output.put((filename, result))
161
162
163 def __checkCodeStyle(filename, source, args):
164 """
165 Private module function to perform the code style check and/or fix
166 found errors.
90 167
91 @param filename source filename (string) 168 @param filename source filename (string)
92 @param source string containing the code to check (string) 169 @param source string containing the code to check (string)
93 @param args arguments used by the codeStyleCheck function (list of 170 @param args arguments used by the codeStyleCheck function (list of
94 excludeMessages (str), includeMessages (str), repeatMessages 171 excludeMessages (str), includeMessages (str), repeatMessages

eric ide

mercurial