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