Wed, 12 Aug 2020 17:10:50 +0200
Checkers: removed the obsolete Tabnanny checker dialog.
eric6.e4p | file | annotate | diff | comparison | revisions | |
eric6/Documentation/Source/eric6.Plugins.CheckerPlugins.Tabnanny.Tabnanny.html | file | annotate | diff | comparison | revisions | |
eric6/Documentation/Source/eric6.Plugins.CheckerPlugins.Tabnanny.TabnannyDialog.html | file | annotate | diff | comparison | revisions | |
eric6/Documentation/Source/eric6.Plugins.PluginTabnanny.html | file | annotate | diff | comparison | revisions | |
eric6/Plugins/CheckerPlugins/Tabnanny/Tabnanny.py | file | annotate | diff | comparison | revisions | |
eric6/Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.py | file | annotate | diff | comparison | revisions | |
eric6/Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.ui | file | annotate | diff | comparison | revisions | |
eric6/Plugins/CheckerPlugins/Tabnanny/__init__.py | file | annotate | diff | comparison | revisions | |
eric6/Plugins/PluginTabnanny.py | file | annotate | diff | comparison | revisions |
--- a/eric6.e4p Tue Aug 11 16:40:11 2020 +0200 +++ b/eric6.e4p Wed Aug 12 17:10:50 2020 +0200 @@ -368,9 +368,6 @@ <Source>eric6/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/messages.py</Source> <Source>eric6/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/translations.py</Source> <Source>eric6/Plugins/CheckerPlugins/SyntaxChecker/yamlCheckSyntax.py</Source> - <Source>eric6/Plugins/CheckerPlugins/Tabnanny/Tabnanny.py</Source> - <Source>eric6/Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.py</Source> - <Source>eric6/Plugins/CheckerPlugins/Tabnanny/__init__.py</Source> <Source>eric6/Plugins/CheckerPlugins/__init__.py</Source> <Source>eric6/Plugins/DocumentationPlugins/Ericapi/EricapiConfigDialog.py</Source> <Source>eric6/Plugins/DocumentationPlugins/Ericapi/EricapiExecDialog.py</Source> @@ -384,7 +381,6 @@ <Source>eric6/Plugins/PluginEricapi.py</Source> <Source>eric6/Plugins/PluginEricdoc.py</Source> <Source>eric6/Plugins/PluginSyntaxChecker.py</Source> - <Source>eric6/Plugins/PluginTabnanny.py</Source> <Source>eric6/Plugins/PluginTranslator.py</Source> <Source>eric6/Plugins/PluginVcsGit.py</Source> <Source>eric6/Plugins/PluginVcsMercurial.py</Source> @@ -1685,7 +1681,6 @@ <Form>eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleCodeSelectionDialog.ui</Form> <Form>eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleStatisticsDialog.ui</Form> <Form>eric6/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.ui</Form> - <Form>eric6/Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.ui</Form> <Form>eric6/Plugins/DocumentationPlugins/Ericapi/EricapiConfigDialog.ui</Form> <Form>eric6/Plugins/DocumentationPlugins/Ericapi/EricapiExecDialog.ui</Form> <Form>eric6/Plugins/DocumentationPlugins/Ericdoc/EricdocConfigDialog.ui</Form>
--- a/eric6/Documentation/Source/eric6.Plugins.CheckerPlugins.Tabnanny.Tabnanny.html Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,616 +0,0 @@ -<!DOCTYPE html> -<html><head> -<title>eric6.Plugins.CheckerPlugins.Tabnanny.Tabnanny</title> -<meta charset="UTF-8"> -<style> -body { - background: #EDECE6; - margin: 0em 1em 10em 1em; - color: black; -} - -h1 { color: white; background: #85774A; } -h2 { color: white; background: #85774A; } -h3 { color: white; background: #9D936E; } -h4 { color: white; background: #9D936E; } - -a { color: #BA6D36; } - -</style> -</head> -<body> -<a NAME="top" ID="top"></a> -<h1>eric6.Plugins.CheckerPlugins.Tabnanny.Tabnanny</h1> - -<p> -The Tab Nanny despises ambiguous indentation. She knows no mercy. -</p> -<p> -tabnanny -- Detection of ambiguous indentation -</p> -<p> -For the time being this module is intended to be called as a script. -However it is possible to import it into an IDE and use the function -check() described below. -</p> -<p> -Warning: The API provided by this module is likely to change in future -releases; such changes may not be backward compatible. -</p> -<p> -This is a modified version to make the original tabnanny better suitable -for being called from within the eric6 IDE. -</p> -<dl> - -<dt>Raises <b>ValueError</b>:</dt> -<dd> -The tokenize module is too old. -</dd> -</dl> -<h3>Global Attributes</h3> - -<table> -<tr><td>__all__</td></tr><tr><td>__version__</td></tr> -</table> -<h3>Classes</h3> - -<table> - -<tr> -<td><a href="#NannyNag">NannyNag</a></td> -<td>Class implementing an exception for indentation issues.</td> -</tr> -<tr> -<td><a href="#Whitespace">Whitespace</a></td> -<td>Class implementing the whitespace checker.</td> -</tr> -</table> -<h3>Functions</h3> - -<table> - -<tr> -<td><a href="#__check">__check</a></td> -<td>Private function to check one Python source file for whitespace related problems.</td> -</tr> -<tr> -<td><a href="#batchCheck">batchCheck</a></td> -<td>Module function to check a batch of files for whitespace related problems.</td> -</tr> -<tr> -<td><a href="#check">check</a></td> -<td>Private function to check one Python source file for whitespace related problems.</td> -</tr> -<tr> -<td><a href="#format_witnesses">format_witnesses</a></td> -<td>Function to format the witnesses as a readable string.</td> -</tr> -<tr> -<td><a href="#initBatchService">initBatchService</a></td> -<td>Initialize the batch service and return the entry point.</td> -</tr> -<tr> -<td><a href="#initService">initService</a></td> -<td>Initialize the service and return the entry point.</td> -</tr> -<tr> -<td><a href="#process_tokens">process_tokens</a></td> -<td>Function processing all tokens generated by a tokenizer run.</td> -</tr> -<tr> -<td><a href="#worker">worker</a></td> -<td>Module function acting as the parallel worker for the style check.</td> -</tr> -</table> -<hr /> -<hr /> -<a NAME="NannyNag" ID="NannyNag"></a> -<h2>NannyNag</h2> - -<p> - Class implementing an exception for indentation issues. -</p> -<p> - Raised by tokeneater() if detecting an ambiguous indent. - Captured and handled in check(). -</p> -<h3>Derived from</h3> -Exception -<h3>Class Attributes</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Class Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Methods</h3> - -<table> - -<tr> -<td><a href="#NannyNag.__init__">NannyNag</a></td> -<td>Constructor</td> -</tr> -<tr> -<td><a href="#NannyNag.get_line">get_line</a></td> -<td>Public method to retrieve the offending line.</td> -</tr> -<tr> -<td><a href="#NannyNag.get_lineno">get_lineno</a></td> -<td>Public method to retrieve the line number.</td> -</tr> -<tr> -<td><a href="#NannyNag.get_msg">get_msg</a></td> -<td>Public method to retrieve the message.</td> -</tr> -</table> -<h3>Static Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> - -<a NAME="NannyNag.__init__" ID="NannyNag.__init__"></a> -<h4>NannyNag (Constructor)</h4> -<b>NannyNag</b>(<i>lineno, msg, line</i>) - -<p> - Constructor -</p> -<dl> - -<dt><i>lineno</i></dt> -<dd> -Line number of the ambiguous indent. -</dd> -<dt><i>msg</i></dt> -<dd> -Descriptive message assigned to this problem. -</dd> -<dt><i>line</i></dt> -<dd> -The offending source line. -</dd> -</dl> -<a NAME="NannyNag.get_line" ID="NannyNag.get_line"></a> -<h4>NannyNag.get_line</h4> -<b>get_line</b>(<i></i>) - -<p> - Public method to retrieve the offending line. -</p> -<dl> -<dt>Returns:</dt> -<dd> -The line of code (string) -</dd> -</dl> -<a NAME="NannyNag.get_lineno" ID="NannyNag.get_lineno"></a> -<h4>NannyNag.get_lineno</h4> -<b>get_lineno</b>(<i></i>) - -<p> - Public method to retrieve the line number. -</p> -<dl> -<dt>Returns:</dt> -<dd> -The line number (integer) -</dd> -</dl> -<a NAME="NannyNag.get_msg" ID="NannyNag.get_msg"></a> -<h4>NannyNag.get_msg</h4> -<b>get_msg</b>(<i></i>) - -<p> - Public method to retrieve the message. -</p> -<dl> -<dt>Returns:</dt> -<dd> -The error message (string) -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="Whitespace" ID="Whitespace"></a> -<h2>Whitespace</h2> - -<p> - Class implementing the whitespace checker. -</p> -<h3>Derived from</h3> -object -<h3>Class Attributes</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Class Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Methods</h3> - -<table> - -<tr> -<td><a href="#Whitespace.__init__">Whitespace</a></td> -<td>Constructor</td> -</tr> -<tr> -<td><a href="#Whitespace.equal">equal</a></td> -<td>Public method to compare the indentation levels of two Whitespace objects for equality.</td> -</tr> -<tr> -<td><a href="#Whitespace.indent_level">indent_level</a></td> -<td>Public method to determine the indentation level.</td> -</tr> -<tr> -<td><a href="#Whitespace.less">less</a></td> -<td>Public method to compare the indentation level against another Whitespace objects to be smaller.</td> -</tr> -<tr> -<td><a href="#Whitespace.longest_run_of_spaces">longest_run_of_spaces</a></td> -<td>Public method to calculate the length of longest contiguous run of spaces.</td> -</tr> -<tr> -<td><a href="#Whitespace.not_equal_witness">not_equal_witness</a></td> -<td>Public method to calculate a tuple of witnessing tab size.</td> -</tr> -<tr> -<td><a href="#Whitespace.not_less_witness">not_less_witness</a></td> -<td>Public method to calculate a tuple of witnessing tab size.</td> -</tr> -</table> -<h3>Static Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> - -<a NAME="Whitespace.__init__" ID="Whitespace.__init__"></a> -<h4>Whitespace (Constructor)</h4> -<b>Whitespace</b>(<i>ws</i>) - -<p> - Constructor -</p> -<dl> - -<dt><i>ws</i></dt> -<dd> -The string to be checked. -</dd> -</dl> -<a NAME="Whitespace.equal" ID="Whitespace.equal"></a> -<h4>Whitespace.equal</h4> -<b>equal</b>(<i>other</i>) - -<p> - Public method to compare the indentation levels of two Whitespace - objects for equality. -</p> -<dl> - -<dt><i>other</i></dt> -<dd> -Whitespace object to compare against. -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -True, if we compare equal against the other Whitespace object. -</dd> -</dl> -<a NAME="Whitespace.indent_level" ID="Whitespace.indent_level"></a> -<h4>Whitespace.indent_level</h4> -<b>indent_level</b>(<i>tabsize</i>) - -<p> - Public method to determine the indentation level. -</p> -<dl> - -<dt><i>tabsize</i></dt> -<dd> -The length of a tab stop. (integer) -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -indentation level (integer) -</dd> -</dl> -<a NAME="Whitespace.less" ID="Whitespace.less"></a> -<h4>Whitespace.less</h4> -<b>less</b>(<i>other</i>) - -<p> - Public method to compare the indentation level against another - Whitespace objects to be smaller. -</p> -<dl> - -<dt><i>other</i></dt> -<dd> -Whitespace object to compare against. -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -True, if we compare less against the other Whitespace object. -</dd> -</dl> -<a NAME="Whitespace.longest_run_of_spaces" ID="Whitespace.longest_run_of_spaces"></a> -<h4>Whitespace.longest_run_of_spaces</h4> -<b>longest_run_of_spaces</b>(<i></i>) - -<p> - Public method to calculate the length of longest contiguous run of - spaces. -</p> -<dl> -<dt>Returns:</dt> -<dd> -The length of longest contiguous run of spaces (whether or not - preceding a tab) -</dd> -</dl> -<a NAME="Whitespace.not_equal_witness" ID="Whitespace.not_equal_witness"></a> -<h4>Whitespace.not_equal_witness</h4> -<b>not_equal_witness</b>(<i>other</i>) - -<p> - Public method to calculate a tuple of witnessing tab size. -</p> -<p> - Intended to be used after not self.equal(other) is known, in which - case it will return at least one witnessing tab size. -</p> -<dl> - -<dt><i>other</i></dt> -<dd> -Whitespace object to calculate against. -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -A list of tuples (ts, i1, i2) such that - i1 == self.indent_level(ts) != other.indent_level(ts) == i2. -</dd> -</dl> -<a NAME="Whitespace.not_less_witness" ID="Whitespace.not_less_witness"></a> -<h4>Whitespace.not_less_witness</h4> -<b>not_less_witness</b>(<i>other</i>) - -<p> - Public method to calculate a tuple of witnessing tab size. -</p> -<p> - Intended to be used after not self.less(other is known, in which - case it will return at least one witnessing tab size. -</p> -<dl> - -<dt><i>other</i></dt> -<dd> -Whitespace object to calculate against. -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -A list of tuples (ts, i1, i2) such that - i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="__check" ID="__check"></a> -<h2>__check</h2> -<b>__check</b>(<i>file, text=""</i>) - -<p> - Private function to check one Python source file for whitespace related - problems. -</p> -<dl> - -<dt><i>file</i></dt> -<dd> -source filename (string) -</dd> -<dt><i>text</i></dt> -<dd> -source text (string) -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -A tuple indicating status (True = an error was found), the - filename, the linenumber and the error message - (boolean, string, string). The values are only - valid, if the status is True. -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="batchCheck" ID="batchCheck"></a> -<h2>batchCheck</h2> -<b>batchCheck</b>(<i>argumentsList, send, fx, cancelled, maxProcesses=0</i>) - -<p> - Module function to check a batch of files for whitespace related problems. -</p> -<dl> - -<dt><i>argumentsList</i> (list)</dt> -<dd> -list of arguments tuples as given for check -</dd> -<dt><i>send</i> (func)</dt> -<dd> -reference to send function -</dd> -<dt><i>fx</i> (str)</dt> -<dd> -registered service name -</dd> -<dt><i>cancelled</i> (func)</dt> -<dd> -reference to function checking for a cancellation -</dd> -<dt><i>maxProcesses</i> (int)</dt> -<dd> -number of processes to be used -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="check" ID="check"></a> -<h2>check</h2> -<b>check</b>(<i>file, text=""</i>) - -<p> - Private function to check one Python source file for whitespace related - problems. -</p> -<dl> - -<dt><i>file</i></dt> -<dd> -source filename (string) -</dd> -<dt><i>text</i></dt> -<dd> -source text (string) -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -A tuple indicating status (True = an error was found), the - filename, the linenumber and the error message - (boolean, string, string, string). The values are only - valid, if the status is True. -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="format_witnesses" ID="format_witnesses"></a> -<h2>format_witnesses</h2> -<b>format_witnesses</b>(<i>w</i>) - -<p> - Function to format the witnesses as a readable string. -</p> -<dl> - -<dt><i>w</i></dt> -<dd> -A list of witnesses -</dd> -</dl> -<dl> -<dt>Returns:</dt> -<dd> -A formated string of the witnesses. -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="initBatchService" ID="initBatchService"></a> -<h2>initBatchService</h2> -<b>initBatchService</b>(<i></i>) - -<p> - Initialize the batch service and return the entry point. -</p> -<dl> -<dt>Returns:</dt> -<dd> -the entry point for the background client (function) -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="initService" ID="initService"></a> -<h2>initService</h2> -<b>initService</b>(<i></i>) - -<p> - Initialize the service and return the entry point. -</p> -<dl> -<dt>Returns:</dt> -<dd> -the entry point for the background client (function) -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="process_tokens" ID="process_tokens"></a> -<h2>process_tokens</h2> -<b>process_tokens</b>(<i>tokens</i>) - -<p> - Function processing all tokens generated by a tokenizer run. -</p> -<dl> - -<dt><i>tokens</i></dt> -<dd> -list of tokens -</dd> -</dl> -<dl> - -<dt>Raises <b>NannyNag</b>:</dt> -<dd> -raised to indicate an indentation error -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -<hr /> -<a NAME="worker" ID="worker"></a> -<h2>worker</h2> -<b>worker</b>(<i>inputQueue, outputQueue</i>) - -<p> - Module function acting as the parallel worker for the style check. -</p> -<dl> - -<dt><i>inputQueue</i></dt> -<dd> -input queue (multiprocessing.Queue) -</dd> -<dt><i>outputQueue</i></dt> -<dd> -output queue (multiprocessing.Queue) -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -</body></html> \ No newline at end of file
--- a/eric6/Documentation/Source/eric6.Plugins.CheckerPlugins.Tabnanny.TabnannyDialog.html Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,363 +0,0 @@ -<!DOCTYPE html> -<html><head> -<title>eric6.Plugins.CheckerPlugins.Tabnanny.TabnannyDialog</title> -<meta charset="UTF-8"> -<style> -body { - background: #EDECE6; - margin: 0em 1em 10em 1em; - color: black; -} - -h1 { color: white; background: #85774A; } -h2 { color: white; background: #85774A; } -h3 { color: white; background: #9D936E; } -h4 { color: white; background: #9D936E; } - -a { color: #BA6D36; } - -</style> -</head> -<body> -<a NAME="top" ID="top"></a> -<h1>eric6.Plugins.CheckerPlugins.Tabnanny.TabnannyDialog</h1> - -<p> -Module implementing a dialog to show the output of the tabnanny command -process. -</p> -<h3>Global Attributes</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Classes</h3> - -<table> - -<tr> -<td><a href="#TabnannyDialog">TabnannyDialog</a></td> -<td>Class implementing a dialog to show the results of the tabnanny check run.</td> -</tr> -</table> -<h3>Functions</h3> - -<table> -<tr><td>None</td></tr> -</table> -<hr /> -<hr /> -<a NAME="TabnannyDialog" ID="TabnannyDialog"></a> -<h2>TabnannyDialog</h2> - -<p> - Class implementing a dialog to show the results of the tabnanny check run. -</p> -<h3>Derived from</h3> -QDialog, Ui_TabnannyDialog -<h3>Class Attributes</h3> - -<table> -<tr><td>filenameRole</td></tr> -</table> -<h3>Class Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Methods</h3> - -<table> - -<tr> -<td><a href="#TabnannyDialog.__init__">TabnannyDialog</a></td> -<td>Constructor</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.__batchFinished">__batchFinished</a></td> -<td>Private slot handling the completion of a batch job.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.__createErrorItem">__createErrorItem</a></td> -<td>Private slot to create a new error item in the result list.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.__createResultItem">__createResultItem</a></td> -<td>Private method to create an entry in the result list.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.__finish">__finish</a></td> -<td>Private slot called when the action or the user pressed the button.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.__processError">__processError</a></td> -<td>Private slot to process an error indication from the service.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.__processResult">__processResult</a></td> -<td>Private slot called after perfoming a style check on one file.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.__resort">__resort</a></td> -<td>Private method to resort the tree.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.check">check</a></td> -<td>Public method to start an indentation check for one file.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.checkBatch">checkBatch</a></td> -<td>Public method to start an indentation check batch job.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.on_buttonBox_clicked">on_buttonBox_clicked</a></td> -<td>Private slot called by a button of the button box clicked.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.on_resultList_itemActivated">on_resultList_itemActivated</a></td> -<td>Private slot to handle the activation of an item.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.on_startButton_clicked">on_startButton_clicked</a></td> -<td>Private slot to start a code metrics run.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.prepare">prepare</a></td> -<td>Public method to prepare the dialog with a list of filenames.</td> -</tr> -<tr> -<td><a href="#TabnannyDialog.start">start</a></td> -<td>Public slot to start the tabnanny check.</td> -</tr> -</table> -<h3>Static Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> - -<a NAME="TabnannyDialog.__init__" ID="TabnannyDialog.__init__"></a> -<h4>TabnannyDialog (Constructor)</h4> -<b>TabnannyDialog</b>(<i>indentCheckService, parent=None</i>) - -<p> - Constructor -</p> -<dl> - -<dt><i>indentCheckService</i></dt> -<dd> -reference to the service (IndentCheckService) -</dd> -<dt><i>parent</i></dt> -<dd> -The parent widget (QWidget). -</dd> -</dl> -<a NAME="TabnannyDialog.__batchFinished" ID="TabnannyDialog.__batchFinished"></a> -<h4>TabnannyDialog.__batchFinished</h4> -<b>__batchFinished</b>(<i></i>) - -<p> - Private slot handling the completion of a batch job. -</p> -<a NAME="TabnannyDialog.__createErrorItem" ID="TabnannyDialog.__createErrorItem"></a> -<h4>TabnannyDialog.__createErrorItem</h4> -<b>__createErrorItem</b>(<i>filename, message</i>) - -<p> - Private slot to create a new error item in the result list. -</p> -<dl> - -<dt><i>filename</i> (str)</dt> -<dd> -name of the file -</dd> -<dt><i>message</i> (str)</dt> -<dd> -error message -</dd> -</dl> -<a NAME="TabnannyDialog.__createResultItem" ID="TabnannyDialog.__createResultItem"></a> -<h4>TabnannyDialog.__createResultItem</h4> -<b>__createResultItem</b>(<i>filename, line, sourcecode</i>) - -<p> - Private method to create an entry in the result list. -</p> -<dl> - -<dt><i>filename</i></dt> -<dd> -filename of file (string) -</dd> -<dt><i>line</i></dt> -<dd> -linenumber of faulty source (integer or string) -</dd> -<dt><i>sourcecode</i></dt> -<dd> -faulty line of code (string) -</dd> -</dl> -<a NAME="TabnannyDialog.__finish" ID="TabnannyDialog.__finish"></a> -<h4>TabnannyDialog.__finish</h4> -<b>__finish</b>(<i></i>) - -<p> - Private slot called when the action or the user pressed the button. -</p> -<a NAME="TabnannyDialog.__processError" ID="TabnannyDialog.__processError"></a> -<h4>TabnannyDialog.__processError</h4> -<b>__processError</b>(<i>fn, msg</i>) - -<p> - Private slot to process an error indication from the service. -</p> -<dl> - -<dt><i>fn</i> (str)</dt> -<dd> -filename of the file -</dd> -<dt><i>msg</i> (str)</dt> -<dd> -error message -</dd> -</dl> -<a NAME="TabnannyDialog.__processResult" ID="TabnannyDialog.__processResult"></a> -<h4>TabnannyDialog.__processResult</h4> -<b>__processResult</b>(<i>fn, nok, line, error</i>) - -<p> - Private slot called after perfoming a style check on one file. -</p> -<dl> - -<dt><i>fn</i></dt> -<dd> -filename of the just checked file (str) -</dd> -<dt><i>nok</i></dt> -<dd> -flag if a problem was found (bool) -</dd> -<dt><i>line</i></dt> -<dd> -line number (str) -</dd> -<dt><i>error</i></dt> -<dd> -text of the problem (str) -</dd> -</dl> -<a NAME="TabnannyDialog.__resort" ID="TabnannyDialog.__resort"></a> -<h4>TabnannyDialog.__resort</h4> -<b>__resort</b>(<i></i>) - -<p> - Private method to resort the tree. -</p> -<a NAME="TabnannyDialog.check" ID="TabnannyDialog.check"></a> -<h4>TabnannyDialog.check</h4> -<b>check</b>(<i>codestring=''</i>) - -<p> - Public method to start an indentation check for one file. -</p> -<p> - The results are reported to the __processResult slot. -</p> -<dl> - -<dt><i>codestring=</i></dt> -<dd> -optional sourcestring (str) -</dd> -</dl> -<a NAME="TabnannyDialog.checkBatch" ID="TabnannyDialog.checkBatch"></a> -<h4>TabnannyDialog.checkBatch</h4> -<b>checkBatch</b>(<i></i>) - -<p> - Public method to start an indentation check batch job. -</p> -<p> - The results are reported to the __processResult slot. -</p> -<a NAME="TabnannyDialog.on_buttonBox_clicked" ID="TabnannyDialog.on_buttonBox_clicked"></a> -<h4>TabnannyDialog.on_buttonBox_clicked</h4> -<b>on_buttonBox_clicked</b>(<i>button</i>) - -<p> - Private slot called by a button of the button box clicked. -</p> -<dl> - -<dt><i>button</i></dt> -<dd> -button that was clicked (QAbstractButton) -</dd> -</dl> -<a NAME="TabnannyDialog.on_resultList_itemActivated" ID="TabnannyDialog.on_resultList_itemActivated"></a> -<h4>TabnannyDialog.on_resultList_itemActivated</h4> -<b>on_resultList_itemActivated</b>(<i>itm, col</i>) - -<p> - Private slot to handle the activation of an item. -</p> -<dl> - -<dt><i>itm</i></dt> -<dd> -reference to the activated item (QTreeWidgetItem) -</dd> -<dt><i>col</i></dt> -<dd> -column the item was activated in (integer) -</dd> -</dl> -<a NAME="TabnannyDialog.on_startButton_clicked" ID="TabnannyDialog.on_startButton_clicked"></a> -<h4>TabnannyDialog.on_startButton_clicked</h4> -<b>on_startButton_clicked</b>(<i></i>) - -<p> - Private slot to start a code metrics run. -</p> -<a NAME="TabnannyDialog.prepare" ID="TabnannyDialog.prepare"></a> -<h4>TabnannyDialog.prepare</h4> -<b>prepare</b>(<i>fileList, project</i>) - -<p> - Public method to prepare the dialog with a list of filenames. -</p> -<dl> - -<dt><i>fileList</i></dt> -<dd> -list of filenames (list of strings) -</dd> -<dt><i>project</i></dt> -<dd> -reference to the project object (Project) -</dd> -</dl> -<a NAME="TabnannyDialog.start" ID="TabnannyDialog.start"></a> -<h4>TabnannyDialog.start</h4> -<b>start</b>(<i>fn</i>) - -<p> - Public slot to start the tabnanny check. -</p> -<dl> - -<dt><i>fn</i></dt> -<dd> -File or list of files or directory to be checked - (string or list of strings) -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -</body></html> \ No newline at end of file
--- a/eric6/Documentation/Source/eric6.Plugins.PluginTabnanny.html Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,430 +0,0 @@ -<!DOCTYPE html> -<html><head> -<title>eric6.Plugins.PluginTabnanny</title> -<meta charset="UTF-8"> -<style> -body { - background: #EDECE6; - margin: 0em 1em 10em 1em; - color: black; -} - -h1 { color: white; background: #85774A; } -h2 { color: white; background: #85774A; } -h3 { color: white; background: #9D936E; } -h4 { color: white; background: #9D936E; } - -a { color: #BA6D36; } - -</style> -</head> -<body> -<a NAME="top" ID="top"></a> -<h1>eric6.Plugins.PluginTabnanny</h1> - -<p> -Module implementing the Tabnanny plugin. -</p> -<h3>Global Attributes</h3> - -<table> -<tr><td>author</td></tr><tr><td>autoactivate</td></tr><tr><td>className</td></tr><tr><td>deactivateable</td></tr><tr><td>error</td></tr><tr><td>longDescription</td></tr><tr><td>name</td></tr><tr><td>packageName</td></tr><tr><td>pyqtApi</td></tr><tr><td>shortDescription</td></tr><tr><td>version</td></tr> -</table> -<h3>Classes</h3> - -<table> - -<tr> -<td><a href="#TabnannyPlugin">TabnannyPlugin</a></td> -<td>Class implementing the Tabnanny plugin.</td> -</tr> -</table> -<h3>Functions</h3> - -<table> -<tr><td>None</td></tr> -</table> -<hr /> -<hr /> -<a NAME="TabnannyPlugin" ID="TabnannyPlugin"></a> -<h2>TabnannyPlugin</h2> - -<p> - Class implementing the Tabnanny plugin. -</p> -<h3>Signals</h3> -<dl> - -<dt>batchFinished()</dt> -<dd> -emitted when a style check batch is done -</dd> -<dt>error(str, str)</dt> -<dd> -emitted in case of an error -</dd> -<dt>indentChecked(str, bool, str, str)</dt> -<dd> -emitted when the indent - check was done. -</dd> -</dl> -<h3>Derived from</h3> -QObject -<h3>Class Attributes</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Class Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> -<h3>Methods</h3> - -<table> - -<tr> -<td><a href="#TabnannyPlugin.__init__">TabnannyPlugin</a></td> -<td>Constructor</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__editorClosed">__editorClosed</a></td> -<td>Private slot called, when an editor was closed.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__editorOpened">__editorOpened</a></td> -<td>Private slot called, when a new editor was opened.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__editorShowMenu">__editorShowMenu</a></td> -<td>Private slot called, when the the editor context menu or a submenu is about to be shown.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__editorTabnanny">__editorTabnanny</a></td> -<td>Private slot to handle the tabnanny context menu action of the editors.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__initialize">__initialize</a></td> -<td>Private slot to (re)initialize the plugin.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__projectBrowserShowMenu">__projectBrowserShowMenu</a></td> -<td>Private slot called, when the the project browser context menu or a submenu is about to be shown.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__projectBrowserTabnanny">__projectBrowserTabnanny</a></td> -<td>Private method to handle the tabnanny context menu action of the project sources browser.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__projectShowMenu">__projectShowMenu</a></td> -<td>Private slot called, when the the project menu or a submenu is about to be shown.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__projectTabnanny">__projectTabnanny</a></td> -<td>Private slot used to check the project files for bad indentations.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.__serviceError">__serviceError</a></td> -<td>Private slot handling service errors.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.activate">activate</a></td> -<td>Public method to activate this plugin.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.batchJobDone">batchJobDone</a></td> -<td>Public slot handling the completion of a batch job.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.cancelIndentBatchCheck">cancelIndentBatchCheck</a></td> -<td>Public method to cancel all batch jobs.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.deactivate">deactivate</a></td> -<td>Public method to deactivate this plugin.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.indentBatchCheck">indentBatchCheck</a></td> -<td>Public method to prepare an indentation check on multiple Python source files.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.indentCheck">indentCheck</a></td> -<td>Public method to prepare an indentation check on one Python source file.</td> -</tr> -<tr> -<td><a href="#TabnannyPlugin.serviceErrorPy3">serviceErrorPy3</a></td> -<td>Public slot handling service errors for Python 3.</td> -</tr> -</table> -<h3>Static Methods</h3> - -<table> -<tr><td>None</td></tr> -</table> - -<a NAME="TabnannyPlugin.__init__" ID="TabnannyPlugin.__init__"></a> -<h4>TabnannyPlugin (Constructor)</h4> -<b>TabnannyPlugin</b>(<i>ui</i>) - -<p> - Constructor -</p> -<dl> - -<dt><i>ui</i></dt> -<dd> -reference to the user interface object (UI.UserInterface) -</dd> -</dl> -<a NAME="TabnannyPlugin.__editorClosed" ID="TabnannyPlugin.__editorClosed"></a> -<h4>TabnannyPlugin.__editorClosed</h4> -<b>__editorClosed</b>(<i>editor</i>) - -<p> - Private slot called, when an editor was closed. -</p> -<dl> - -<dt><i>editor</i></dt> -<dd> -reference to the editor (QScintilla.Editor) -</dd> -</dl> -<a NAME="TabnannyPlugin.__editorOpened" ID="TabnannyPlugin.__editorOpened"></a> -<h4>TabnannyPlugin.__editorOpened</h4> -<b>__editorOpened</b>(<i>editor</i>) - -<p> - Private slot called, when a new editor was opened. -</p> -<dl> - -<dt><i>editor</i></dt> -<dd> -reference to the new editor (QScintilla.Editor) -</dd> -</dl> -<a NAME="TabnannyPlugin.__editorShowMenu" ID="TabnannyPlugin.__editorShowMenu"></a> -<h4>TabnannyPlugin.__editorShowMenu</h4> -<b>__editorShowMenu</b>(<i>menuName, menu, editor</i>) - -<p> - Private slot called, when the the editor context menu or a submenu is - about to be shown. -</p> -<dl> - -<dt><i>menuName</i></dt> -<dd> -name of the menu to be shown (string) -</dd> -<dt><i>menu</i></dt> -<dd> -reference to the menu (QMenu) -</dd> -<dt><i>editor</i></dt> -<dd> -reference to the editor -</dd> -</dl> -<a NAME="TabnannyPlugin.__editorTabnanny" ID="TabnannyPlugin.__editorTabnanny"></a> -<h4>TabnannyPlugin.__editorTabnanny</h4> -<b>__editorTabnanny</b>(<i></i>) - -<p> - Private slot to handle the tabnanny context menu action of the editors. -</p> -<a NAME="TabnannyPlugin.__initialize" ID="TabnannyPlugin.__initialize"></a> -<h4>TabnannyPlugin.__initialize</h4> -<b>__initialize</b>(<i></i>) - -<p> - Private slot to (re)initialize the plugin. -</p> -<a NAME="TabnannyPlugin.__projectBrowserShowMenu" ID="TabnannyPlugin.__projectBrowserShowMenu"></a> -<h4>TabnannyPlugin.__projectBrowserShowMenu</h4> -<b>__projectBrowserShowMenu</b>(<i>menuName, menu</i>) - -<p> - Private slot called, when the the project browser context menu or a - submenu is about to be shown. -</p> -<dl> - -<dt><i>menuName</i></dt> -<dd> -name of the menu to be shown (string) -</dd> -<dt><i>menu</i></dt> -<dd> -reference to the menu (QMenu) -</dd> -</dl> -<a NAME="TabnannyPlugin.__projectBrowserTabnanny" ID="TabnannyPlugin.__projectBrowserTabnanny"></a> -<h4>TabnannyPlugin.__projectBrowserTabnanny</h4> -<b>__projectBrowserTabnanny</b>(<i></i>) - -<p> - Private method to handle the tabnanny context menu action of the - project sources browser. -</p> -<a NAME="TabnannyPlugin.__projectShowMenu" ID="TabnannyPlugin.__projectShowMenu"></a> -<h4>TabnannyPlugin.__projectShowMenu</h4> -<b>__projectShowMenu</b>(<i>menuName, menu</i>) - -<p> - Private slot called, when the the project menu or a submenu is - about to be shown. -</p> -<dl> - -<dt><i>menuName</i></dt> -<dd> -name of the menu to be shown (string) -</dd> -<dt><i>menu</i></dt> -<dd> -reference to the menu (QMenu) -</dd> -</dl> -<a NAME="TabnannyPlugin.__projectTabnanny" ID="TabnannyPlugin.__projectTabnanny"></a> -<h4>TabnannyPlugin.__projectTabnanny</h4> -<b>__projectTabnanny</b>(<i></i>) - -<p> - Private slot used to check the project files for bad indentations. -</p> -<a NAME="TabnannyPlugin.__serviceError" ID="TabnannyPlugin.__serviceError"></a> -<h4>TabnannyPlugin.__serviceError</h4> -<b>__serviceError</b>(<i>fn, msg</i>) - -<p> - Private slot handling service errors. -</p> -<dl> - -<dt><i>fn</i></dt> -<dd> -file name (string) -</dd> -<dt><i>msg</i></dt> -<dd> -message text (string) -</dd> -</dl> -<a NAME="TabnannyPlugin.activate" ID="TabnannyPlugin.activate"></a> -<h4>TabnannyPlugin.activate</h4> -<b>activate</b>(<i></i>) - -<p> - Public method to activate this plugin. -</p> -<dl> -<dt>Returns:</dt> -<dd> -tuple of None and activation status (boolean) -</dd> -</dl> -<a NAME="TabnannyPlugin.batchJobDone" ID="TabnannyPlugin.batchJobDone"></a> -<h4>TabnannyPlugin.batchJobDone</h4> -<b>batchJobDone</b>(<i>fx, lang</i>) - -<p> - Public slot handling the completion of a batch job. -</p> -<dl> - -<dt><i>fx</i></dt> -<dd> -service name (string) -</dd> -<dt><i>lang</i></dt> -<dd> -language (string) -</dd> -</dl> -<a NAME="TabnannyPlugin.cancelIndentBatchCheck" ID="TabnannyPlugin.cancelIndentBatchCheck"></a> -<h4>TabnannyPlugin.cancelIndentBatchCheck</h4> -<b>cancelIndentBatchCheck</b>(<i></i>) - -<p> - Public method to cancel all batch jobs. -</p> -<a NAME="TabnannyPlugin.deactivate" ID="TabnannyPlugin.deactivate"></a> -<h4>TabnannyPlugin.deactivate</h4> -<b>deactivate</b>(<i></i>) - -<p> - Public method to deactivate this plugin. -</p> -<a NAME="TabnannyPlugin.indentBatchCheck" ID="TabnannyPlugin.indentBatchCheck"></a> -<h4>TabnannyPlugin.indentBatchCheck</h4> -<b>indentBatchCheck</b>(<i>argumentsList</i>) - -<p> - Public method to prepare an indentation check on multiple Python - source files. -</p> -<dl> - -<dt><i>argumentsList</i></dt> -<dd> -list of arguments tuples with each tuple - containing filename and source (string, string) -</dd> -</dl> -<a NAME="TabnannyPlugin.indentCheck" ID="TabnannyPlugin.indentCheck"></a> -<h4>TabnannyPlugin.indentCheck</h4> -<b>indentCheck</b>(<i>lang, filename, source</i>) - -<p> - Public method to prepare an indentation check on one Python source - file. -</p> -<dl> - -<dt><i>lang</i></dt> -<dd> -language of the file or None to determine by internal - algorithm (str or None) -</dd> -<dt><i>filename</i></dt> -<dd> -source filename (string) -</dd> -<dt><i>source</i></dt> -<dd> -string containing the code to check (string) -</dd> -</dl> -<a NAME="TabnannyPlugin.serviceErrorPy3" ID="TabnannyPlugin.serviceErrorPy3"></a> -<h4>TabnannyPlugin.serviceErrorPy3</h4> -<b>serviceErrorPy3</b>(<i>fx, lang, fn, msg</i>) - -<p> - Public slot handling service errors for Python 3. -</p> -<dl> - -<dt><i>fx</i></dt> -<dd> -service name (string) -</dd> -<dt><i>lang</i></dt> -<dd> -language (string) -</dd> -<dt><i>fn</i></dt> -<dd> -file name (string) -</dd> -<dt><i>msg</i></dt> -<dd> -message text (string) -</dd> -</dl> -<div align="right"><a href="#top">Up</a></div> -<hr /> -</body></html> \ No newline at end of file
--- a/eric6/Plugins/CheckerPlugins/Tabnanny/Tabnanny.py Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,524 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -The Tab Nanny despises ambiguous indentation. She knows no mercy. - -tabnanny -- Detection of ambiguous indentation - -For the time being this module is intended to be called as a script. -However it is possible to import it into an IDE and use the function -check() described below. - -Warning: The API provided by this module is likely to change in future -releases; such changes may not be backward compatible. - -This is a modified version to make the original tabnanny better suitable -for being called from within the eric6 IDE. - -@exception ValueError The tokenize module is too old. -""" - -# Released to the public domain, by Tim Peters, 15 April 1998. - -# XXX Note: this is now a standard library module. -# XXX The API needs to undergo changes however; the current code is too -# XXX script-like. This will be addressed later. - -# -# This is a modified version to make the original tabnanny better suitable -# for being called from within the eric6 IDE. The modifications are as -# follows: -# -# - there is no main function anymore -# - check function has been modified to only accept a filename and return -# a tuple indicating status (1 = an error was found), the filename, the -# linenumber and the error message (boolean, string, string, string). The -# values are only valid, if the status equals 1. -# -# Mofifications Copyright (c) 2003-2020 Detlev Offenbach -# <detlev@die-offenbachs.de> -# - -__version__ = "6_eric" - -import tokenize -try: - import StringIO as io - import Queue as queue -except (ImportError): - import io # __IGNORE_WARNING__ - import queue - -import multiprocessing - - -if not hasattr(tokenize, 'NL'): - raise ValueError("tokenize.NL doesn't exist -- tokenize module too old") - -__all__ = ["check", "NannyNag", "process_tokens"] - - -def initService(): - """ - Initialize the service and return the entry point. - - @return the entry point for the background client (function) - """ - return check - - -def initBatchService(): - """ - Initialize the batch service and return the entry point. - - @return the entry point for the background client (function) - """ - return batchCheck - - -class NannyNag(Exception): - """ - Class implementing an exception for indentation issues. - - Raised by tokeneater() if detecting an ambiguous indent. - Captured and handled in check(). - """ - def __init__(self, lineno, msg, line): - """ - Constructor - - @param lineno Line number of the ambiguous indent. - @param msg Descriptive message assigned to this problem. - @param line The offending source line. - """ - self.lineno, self.msg, self.line = lineno, msg, line - - def get_lineno(self): - """ - Public method to retrieve the line number. - - @return The line number (integer) - """ - return self.lineno - - def get_msg(self): - """ - Public method to retrieve the message. - - @return The error message (string) - """ - return self.msg - - def get_line(self): - """ - Public method to retrieve the offending line. - - @return The line of code (string) - """ - return self.line - - -def check(file, text=""): - """ - Private function to check one Python source file for whitespace related - problems. - - @param file source filename (string) - @param text source text (string) - @return A tuple indicating status (True = an error was found), the - filename, the linenumber and the error message - (boolean, string, string, string). The values are only - valid, if the status is True. - """ - return __check(file, text) - - -def batchCheck(argumentsList, send, fx, cancelled, maxProcesses=0): - """ - Module function to check a batch of files for whitespace related problems. - - @param argumentsList list of arguments tuples as given for check - @type list - @param send reference to send function - @type func - @param fx registered service name - @type str - @param cancelled reference to function checking for a cancellation - @type func - @param maxProcesses number of processes to be used - @type int - """ - if maxProcesses == 0: - # determine based on CPU count - try: - NumberOfProcesses = multiprocessing.cpu_count() - if NumberOfProcesses >= 1: - NumberOfProcesses -= 1 - except NotImplementedError: - NumberOfProcesses = 1 - else: - NumberOfProcesses = maxProcesses - - # Create queues - taskQueue = multiprocessing.Queue() - doneQueue = multiprocessing.Queue() - - # Submit tasks (initially two time number of processes - initialTasks = 2 * NumberOfProcesses - for task in argumentsList[:initialTasks]: - taskQueue.put(task) - - # Start worker processes - for _ in range(NumberOfProcesses): - multiprocessing.Process( - target=worker, args=(taskQueue, doneQueue) - ).start() - - # Get and send results - endIndex = len(argumentsList) - initialTasks - for i in range(len(argumentsList)): - resultSent = False - wasCancelled = False - - while not resultSent: - try: - # get result (waiting max. 3 seconds and send it to frontend - filename, result = doneQueue.get() - send(fx, filename, result) - resultSent = True - except queue.Empty: - # ignore empty queue, just carry on - if cancelled(): - wasCancelled = True - break - - if wasCancelled or cancelled(): - # just exit the loop ignoring the results of queued tasks - break - - if i < endIndex: - taskQueue.put(argumentsList[i + initialTasks]) - - # Tell child processes to stop - for _ in range(NumberOfProcesses): - taskQueue.put('STOP') - - -def worker(inputQueue, outputQueue): - """ - Module function acting as the parallel worker for the style check. - - @param inputQueue input queue (multiprocessing.Queue) - @param outputQueue output queue (multiprocessing.Queue) - """ - for filename, source in iter(inputQueue.get, 'STOP'): - result = __check(filename, source) - outputQueue.put((filename, result)) - - -def __check(file, text=""): - """ - Private function to check one Python source file for whitespace related - problems. - - @param file source filename (string) - @param text source text (string) - @return A tuple indicating status (True = an error was found), the - filename, the linenumber and the error message - (boolean, string, string). The values are only - valid, if the status is True. - """ - global indents, check_equal - indents = [Whitespace("")] - check_equal = 0 - if not text: - return (True, "1", "Error: source code missing.") - - source = io.StringIO(text) - try: - process_tokens(tokenize.generate_tokens(source.readline)) - - except tokenize.TokenError as msg: - return (True, "1", "Token Error: {0}".format(str(msg))) - - except IndentationError as err: - return (True, str(err.lineno), - "Indentation Error: {0}".format(str(err.msg))) - - except NannyNag as nag: - badline = nag.get_lineno() - line = nag.get_line() - return (True, str(badline), line) - - except Exception as err: - return (True, "1", "Unspecific Error: {0}".format(str(err))) - - return (False, "", "") - - -class Whitespace(object): - """ - Class implementing the whitespace checker. - """ - # the characters used for space and tab - S, T = ' \t' - - # members: - # raw - # the original string - # n - # the number of leading whitespace characters in raw - # nt - # the number of tabs in raw[:n] - # norm - # the normal form as a pair (count, trailing), where: - # count - # a tuple such that raw[:n] contains count[i] - # instances of S * i + T - # trailing - # the number of trailing spaces in raw[:n] - # It's A Theorem that m.indent_level(t) == - # n.indent_level(t) for all t >= 1 iff m.norm == n.norm. - # is_simple - # true iff raw[:n] is of the form (T*)(S*) - - def __init__(self, ws): - """ - Constructor - - @param ws The string to be checked. - """ - self.raw = ws - S, T = Whitespace.S, Whitespace.T - count = [] - b = n = nt = 0 - for ch in self.raw: - if ch == S: - n = n + 1 - b = b + 1 - elif ch == T: - n = n + 1 - nt = nt + 1 - if b >= len(count): - count = count + [0] * (b - len(count) + 1) - count[b] = count[b] + 1 - b = 0 - else: - break - self.n = n - self.nt = nt - self.norm = tuple(count), b - self.is_simple = len(count) <= 1 - - # return length of longest contiguous run of spaces (whether or not - # preceding a tab) - def longest_run_of_spaces(self): - """ - Public method to calculate the length of longest contiguous run of - spaces. - - @return The length of longest contiguous run of spaces (whether or not - preceding a tab) - """ - count, trailing = self.norm - return max(len(count) - 1, trailing) - - def indent_level(self, tabsize): - """ - Public method to determine the indentation level. - - @param tabsize The length of a tab stop. (integer) - @return indentation level (integer) - """ - ## count, il = self.norm - ## for i in range(len(count)): - ## if count[i]: - ## il = il + (i/tabsize + 1)*tabsize * count[i] - ## return il - - ## quicker: - ## il = trailing + sum (i/ts + 1)*ts*count[i] = - ## trailing + ts * sum (i/ts + 1)*count[i] = - ## trailing + ts * sum i/ts*count[i] + count[i] = - ## trailing + ts * [(sum i/ts*count[i]) + (sum count[i])] = - ## trailing + ts * [(sum i/ts*count[i]) + num_tabs] - ## and note that i/ts*count[i] is 0 when i < ts - - count, trailing = self.norm - il = 0 - for i in range(tabsize, len(count)): - il = il + i / tabsize * count[i] - return trailing + tabsize * (il + self.nt) - - # return true iff self.indent_level(t) == other.indent_level(t) - # for all t >= 1 - def equal(self, other): - """ - Public method to compare the indentation levels of two Whitespace - objects for equality. - - @param other Whitespace object to compare against. - @return True, if we compare equal against the other Whitespace object. - """ - return self.norm == other.norm - - # return a list of tuples (ts, i1, i2) such that - # i1 == self.indent_level(ts) != other.indent_level(ts) == i2. - # Intended to be used after not self.equal(other) is known, in which - # case it will return at least one witnessing tab size. - def not_equal_witness(self, other): - """ - Public method to calculate a tuple of witnessing tab size. - - Intended to be used after not self.equal(other) is known, in which - case it will return at least one witnessing tab size. - - @param other Whitespace object to calculate against. - @return A list of tuples (ts, i1, i2) such that - i1 == self.indent_level(ts) != other.indent_level(ts) == i2. - """ - n = max(self.longest_run_of_spaces(), - other.longest_run_of_spaces()) + 1 - a = [] - for ts in range(1, n + 1): - if self.indent_level(ts) != other.indent_level(ts): - a.append((ts, - self.indent_level(ts), - other.indent_level(ts))) - return a - - # Return True iff self.indent_level(t) < other.indent_level(t) - # for all t >= 1. - # The algorithm is due to Vincent Broman. - # Easy to prove it's correct. - # XXXpost that. - # Trivial to prove n is sharp (consider T vs ST). - # Unknown whether there's a faster general way. I suspected so at - # first, but no longer. - # For the special (but common!) case where M and N are both of the - # form (T*)(S*), M.less(N) iff M.len() < N.len() and - # M.num_tabs() <= N.num_tabs(). Proof is easy but kinda long-winded. - # XXXwrite that up. - # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1. - def less(self, other): - """ - Public method to compare the indentation level against another - Whitespace objects to be smaller. - - @param other Whitespace object to compare against. - @return True, if we compare less against the other Whitespace object. - """ - if self.n >= other.n: - return False - if self.is_simple and other.is_simple: - return self.nt <= other.nt - n = max(self.longest_run_of_spaces(), - other.longest_run_of_spaces()) + 1 - # the self.n >= other.n test already did it for ts=1 - for ts in range(2, n + 1): - if self.indent_level(ts) >= other.indent_level(ts): - return False - return True - - # return a list of tuples (ts, i1, i2) such that - # i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. - # Intended to be used after not self.less(other) is known, in which - # case it will return at least one witnessing tab size. - def not_less_witness(self, other): - """ - Public method to calculate a tuple of witnessing tab size. - - Intended to be used after not self.less(other is known, in which - case it will return at least one witnessing tab size. - - @param other Whitespace object to calculate against. - @return A list of tuples (ts, i1, i2) such that - i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. - """ - n = max(self.longest_run_of_spaces(), - other.longest_run_of_spaces()) + 1 - a = [] - for ts in range(1, n + 1): - if self.indent_level(ts) >= other.indent_level(ts): - a.append((ts, - self.indent_level(ts), - other.indent_level(ts))) - return a - - -def format_witnesses(w): - """ - Function to format the witnesses as a readable string. - - @param w A list of witnesses - @return A formated string of the witnesses. - """ - firsts = [str(tup[0]) for tup in w] - prefix = "at tab size" - if len(w) > 1: - prefix = prefix + "s" - return prefix + " " + ', '.join(firsts) - - -def process_tokens(tokens): - """ - Function processing all tokens generated by a tokenizer run. - - @param tokens list of tokens - @exception NannyNag raised to indicate an indentation error - """ - INDENT = tokenize.INDENT - DEDENT = tokenize.DEDENT - NEWLINE = tokenize.NEWLINE - JUNK = tokenize.COMMENT, tokenize.NL - indents = [Whitespace("")] - check_equal = 0 - - for (tokenType, token, start, _end, line) in tokens: - if tokenType == NEWLINE: - # a program statement, or ENDMARKER, will eventually follow, - # after some (possibly empty) run of tokens of the form - # (NL | COMMENT)* (INDENT | DEDENT+)? - # If an INDENT appears, setting check_equal is wrong, and will - # be undone when we see the INDENT. - check_equal = 1 - - elif tokenType == INDENT: - check_equal = 0 - thisguy = Whitespace(token) - if not indents[-1].less(thisguy): - witness = indents[-1].not_less_witness(thisguy) - msg = "indent not greater e.g. " + format_witnesses(witness) - raise NannyNag(start[0], msg, line) - indents.append(thisguy) - - elif tokenType == DEDENT: - # there's nothing we need to check here! what's important is - # that when the run of DEDENTs ends, the indentation of the - # program statement (or ENDMARKER) that triggered the run is - # equal to what's left at the top of the indents stack - - # Ouch! This assert triggers if the last line of the source - # is indented *and* lacks a newline -- then DEDENTs pop out - # of thin air. - # assert check_equal # else no earlier NEWLINE, or an - # earlier INDENT - check_equal = 1 - - del indents[-1] - - elif check_equal and tokenType not in JUNK: - # this is the first "real token" following a NEWLINE, so it - # must be the first token of the next program statement, or an - # ENDMARKER; the "line" argument exposes the leading whitespace - # for this statement; in the case of ENDMARKER, line is an empty - # string, so will properly match the empty string with which the - # "indents" stack was seeded - check_equal = 0 - thisguy = Whitespace(line) - if not indents[-1].equal(thisguy): - witness = indents[-1].not_equal_witness(thisguy) - msg = "indent not equal e.g. " + format_witnesses(witness) - raise NannyNag(start[0], msg, line) - -# eflag: noqa = M111
--- a/eric6/Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.py Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,391 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright (c) 2003 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> -# - -""" -Module implementing a dialog to show the output of the tabnanny command -process. -""" - - -import os -import fnmatch - -from PyQt5.QtCore import pyqtSlot, Qt, QTimer -from PyQt5.QtWidgets import ( - QDialog, QDialogButtonBox, QTreeWidgetItem, QApplication, QHeaderView -) - -from E5Gui.E5Application import e5App - -from .Ui_TabnannyDialog import Ui_TabnannyDialog - -import Utilities -import Preferences - - -class TabnannyDialog(QDialog, Ui_TabnannyDialog): - """ - Class implementing a dialog to show the results of the tabnanny check run. - """ - filenameRole = Qt.UserRole + 1 - - def __init__(self, indentCheckService, parent=None): - """ - Constructor - - @param indentCheckService reference to the service (IndentCheckService) - @param parent The parent widget (QWidget). - """ - super(TabnannyDialog, self).__init__(parent) - self.setupUi(self) - self.setWindowFlags(Qt.Window) - - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) - self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) - - self.resultList.headerItem().setText(self.resultList.columnCount(), "") - self.resultList.header().setSortIndicator(0, Qt.AscendingOrder) - - self.indentCheckService = indentCheckService - self.indentCheckService.indentChecked.connect(self.__processResult) - self.indentCheckService.batchFinished.connect(self.__batchFinished) - self.indentCheckService.error.connect(self.__processError) - self.filename = None - - self.noResults = True - self.cancelled = False - self.__finished = True - self.__errorItem = None - - self.__fileList = [] - self.__project = None - self.filterFrame.setVisible(False) - - self.checkProgress.setVisible(False) - self.checkProgressLabel.setVisible(False) - self.checkProgressLabel.setMaximumWidth(600) - - def __resort(self): - """ - Private method to resort the tree. - """ - self.resultList.sortItems( - self.resultList.sortColumn(), - self.resultList.header().sortIndicatorOrder()) - - def __createErrorItem(self, filename, message): - """ - Private slot to create a new error item in the result list. - - @param filename name of the file - @type str - @param message error message - @type str - """ - if self.__errorItem is None: - self.__errorItem = QTreeWidgetItem(self.resultList, [ - self.tr("Errors")]) - self.__errorItem.setExpanded(True) - self.__errorItem.setForeground(0, Qt.red) - - msg = "{0} ({1})".format(self.__project.getRelativePath(filename), - message) - if not self.resultList.findItems(msg, Qt.MatchExactly): - itm = QTreeWidgetItem(self.__errorItem, [msg]) - itm.setForeground(0, Qt.red) - itm.setFirstColumnSpanned(True) - - def __createResultItem(self, filename, line, sourcecode): - """ - Private method to create an entry in the result list. - - @param filename filename of file (string) - @param line linenumber of faulty source (integer or string) - @param sourcecode faulty line of code (string) - """ - itm = QTreeWidgetItem(self.resultList) - itm.setData(0, Qt.DisplayRole, - self.__project.getRelativePath(filename)) - itm.setData(1, Qt.DisplayRole, line) - itm.setData(2, Qt.DisplayRole, sourcecode) - itm.setTextAlignment(1, Qt.AlignRight) - itm.setData(0, self.filenameRole, filename) - - def prepare(self, fileList, project): - """ - Public method to prepare the dialog with a list of filenames. - - @param fileList list of filenames (list of strings) - @param project reference to the project object (Project) - """ - self.__fileList = fileList[:] - self.__project = project - - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) - self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) - self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) - - self.filterFrame.setVisible(True) - - self.__data = self.__project.getData("CHECKERSPARMS", "Tabnanny") - if self.__data is None or "ExcludeFiles" not in self.__data: - self.__data = {"ExcludeFiles": ""} - self.excludeFilesEdit.setText(self.__data["ExcludeFiles"]) - - def start(self, fn): - """ - Public slot to start the tabnanny check. - - @param fn File or list of files or directory to be checked - (string or list of strings) - """ - if self.__project is None: - self.__project = e5App().getObject("Project") - - self.cancelled = False - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) - self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) - self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) - self.checkProgress.setVisible(True) - QApplication.processEvents() - - if isinstance(fn, list): - self.files = fn - elif os.path.isdir(fn): - self.files = [] - extensions = set(Preferences.getPython("Python3Extensions")) - for ext in extensions: - self.files.extend( - Utilities.direntries(fn, True, '*{0}'.format(ext), 0)) - else: - self.files = [fn] - - self.__errorItem = None - - if len(self.files) > 0: - self.checkProgress.setMaximum(len(self.files)) - self.checkProgress.setVisible(len(self.files) > 1) - self.checkProgressLabel.setVisible(len(self.files) > 1) - QApplication.processEvents() - - # now go through all the files - self.progress = 0 - self.files.sort() - if len(self.files) == 1: - self.__batch = False - self.check() - else: - self.__batch = True - self.checkBatch() - - def check(self, codestring=''): - """ - Public method to start an indentation check for one file. - - The results are reported to the __processResult slot. - @keyparam codestring optional sourcestring (str) - """ - if not self.files: - self.checkProgressLabel.setPath("") - self.checkProgress.setMaximum(1) - self.checkProgress.setValue(1) - self.__finish() - return - - self.filename = self.files.pop(0) - self.checkProgress.setValue(self.progress) - self.checkProgressLabel.setPath(self.filename) - QApplication.processEvents() - self.__resort() - - if self.cancelled: - return - - try: - self.source = Utilities.readEncodedFile(self.filename)[0] - self.source = Utilities.normalizeCode(self.source) - except (UnicodeError, IOError) as msg: - self.noResults = False - self.__createResultItem( - self.filename, 1, - "Error: {0}".format(str(msg)).rstrip()) - self.progress += 1 - # Continue with next file - self.check() - return - - self.__finished = False - self.indentCheckService.indentCheck( - None, self.filename, self.source) - - def checkBatch(self): - """ - Public method to start an indentation check batch job. - - The results are reported to the __processResult slot. - """ - self.__lastFileItem = None - - self.checkProgressLabel.setPath(self.tr("Preparing files...")) - progress = 0 - - argumentsList = [] - for filename in self.files: - progress += 1 - self.checkProgress.setValue(progress) - QApplication.processEvents() - - try: - source = Utilities.readEncodedFile(filename)[0] - source = Utilities.normalizeCode(source) - except (UnicodeError, IOError) as msg: - self.noResults = False - self.__createResultItem( - filename, 1, - "Error: {0}".format(str(msg)).rstrip()) - continue - - argumentsList.append((filename, source)) - - # reset the progress bar to the checked files - self.checkProgress.setValue(self.progress) - self.checkProgressLabel.setPath(self.tr("Transferring data...")) - QApplication.processEvents() - - self.__finished = False - self.indentCheckService.indentBatchCheck(argumentsList) - - def __batchFinished(self): - """ - Private slot handling the completion of a batch job. - """ - self.checkProgressLabel.setPath("") - self.checkProgress.setMaximum(1) - self.checkProgress.setValue(1) - self.__finish() - - def __processError(self, fn, msg): - """ - Private slot to process an error indication from the service. - - @param fn filename of the file - @type str - @param msg error message - @type str - """ - self.__createErrorItem(fn, msg) - - if not self.__batch: - self.check() - - def __processResult(self, fn, nok, line, error): - """ - Private slot called after perfoming a style check on one file. - - @param fn filename of the just checked file (str) - @param nok flag if a problem was found (bool) - @param line line number (str) - @param error text of the problem (str) - """ - if self.__finished: - return - - # Check if it's the requested file, otherwise ignore signal if not - # in batch mode - if not self.__batch and fn != self.filename: - return - - if nok: - self.noResults = False - self.__createResultItem(fn, line, error.rstrip()) - self.progress += 1 - - self.checkProgress.setValue(self.progress) - self.checkProgressLabel.setPath(fn) - QApplication.processEvents() - self.__resort() - - if not self.__batch: - self.check() - - def __finish(self): - """ - Private slot called when the action or the user pressed the button. - """ - if not self.__finished: - self.__finished = True - - self.cancelled = True - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) - self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) - self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) - - if self.noResults: - self.__createResultItem( - self.tr('No indentation errors found.'), "", "") - QApplication.processEvents() - self.resultList.header().resizeSections( - QHeaderView.ResizeToContents) - self.resultList.header().setStretchLastSection(True) - - self.checkProgress.setVisible(False) - self.checkProgressLabel.setVisible(False) - - def on_buttonBox_clicked(self, button): - """ - Private slot called by a button of the button box clicked. - - @param button button that was clicked (QAbstractButton) - """ - if button == self.buttonBox.button(QDialogButtonBox.Close): - self.close() - elif button == self.buttonBox.button(QDialogButtonBox.Cancel): - if self.__batch: - self.indentCheckService.cancelIndentBatchCheck() - QTimer.singleShot(1000, self.__finish) - else: - self.__finish() - - @pyqtSlot() - def on_startButton_clicked(self): - """ - Private slot to start a code metrics run. - """ - fileList = self.__fileList[:] - - filterString = self.excludeFilesEdit.text() - if ( - "ExcludeFiles" not in self.__data or - filterString != self.__data["ExcludeFiles"] - ): - self.__data["ExcludeFiles"] = filterString - self.__project.setData("CHECKERSPARMS", "Tabnanny", self.__data) - filterList = [f.strip() for f in filterString.split(",") - if f.strip()] - if filterList: - for fileFilter in filterList: - fileList = [ - f for f in fileList if not fnmatch.fnmatch(f, fileFilter) - ] - - self.resultList.clear() - self.noResults = True - self.cancelled = False - self.start(fileList) - - def on_resultList_itemActivated(self, itm, col): - """ - Private slot to handle the activation of an item. - - @param itm reference to the activated item (QTreeWidgetItem) - @param col column the item was activated in (integer) - """ - if self.noResults: - return - - fn = Utilities.normabspath(itm.data(0, self.filenameRole)) - lineno = int(itm.text(1)) - - e5App().getObject("ViewManager").openSourceFile(fn, lineno)
--- a/eric6/Plugins/CheckerPlugins/Tabnanny/TabnannyDialog.ui Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>TabnannyDialog</class> - <widget class="QDialog" name="TabnannyDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>650</width> - <height>400</height> - </rect> - </property> - <property name="windowTitle"> - <string>Tabnanny Result</string> - </property> - <property name="whatsThis"> - <string><b>Tabnanny Results</b> -<p>This dialog shows the results of the tabnanny command. Double clicking an -entry will open an editor window and position the cursor at the respective line.</p></string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QFrame" name="filterFrame"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> - </property> - <property name="frameShadow"> - <enum>QFrame::Raised</enum> - </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="margin"> - <number>0</number> - </property> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Exclude Files:</string> - </property> - </widget> - </item> - <item> - <widget class="E5ClearableLineEdit" name="excludeFilesEdit"> - <property name="toolTip"> - <string>Enter filename patterns of files to be excluded separated by a comma</string> - </property> - </widget> - </item> - <item> - <widget class="Line" name="line"> - <property name="lineWidth"> - <number>2</number> - </property> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="startButton"> - <property name="toolTip"> - <string>Press to start the tabnanny run</string> - </property> - <property name="text"> - <string>Start</string> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QTreeWidget" name="resultList"> - <property name="whatsThis"> - <string><b>Result List</b> -<p>This list shows the results of the tabnanny command. Double clicking -an entry will open this entry in an editor window and position the cursor at -the respective line.</p></string> - </property> - <property name="alternatingRowColors"> - <bool>true</bool> - </property> - <property name="rootIsDecorated"> - <bool>false</bool> - </property> - <property name="itemsExpandable"> - <bool>false</bool> - </property> - <property name="sortingEnabled"> - <bool>true</bool> - </property> - <column> - <property name="text"> - <string>Filename</string> - </property> - </column> - <column> - <property name="text"> - <string>#</string> - </property> - </column> - <column> - <property name="text"> - <string>Source</string> - </property> - </column> - </widget> - </item> - <item> - <widget class="E5SqueezeLabelPath" name="checkProgressLabel"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item> - <widget class="QProgressBar" name="checkProgress"> - <property name="toolTip"> - <string>Shows the progress of the tabnanny action</string> - </property> - <property name="value"> - <number>0</number> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="format"> - <string>%v/%m Files</string> - </property> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Close</set> - </property> - </widget> - </item> - </layout> - </widget> - <pixmapfunction>qPixmapFromMimeSource</pixmapfunction> - <customwidgets> - <customwidget> - <class>E5SqueezeLabelPath</class> - <extends>QLabel</extends> - <header>E5Gui/E5SqueezeLabels.h</header> - </customwidget> - <customwidget> - <class>E5ClearableLineEdit</class> - <extends>QLineEdit</extends> - <header>E5Gui/E5LineEdit.h</header> - </customwidget> - </customwidgets> - <tabstops> - <tabstop>startButton</tabstop> - <tabstop>excludeFilesEdit</tabstop> - <tabstop>resultList</tabstop> - <tabstop>buttonBox</tabstop> - </tabstops> - <resources/> - <connections/> -</ui>
--- a/eric6/Plugins/CheckerPlugins/Tabnanny/__init__.py Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright (c) 2007 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> -# - -""" -Package containing the Tabnanny plugin. -"""
--- a/eric6/Plugins/PluginTabnanny.py Tue Aug 11 16:40:11 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,392 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright (c) 2007 - 2020 Detlev Offenbach <detlev@die-offenbachs.de> -# - -""" -Module implementing the Tabnanny plugin. -""" - -# TODO: remove tabnanny as it is obsolete - -import os - -from PyQt5.QtCore import QObject, pyqtSignal - -from E5Gui.E5Application import e5App -from E5Gui.E5Action import E5Action -from Project.ProjectBrowserModel import ProjectBrowserFileItem -from Utilities import determinePythonVersion - -import Preferences -import UI.Info - -# Start-Of-Header -name = "Tabnanny Plugin" -author = "Detlev Offenbach <detlev@die-offenbachs.de>" -autoactivate = True -deactivateable = True -version = UI.Info.VersionOnly -className = "TabnannyPlugin" -packageName = "__core__" -shortDescription = "Show the Tabnanny dialog." -longDescription = ( - """This plugin implements the Tabnanny dialog.""" - """ Tabnanny is used to check Python source files for correct""" - """ indentations.""" -) -pyqtApi = 2 -# End-Of-Header - -error = "" - - -class TabnannyPlugin(QObject): - """ - Class implementing the Tabnanny plugin. - - @signal indentChecked(str, bool, str, str) emitted when the indent - check was done. - @signal batchFinished() emitted when a style check batch is done - @signal error(str, str) emitted in case of an error - """ - indentChecked = pyqtSignal(str, bool, str, str) - batchFinished = pyqtSignal() - error = pyqtSignal(str, str) - - def __init__(self, ui): - """ - Constructor - - @param ui reference to the user interface object (UI.UserInterface) - """ - super(TabnannyPlugin, self).__init__(ui) - self.__ui = ui - self.__initialize() - - self.backgroundService = e5App().getObject("BackgroundService") - - path = os.path.join( - os.path.dirname(__file__), 'CheckerPlugins', 'Tabnanny') - self.backgroundService.serviceConnect( - 'indent', 'Python3', path, 'Tabnanny', - lambda *args: self.indentChecked.emit(*args), - onErrorCallback=self.serviceErrorPy3, - onBatchDone=self.batchJobDone) - - self.queuedBatches = [] - self.batchesFinished = True - - def __serviceError(self, fn, msg): - """ - Private slot handling service errors. - - @param fn file name (string) - @param msg message text (string) - """ - self.error.emit(fn, msg) - - def serviceErrorPy3(self, fx, lang, fn, msg): - """ - Public slot handling service errors for Python 3. - - @param fx service name (string) - @param lang language (string) - @param fn file name (string) - @param msg message text (string) - """ - if fx in ['indent', 'batch_indent'] and lang == 'Python3': - if fx == 'indent': - self.__serviceError(fn, msg) - else: - self.__serviceError(self.tr("Python 3 batch check"), msg) - self.batchJobDone(fx, lang) - - def batchJobDone(self, fx, lang): - """ - Public slot handling the completion of a batch job. - - @param fx service name (string) - @param lang language (string) - """ - if fx in ['indent', 'batch_indent']: - if lang in self.queuedBatches: - self.queuedBatches.remove(lang) - # prevent sending the signal multiple times - if len(self.queuedBatches) == 0 and not self.batchesFinished: - self.batchFinished.emit() - self.batchesFinished = True - - def __initialize(self): - """ - Private slot to (re)initialize the plugin. - """ - self.__projectAct = None - self.__projectTabnannyDialog = None - - self.__projectBrowserAct = None - self.__projectBrowserMenu = None - self.__projectBrowserTabnannyDialog = None - - self.__editors = [] - self.__editorAct = None - self.__editorTabnannyDialog = None - - def indentCheck(self, lang, filename, source): - """ - Public method to prepare an indentation check on one Python source - file. - - @param lang language of the file or None to determine by internal - algorithm (str or None) - @param filename source filename (string) - @param source string containing the code to check (string) - """ - if lang is None: - lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang != 'Python3': - return - - self.backgroundService.enqueueRequest( - 'indent', lang, filename, [source]) - - def indentBatchCheck(self, argumentsList): - """ - Public method to prepare an indentation check on multiple Python - source files. - - @param argumentsList list of arguments tuples with each tuple - containing filename and source (string, string) - """ - data = { - "Python3": [], - } - for filename, source in argumentsList: - lang = 'Python{0}'.format(determinePythonVersion(filename, source)) - if lang != 'Python3': - continue - else: - data[lang].append((filename, source)) - - self.queuedBatches = [] - if data['Python3']: - self.queuedBatches.append('Python3') - self.backgroundService.enqueueRequest( - 'batch_indent', 'Python3', "", data['Python3']) - self.batchesFinished = False - - def cancelIndentBatchCheck(self): - """ - Public method to cancel all batch jobs. - """ - self.backgroundService.requestCancel('batch_style', 'Python3') - - def activate(self): - """ - Public method to activate this plugin. - - @return tuple of None and activation status (boolean) - """ - menu = e5App().getObject("Project").getMenu("Checks") - if menu: - self.__projectAct = E5Action( - self.tr('Check Indentations'), - self.tr('&Indentations...'), 0, 0, - self, 'project_check_indentations') - self.__projectAct.setStatusTip( - self.tr('Check indentations using tabnanny.')) - self.__projectAct.setWhatsThis(self.tr( - """<b>Check Indentations...</b>""" - """<p>This checks Python files""" - """ for bad indentations using tabnanny.</p>""" - )) - self.__projectAct.triggered.connect(self.__projectTabnanny) - e5App().getObject("Project").addE5Actions([self.__projectAct]) - menu.addAction(self.__projectAct) - - self.__editorAct = E5Action( - self.tr('Check Indentations'), - self.tr('&Indentations...'), 0, 0, - self, "") - self.__editorAct.setWhatsThis(self.tr( - """<b>Check Indentations...</b>""" - """<p>This checks Python files""" - """ for bad indentations using tabnanny.</p>""" - )) - self.__editorAct.triggered.connect(self.__editorTabnanny) - - e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) - e5App().getObject("ProjectBrowser").getProjectBrowser( - "sources").showMenu.connect(self.__projectBrowserShowMenu) - e5App().getObject("ViewManager").editorOpenedEd.connect( - self.__editorOpened) - e5App().getObject("ViewManager").editorClosedEd.connect( - self.__editorClosed) - - for editor in e5App().getObject("ViewManager").getOpenEditors(): - self.__editorOpened(editor) - - return None, True - - def deactivate(self): - """ - Public method to deactivate this plugin. - """ - e5App().getObject("Project").showMenu.disconnect( - self.__projectShowMenu) - e5App().getObject("ProjectBrowser").getProjectBrowser( - "sources").showMenu.disconnect(self.__projectBrowserShowMenu) - e5App().getObject("ViewManager").editorOpenedEd.disconnect( - self.__editorOpened) - e5App().getObject("ViewManager").editorClosedEd.disconnect( - self.__editorClosed) - - menu = e5App().getObject("Project").getMenu("Checks") - if menu: - menu.removeAction(self.__projectAct) - - if self.__projectBrowserMenu: - if self.__projectBrowserAct: - self.__projectBrowserMenu.removeAction( - self.__projectBrowserAct) - - for editor in self.__editors: - editor.showMenu.disconnect(self.__editorShowMenu) - menu = editor.getMenu("Checks") - if menu is not None: - menu.removeAction(self.__editorAct) - - self.__initialize() - - def __projectShowMenu(self, menuName, menu): - """ - Private slot called, when the the project menu or a submenu is - about to be shown. - - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) - """ - if menuName == "Checks" and self.__projectAct is not None: - self.__projectAct.setEnabled( - e5App().getObject("Project").getProjectLanguage() in - ["Python3", "MicroPython"]) - - def __projectBrowserShowMenu(self, menuName, menu): - """ - Private slot called, when the the project browser context menu or a - submenu is about to be shown. - - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) - """ - if ( - menuName == "Checks" and - e5App().getObject("Project").getProjectLanguage() in - ["Python3", "MicroPython"] - ): - self.__projectBrowserMenu = menu - if self.__projectBrowserAct is None: - self.__projectBrowserAct = E5Action( - self.tr('Check Indentations'), - self.tr('&Indentations...'), 0, 0, - self, "") - self.__projectBrowserAct.setWhatsThis(self.tr( - """<b>Check Indentations...</b>""" - """<p>This checks Python files""" - """ for bad indentations using tabnanny.</p>""" - )) - self.__projectBrowserAct.triggered.connect( - self.__projectBrowserTabnanny) - if self.__projectBrowserAct not in menu.actions(): - menu.addAction(self.__projectBrowserAct) - - def __projectTabnanny(self): - """ - Private slot used to check the project files for bad indentations. - """ - project = e5App().getObject("Project") - project.saveAllScripts() - ppath = project.getProjectPath() - files = [os.path.join(ppath, file) - for file in project.pdata["SOURCES"] - if file.endswith( - tuple(Preferences.getPython("Python3Extensions")))] - - from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog - self.__projectTabnannyDialog = TabnannyDialog(self) - self.__projectTabnannyDialog.show() - self.__projectTabnannyDialog.prepare(files, project) - - def __projectBrowserTabnanny(self): - """ - Private method to handle the tabnanny context menu action of the - project sources browser. - """ - browser = e5App().getObject("ProjectBrowser").getProjectBrowser( - "sources") - if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: - fn = [] - for itm in browser.getSelectedItems([ProjectBrowserFileItem]): - fn.append(itm.fileName()) - else: - itm = browser.model().item(browser.currentIndex()) - try: - fn = itm.fileName() - except AttributeError: - fn = itm.dirName() - - from CheckerPlugins.Tabnanny.TabnannyDialog import TabnannyDialog - self.__projectBrowserTabnannyDialog = TabnannyDialog(self) - self.__projectBrowserTabnannyDialog.show() - self.__projectBrowserTabnannyDialog.start(fn) - - def __editorOpened(self, editor): - """ - Private slot called, when a new editor was opened. - - @param editor reference to the new editor (QScintilla.Editor) - """ - menu = editor.getMenu("Checks") - if menu is not None: - menu.addAction(self.__editorAct) - editor.showMenu.connect(self.__editorShowMenu) - self.__editors.append(editor) - - def __editorClosed(self, editor): - """ - Private slot called, when an editor was closed. - - @param editor reference to the editor (QScintilla.Editor) - """ - try: - self.__editors.remove(editor) - except ValueError: - pass - - def __editorShowMenu(self, menuName, menu, editor): - """ - Private slot called, when the the editor context menu or a submenu is - about to be shown. - - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) - @param editor reference to the editor - """ - if menuName == "Checks": - if self.__editorAct not in menu.actions(): - menu.addAction(self.__editorAct) - self.__editorAct.setEnabled(editor.isPyFile()) - - def __editorTabnanny(self): - """ - Private slot to handle the tabnanny context menu action of the editors. - """ - editor = e5App().getObject("ViewManager").activeWindow() - if editor is not None: - if editor.checkDirty() and editor.getFileName() is not None: - from CheckerPlugins.Tabnanny.TabnannyDialog import ( - TabnannyDialog - ) - self.__editorTabnannyDialog = TabnannyDialog(self) - self.__editorTabnannyDialog.show() - self.__editorTabnannyDialog.start(editor.getFileName())