|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric6.Plugins.CheckerPlugins.Tabnanny.Tabnanny</title> |
|
4 <meta charset="UTF-8"> |
|
5 <style> |
|
6 body { |
|
7 background: #EDECE6; |
|
8 margin: 0em 1em 10em 1em; |
|
9 color: black; |
|
10 } |
|
11 |
|
12 h1 { color: white; background: #85774A; } |
|
13 h2 { color: white; background: #85774A; } |
|
14 h3 { color: white; background: #9D936E; } |
|
15 h4 { color: white; background: #9D936E; } |
|
16 |
|
17 a { color: #BA6D36; } |
|
18 |
|
19 </style> |
|
20 </head> |
|
21 <body><a NAME="top" ID="top"></a> |
|
22 <h1>eric6.Plugins.CheckerPlugins.Tabnanny.Tabnanny</h1> |
|
23 <p> |
|
24 The Tab Nanny despises ambiguous indentation. She knows no mercy. |
|
25 </p><p> |
|
26 tabnanny -- Detection of ambiguous indentation |
|
27 </p><p> |
|
28 For the time being this module is intended to be called as a script. |
|
29 However it is possible to import it into an IDE and use the function |
|
30 check() described below. |
|
31 </p><p> |
|
32 Warning: The API provided by this module is likely to change in future |
|
33 releases; such changes may not be backward compatible. |
|
34 </p><p> |
|
35 This is a modified version to make the original tabnanny better suitable |
|
36 for being called from within the eric6 IDE. |
|
37 </p><dl> |
|
38 <dt>Raises <b>ValueError</b>:</dt> |
|
39 <dd> |
|
40 The tokenize module is too old. |
|
41 </dd> |
|
42 </dl> |
|
43 <h3>Global Attributes</h3> |
|
44 <table> |
|
45 <tr><td>__all__</td></tr><tr><td>__version__</td></tr> |
|
46 </table> |
|
47 <h3>Classes</h3> |
|
48 <table> |
|
49 <tr> |
|
50 <td><a href="#NannyNag">NannyNag</a></td> |
|
51 <td>Class implementing an exception for indentation issues.</td> |
|
52 </tr><tr> |
|
53 <td><a href="#Whitespace">Whitespace</a></td> |
|
54 <td>Class implementing the whitespace checker.</td> |
|
55 </tr> |
|
56 </table> |
|
57 <h3>Functions</h3> |
|
58 <table> |
|
59 <tr> |
|
60 <td><a href="#__check">__check</a></td> |
|
61 <td>Private function to check one Python source file for whitespace related problems.</td> |
|
62 </tr><tr> |
|
63 <td><a href="#batchCheck">batchCheck</a></td> |
|
64 <td>Module function to check a batch of files for whitespace related problems.</td> |
|
65 </tr><tr> |
|
66 <td><a href="#check">check</a></td> |
|
67 <td>Private function to check one Python source file for whitespace related problems.</td> |
|
68 </tr><tr> |
|
69 <td><a href="#format_witnesses">format_witnesses</a></td> |
|
70 <td>Function to format the witnesses as a readable string.</td> |
|
71 </tr><tr> |
|
72 <td><a href="#initBatchService">initBatchService</a></td> |
|
73 <td>Initialize the batch service and return the entry point.</td> |
|
74 </tr><tr> |
|
75 <td><a href="#initService">initService</a></td> |
|
76 <td>Initialize the service and return the entry point.</td> |
|
77 </tr><tr> |
|
78 <td><a href="#process_tokens">process_tokens</a></td> |
|
79 <td>Function processing all tokens generated by a tokenizer run.</td> |
|
80 </tr><tr> |
|
81 <td><a href="#worker">worker</a></td> |
|
82 <td>Module function acting as the parallel worker for the style check.</td> |
|
83 </tr> |
|
84 </table> |
|
85 <hr /><hr /> |
|
86 <a NAME="NannyNag" ID="NannyNag"></a> |
|
87 <h2>NannyNag</h2> |
|
88 <p> |
|
89 Class implementing an exception for indentation issues. |
|
90 </p><p> |
|
91 Raised by tokeneater() if detecting an ambiguous indent. |
|
92 Captured and handled in check(). |
|
93 </p> |
|
94 <h3>Derived from</h3> |
|
95 Exception |
|
96 <h3>Class Attributes</h3> |
|
97 <table> |
|
98 <tr><td>None</td></tr> |
|
99 </table> |
|
100 <h3>Class Methods</h3> |
|
101 <table> |
|
102 <tr><td>None</td></tr> |
|
103 </table> |
|
104 <h3>Methods</h3> |
|
105 <table> |
|
106 <tr> |
|
107 <td><a href="#NannyNag.__init__">NannyNag</a></td> |
|
108 <td>Constructor</td> |
|
109 </tr><tr> |
|
110 <td><a href="#NannyNag.get_line">get_line</a></td> |
|
111 <td>Public method to retrieve the offending line.</td> |
|
112 </tr><tr> |
|
113 <td><a href="#NannyNag.get_lineno">get_lineno</a></td> |
|
114 <td>Public method to retrieve the line number.</td> |
|
115 </tr><tr> |
|
116 <td><a href="#NannyNag.get_msg">get_msg</a></td> |
|
117 <td>Public method to retrieve the message.</td> |
|
118 </tr> |
|
119 </table> |
|
120 <h3>Static Methods</h3> |
|
121 <table> |
|
122 <tr><td>None</td></tr> |
|
123 </table> |
|
124 <a NAME="NannyNag.__init__" ID="NannyNag.__init__"></a> |
|
125 <h4>NannyNag (Constructor)</h4> |
|
126 <b>NannyNag</b>(<i>lineno, msg, line</i>) |
|
127 <p> |
|
128 Constructor |
|
129 </p><dl> |
|
130 <dt><i>lineno</i></dt> |
|
131 <dd> |
|
132 Line number of the ambiguous indent. |
|
133 </dd><dt><i>msg</i></dt> |
|
134 <dd> |
|
135 Descriptive message assigned to this problem. |
|
136 </dd><dt><i>line</i></dt> |
|
137 <dd> |
|
138 The offending source line. |
|
139 </dd> |
|
140 </dl><a NAME="NannyNag.get_line" ID="NannyNag.get_line"></a> |
|
141 <h4>NannyNag.get_line</h4> |
|
142 <b>get_line</b>(<i></i>) |
|
143 <p> |
|
144 Public method to retrieve the offending line. |
|
145 </p><dl> |
|
146 <dt>Returns:</dt> |
|
147 <dd> |
|
148 The line of code (string) |
|
149 </dd> |
|
150 </dl><a NAME="NannyNag.get_lineno" ID="NannyNag.get_lineno"></a> |
|
151 <h4>NannyNag.get_lineno</h4> |
|
152 <b>get_lineno</b>(<i></i>) |
|
153 <p> |
|
154 Public method to retrieve the line number. |
|
155 </p><dl> |
|
156 <dt>Returns:</dt> |
|
157 <dd> |
|
158 The line number (integer) |
|
159 </dd> |
|
160 </dl><a NAME="NannyNag.get_msg" ID="NannyNag.get_msg"></a> |
|
161 <h4>NannyNag.get_msg</h4> |
|
162 <b>get_msg</b>(<i></i>) |
|
163 <p> |
|
164 Public method to retrieve the message. |
|
165 </p><dl> |
|
166 <dt>Returns:</dt> |
|
167 <dd> |
|
168 The error message (string) |
|
169 </dd> |
|
170 </dl> |
|
171 <div align="right"><a href="#top">Up</a></div> |
|
172 <hr /><hr /> |
|
173 <a NAME="Whitespace" ID="Whitespace"></a> |
|
174 <h2>Whitespace</h2> |
|
175 <p> |
|
176 Class implementing the whitespace checker. |
|
177 </p> |
|
178 <h3>Derived from</h3> |
|
179 object |
|
180 <h3>Class Attributes</h3> |
|
181 <table> |
|
182 <tr><td>None</td></tr> |
|
183 </table> |
|
184 <h3>Class Methods</h3> |
|
185 <table> |
|
186 <tr><td>None</td></tr> |
|
187 </table> |
|
188 <h3>Methods</h3> |
|
189 <table> |
|
190 <tr> |
|
191 <td><a href="#Whitespace.__init__">Whitespace</a></td> |
|
192 <td>Constructor</td> |
|
193 </tr><tr> |
|
194 <td><a href="#Whitespace.equal">equal</a></td> |
|
195 <td>Public method to compare the indentation levels of two Whitespace objects for equality.</td> |
|
196 </tr><tr> |
|
197 <td><a href="#Whitespace.indent_level">indent_level</a></td> |
|
198 <td>Public method to determine the indentation level.</td> |
|
199 </tr><tr> |
|
200 <td><a href="#Whitespace.less">less</a></td> |
|
201 <td>Public method to compare the indentation level against another Whitespace objects to be smaller.</td> |
|
202 </tr><tr> |
|
203 <td><a href="#Whitespace.longest_run_of_spaces">longest_run_of_spaces</a></td> |
|
204 <td>Public method to calculate the length of longest contiguous run of spaces.</td> |
|
205 </tr><tr> |
|
206 <td><a href="#Whitespace.not_equal_witness">not_equal_witness</a></td> |
|
207 <td>Public method to calculate a tuple of witnessing tab size.</td> |
|
208 </tr><tr> |
|
209 <td><a href="#Whitespace.not_less_witness">not_less_witness</a></td> |
|
210 <td>Public method to calculate a tuple of witnessing tab size.</td> |
|
211 </tr> |
|
212 </table> |
|
213 <h3>Static Methods</h3> |
|
214 <table> |
|
215 <tr><td>None</td></tr> |
|
216 </table> |
|
217 <a NAME="Whitespace.__init__" ID="Whitespace.__init__"></a> |
|
218 <h4>Whitespace (Constructor)</h4> |
|
219 <b>Whitespace</b>(<i>ws</i>) |
|
220 <p> |
|
221 Constructor |
|
222 </p><dl> |
|
223 <dt><i>ws</i></dt> |
|
224 <dd> |
|
225 The string to be checked. |
|
226 </dd> |
|
227 </dl><a NAME="Whitespace.equal" ID="Whitespace.equal"></a> |
|
228 <h4>Whitespace.equal</h4> |
|
229 <b>equal</b>(<i>other</i>) |
|
230 <p> |
|
231 Public method to compare the indentation levels of two Whitespace |
|
232 objects for equality. |
|
233 </p><dl> |
|
234 <dt><i>other</i></dt> |
|
235 <dd> |
|
236 Whitespace object to compare against. |
|
237 </dd> |
|
238 </dl><dl> |
|
239 <dt>Returns:</dt> |
|
240 <dd> |
|
241 True, if we compare equal against the other Whitespace object. |
|
242 </dd> |
|
243 </dl><a NAME="Whitespace.indent_level" ID="Whitespace.indent_level"></a> |
|
244 <h4>Whitespace.indent_level</h4> |
|
245 <b>indent_level</b>(<i>tabsize</i>) |
|
246 <p> |
|
247 Public method to determine the indentation level. |
|
248 </p><dl> |
|
249 <dt><i>tabsize</i></dt> |
|
250 <dd> |
|
251 The length of a tab stop. (integer) |
|
252 </dd> |
|
253 </dl><dl> |
|
254 <dt>Returns:</dt> |
|
255 <dd> |
|
256 indentation level (integer) |
|
257 </dd> |
|
258 </dl><a NAME="Whitespace.less" ID="Whitespace.less"></a> |
|
259 <h4>Whitespace.less</h4> |
|
260 <b>less</b>(<i>other</i>) |
|
261 <p> |
|
262 Public method to compare the indentation level against another |
|
263 Whitespace objects to be smaller. |
|
264 </p><dl> |
|
265 <dt><i>other</i></dt> |
|
266 <dd> |
|
267 Whitespace object to compare against. |
|
268 </dd> |
|
269 </dl><dl> |
|
270 <dt>Returns:</dt> |
|
271 <dd> |
|
272 True, if we compare less against the other Whitespace object. |
|
273 </dd> |
|
274 </dl><a NAME="Whitespace.longest_run_of_spaces" ID="Whitespace.longest_run_of_spaces"></a> |
|
275 <h4>Whitespace.longest_run_of_spaces</h4> |
|
276 <b>longest_run_of_spaces</b>(<i></i>) |
|
277 <p> |
|
278 Public method to calculate the length of longest contiguous run of |
|
279 spaces. |
|
280 </p><dl> |
|
281 <dt>Returns:</dt> |
|
282 <dd> |
|
283 The length of longest contiguous run of spaces (whether or not |
|
284 preceding a tab) |
|
285 </dd> |
|
286 </dl><a NAME="Whitespace.not_equal_witness" ID="Whitespace.not_equal_witness"></a> |
|
287 <h4>Whitespace.not_equal_witness</h4> |
|
288 <b>not_equal_witness</b>(<i>other</i>) |
|
289 <p> |
|
290 Public method to calculate a tuple of witnessing tab size. |
|
291 </p><p> |
|
292 Intended to be used after not self.equal(other) is known, in which |
|
293 case it will return at least one witnessing tab size. |
|
294 </p><dl> |
|
295 <dt><i>other</i></dt> |
|
296 <dd> |
|
297 Whitespace object to calculate against. |
|
298 </dd> |
|
299 </dl><dl> |
|
300 <dt>Returns:</dt> |
|
301 <dd> |
|
302 A list of tuples (ts, i1, i2) such that |
|
303 i1 == self.indent_level(ts) != other.indent_level(ts) == i2. |
|
304 </dd> |
|
305 </dl><a NAME="Whitespace.not_less_witness" ID="Whitespace.not_less_witness"></a> |
|
306 <h4>Whitespace.not_less_witness</h4> |
|
307 <b>not_less_witness</b>(<i>other</i>) |
|
308 <p> |
|
309 Public method to calculate a tuple of witnessing tab size. |
|
310 </p><p> |
|
311 Intended to be used after not self.less(other is known, in which |
|
312 case it will return at least one witnessing tab size. |
|
313 </p><dl> |
|
314 <dt><i>other</i></dt> |
|
315 <dd> |
|
316 Whitespace object to calculate against. |
|
317 </dd> |
|
318 </dl><dl> |
|
319 <dt>Returns:</dt> |
|
320 <dd> |
|
321 A list of tuples (ts, i1, i2) such that |
|
322 i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. |
|
323 </dd> |
|
324 </dl> |
|
325 <div align="right"><a href="#top">Up</a></div> |
|
326 <hr /><hr /> |
|
327 <a NAME="__check" ID="__check"></a> |
|
328 <h2>__check</h2> |
|
329 <b>__check</b>(<i>file, text=""</i>) |
|
330 <p> |
|
331 Private function to check one Python source file for whitespace related |
|
332 problems. |
|
333 </p><dl> |
|
334 <dt><i>file</i></dt> |
|
335 <dd> |
|
336 source filename (string) |
|
337 </dd><dt><i>text</i></dt> |
|
338 <dd> |
|
339 source text (string) |
|
340 </dd> |
|
341 </dl><dl> |
|
342 <dt>Returns:</dt> |
|
343 <dd> |
|
344 A tuple indicating status (True = an error was found), the |
|
345 filename, the linenumber and the error message |
|
346 (boolean, string, string). The values are only |
|
347 valid, if the status is True. |
|
348 </dd> |
|
349 </dl> |
|
350 <div align="right"><a href="#top">Up</a></div> |
|
351 <hr /><hr /> |
|
352 <a NAME="batchCheck" ID="batchCheck"></a> |
|
353 <h2>batchCheck</h2> |
|
354 <b>batchCheck</b>(<i>argumentsList, send, fx, cancelled, maxProcesses=0</i>) |
|
355 <p> |
|
356 Module function to check a batch of files for whitespace related problems. |
|
357 </p><dl> |
|
358 <dt><i>argumentsList</i> (list)</dt> |
|
359 <dd> |
|
360 list of arguments tuples as given for check |
|
361 </dd><dt><i>send</i> (func)</dt> |
|
362 <dd> |
|
363 reference to send function |
|
364 </dd><dt><i>fx</i> (str)</dt> |
|
365 <dd> |
|
366 registered service name |
|
367 </dd><dt><i>cancelled</i> (func)</dt> |
|
368 <dd> |
|
369 reference to function checking for a cancellation |
|
370 </dd><dt><i>maxProcesses</i> (int)</dt> |
|
371 <dd> |
|
372 number of processes to be used |
|
373 </dd> |
|
374 </dl> |
|
375 <div align="right"><a href="#top">Up</a></div> |
|
376 <hr /><hr /> |
|
377 <a NAME="check" ID="check"></a> |
|
378 <h2>check</h2> |
|
379 <b>check</b>(<i>file, text=""</i>) |
|
380 <p> |
|
381 Private function to check one Python source file for whitespace related |
|
382 problems. |
|
383 </p><dl> |
|
384 <dt><i>file</i></dt> |
|
385 <dd> |
|
386 source filename (string) |
|
387 </dd><dt><i>text</i></dt> |
|
388 <dd> |
|
389 source text (string) |
|
390 </dd> |
|
391 </dl><dl> |
|
392 <dt>Returns:</dt> |
|
393 <dd> |
|
394 A tuple indicating status (True = an error was found), the |
|
395 filename, the linenumber and the error message |
|
396 (boolean, string, string, string). The values are only |
|
397 valid, if the status is True. |
|
398 </dd> |
|
399 </dl> |
|
400 <div align="right"><a href="#top">Up</a></div> |
|
401 <hr /><hr /> |
|
402 <a NAME="format_witnesses" ID="format_witnesses"></a> |
|
403 <h2>format_witnesses</h2> |
|
404 <b>format_witnesses</b>(<i>w</i>) |
|
405 <p> |
|
406 Function to format the witnesses as a readable string. |
|
407 </p><dl> |
|
408 <dt><i>w</i></dt> |
|
409 <dd> |
|
410 A list of witnesses |
|
411 </dd> |
|
412 </dl><dl> |
|
413 <dt>Returns:</dt> |
|
414 <dd> |
|
415 A formated string of the witnesses. |
|
416 </dd> |
|
417 </dl> |
|
418 <div align="right"><a href="#top">Up</a></div> |
|
419 <hr /><hr /> |
|
420 <a NAME="initBatchService" ID="initBatchService"></a> |
|
421 <h2>initBatchService</h2> |
|
422 <b>initBatchService</b>(<i></i>) |
|
423 <p> |
|
424 Initialize the batch service and return the entry point. |
|
425 </p><dl> |
|
426 <dt>Returns:</dt> |
|
427 <dd> |
|
428 the entry point for the background client (function) |
|
429 </dd> |
|
430 </dl> |
|
431 <div align="right"><a href="#top">Up</a></div> |
|
432 <hr /><hr /> |
|
433 <a NAME="initService" ID="initService"></a> |
|
434 <h2>initService</h2> |
|
435 <b>initService</b>(<i></i>) |
|
436 <p> |
|
437 Initialize the service and return the entry point. |
|
438 </p><dl> |
|
439 <dt>Returns:</dt> |
|
440 <dd> |
|
441 the entry point for the background client (function) |
|
442 </dd> |
|
443 </dl> |
|
444 <div align="right"><a href="#top">Up</a></div> |
|
445 <hr /><hr /> |
|
446 <a NAME="process_tokens" ID="process_tokens"></a> |
|
447 <h2>process_tokens</h2> |
|
448 <b>process_tokens</b>(<i>tokens</i>) |
|
449 <p> |
|
450 Function processing all tokens generated by a tokenizer run. |
|
451 </p><dl> |
|
452 <dt><i>tokens</i></dt> |
|
453 <dd> |
|
454 list of tokens |
|
455 </dd> |
|
456 </dl><dl> |
|
457 <dt>Raises <b>NannyNag</b>:</dt> |
|
458 <dd> |
|
459 raised to indicate an indentation error |
|
460 </dd> |
|
461 </dl> |
|
462 <div align="right"><a href="#top">Up</a></div> |
|
463 <hr /><hr /> |
|
464 <a NAME="worker" ID="worker"></a> |
|
465 <h2>worker</h2> |
|
466 <b>worker</b>(<i>inputQueue, outputQueue</i>) |
|
467 <p> |
|
468 Module function acting as the parallel worker for the style check. |
|
469 </p><dl> |
|
470 <dt><i>inputQueue</i></dt> |
|
471 <dd> |
|
472 input queue (multiprocessing.Queue) |
|
473 </dd><dt><i>outputQueue</i></dt> |
|
474 <dd> |
|
475 output queue (multiprocessing.Queue) |
|
476 </dd> |
|
477 </dl> |
|
478 <div align="right"><a href="#top">Up</a></div> |
|
479 <hr /> |
|
480 </body></html> |