Fri, 09 Sep 2011 11:54:20 +0200
Made the check for line flags like __IGNORE_WARNING__ more flexible and extensible.
--- a/APIs/Python3/eric5.api Fri Sep 09 09:33:19 2011 +0200 +++ b/APIs/Python3/eric5.api Fri Sep 09 11:54:20 2011 +0200 @@ -6774,6 +6774,7 @@ eric5.Utilities.escape_uentities?4(m) eric5.Utilities.extractFlags?4(text) eric5.Utilities.extractFlagsFromFile?4(filename) +eric5.Utilities.extractLineFlags?4(line, startComment=") eric5.Utilities.fromNativeSeparators?4(path) eric5.Utilities.generateDistroInfo?4(linesep='\n') eric5.Utilities.generatePluginsVersionInfo?4(linesep='\n') @@ -6934,6 +6935,7 @@ eric5.UtilitiesPython2.Tabnanny.process_tokens?4(tokens) eric5.UtilitiesPython2.Tools.coding_regexps?7 eric5.UtilitiesPython2.Tools.decode?4(text) +eric5.UtilitiesPython2.Tools.extractLineFlags?4(line, startComment=") eric5.UtilitiesPython2.Tools.get_coding?4(text) eric5.UtilitiesPython2.Tools.normalizeCode?4(codestring) eric5.UtilitiesPython2.Tools.readEncodedFile?4(filename)
--- a/Documentation/Help/source.qhp Fri Sep 09 09:33:19 2011 +0200 +++ b/Documentation/Help/source.qhp Fri Sep 09 11:54:20 2011 +0200 @@ -2441,6 +2441,7 @@ <keyword name="escape_uentities" id="escape_uentities" ref="eric5.Utilities.__init__.html#escape_uentities" /> <keyword name="extractFlags" id="extractFlags" ref="eric5.Utilities.__init__.html#extractFlags" /> <keyword name="extractFlagsFromFile" id="extractFlagsFromFile" ref="eric5.Utilities.__init__.html#extractFlagsFromFile" /> + <keyword name="extractLineFlags" id="extractLineFlags" ref="eric5.Utilities.__init__.html#extractLineFlags" /> <keyword name="fromNativeSeparators" id="fromNativeSeparators" ref="eric5.Utilities.__init__.html#fromNativeSeparators" /> <keyword name="generateDistroInfo" id="generateDistroInfo" ref="eric5.Utilities.__init__.html#generateDistroInfo" /> <keyword name="generatePluginsVersionInfo" id="generatePluginsVersionInfo" ref="eric5.Utilities.__init__.html#generatePluginsVersionInfo" /> @@ -3397,6 +3398,7 @@ <keyword name="UtilitiesPython2 (Package)" id="UtilitiesPython2 (Package)" ref="index-eric5.UtilitiesPython2.html" /> <keyword name="Tools (Module)" id="Tools (Module)" ref="eric5.UtilitiesPython2.Tools.html" /> <keyword name="decode" id="decode" ref="eric5.UtilitiesPython2.Tools.html#decode" /> + <keyword name="extractLineFlags" id="extractLineFlags" ref="eric5.UtilitiesPython2.Tools.html#extractLineFlags" /> <keyword name="get_coding" id="get_coding" ref="eric5.UtilitiesPython2.Tools.html#get_coding" /> <keyword name="normalizeCode" id="normalizeCode" ref="eric5.UtilitiesPython2.Tools.html#normalizeCode" /> <keyword name="readEncodedFile" id="readEncodedFile" ref="eric5.UtilitiesPython2.Tools.html#readEncodedFile" />
--- a/Documentation/Source/eric5.Utilities.__init__.html Fri Sep 09 09:33:19 2011 +0200 +++ b/Documentation/Source/eric5.Utilities.__init__.html Fri Sep 09 11:54:20 2011 +0200 @@ -86,6 +86,9 @@ <td><a href="#extractFlagsFromFile">extractFlagsFromFile</a></td> <td>Function to extract eric specific flags out of the given file.</td> </tr><tr> +<td><a href="#extractLineFlags">extractLineFlags</a></td> +<td>Function to extract flags starting and ending with '__' from a line comment.</td> +</tr><tr> <td><a href="#fromNativeSeparators">fromNativeSeparators</a></td> <td>Function returning a path, that is using "/" separator characters.</td> </tr><tr> @@ -625,6 +628,30 @@ </dl> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> +<a NAME="extractLineFlags" ID="extractLineFlags"></a> +<h2>extractLineFlags</h2> +<b>extractLineFlags</b>(<i>line, startComment="</i>) +<p> + Function to extract flags starting and ending with '__' from a line comment. +</p><dl> +<dt><i>line</i></dt> +<dd> +line to extract flags from (string) +</dd><dt><i>startComment=</i></dt> +<dd> +string identifying the start of the comment (string) +</dd><dt><i>endComment=</i></dt> +<dd> +string identifying the end of a comment (string) +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +list containing the extracted flags (list of strings) +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> <a NAME="fromNativeSeparators" ID="fromNativeSeparators"></a> <h2>fromNativeSeparators</h2> <b>fromNativeSeparators</b>(<i>path</i>)
--- a/Documentation/Source/eric5.UtilitiesPython2.Tools.html Fri Sep 09 09:33:19 2011 +0200 +++ b/Documentation/Source/eric5.UtilitiesPython2.Tools.html Fri Sep 09 11:54:20 2011 +0200 @@ -38,6 +38,9 @@ <td><a href="#decode">decode</a></td> <td>Function to decode a text.</td> </tr><tr> +<td><a href="#extractLineFlags">extractLineFlags</a></td> +<td>Function to extract flags starting and ending with '__' from a line comment.</td> +</tr><tr> <td><a href="#get_coding">get_coding</a></td> <td>Function to get the coding of a text.</td> </tr><tr> @@ -67,6 +70,30 @@ </dl> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> +<a NAME="extractLineFlags" ID="extractLineFlags"></a> +<h2>extractLineFlags</h2> +<b>extractLineFlags</b>(<i>line, startComment="</i>) +<p> + Function to extract flags starting and ending with '__' from a line comment. +</p><dl> +<dt><i>line</i></dt> +<dd> +line to extract flags from (string) +</dd><dt><i>startComment=</i></dt> +<dd> +string identifying the start of the comment (string) +</dd><dt><i>endComment=</i></dt> +<dd> +string identifying the end of a comment (string) +</dd> +</dl><dl> +<dt>Returns:</dt> +<dd> +list containing the extracted flags (list of strings) +</dd> +</dl> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> <a NAME="get_coding" ID="get_coding"></a> <h2>get_coding</h2> <b>get_coding</b>(<i>text</i>)
--- a/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py Fri Sep 09 09:33:19 2011 +0200 +++ b/Plugins/CheckerPlugins/Pep8/Pep8Dialog.py Fri Sep 09 11:54:20 2011 +0200 @@ -325,8 +325,8 @@ checker.messages.sort(key=lambda a: a[1]) for message in checker.messages: fname, lineno, position, text = message - if not source[lineno - 1].strip()\ - .endswith("__IGNORE_WARNING__"): + if "__IGNORE_WARNING__" not in Utilities.extractLineFlags( + source[lineno - 1].strip()): self.noResults = False fixed = False if fixer:
--- a/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py Fri Sep 09 09:33:19 2011 +0200 +++ b/Plugins/CheckerPlugins/SyntaxChecker/SyntaxCheckerDialog.py Fri Sep 09 11:54:20 2011 +0200 @@ -231,8 +231,9 @@ continue fname, lineno, message = \ warning.getMessageData() - if not sourceLines[lineno - 1].strip()\ - .endswith("__IGNORE_WARNING__"): + if "__IGNORE_WARNING__" not in \ + Utilities.extractLineFlags( + sourceLines[lineno - 1].strip()): self.noResults = False self.__createResultItem( fname, lineno, 0, message, "",
--- a/QScintilla/Editor.py Fri Sep 09 09:33:19 2011 +0200 +++ b/QScintilla/Editor.py Fri Sep 09 11:54:20 2011 +0200 @@ -4440,8 +4440,8 @@ continue _fn, lineno, message = warning.getMessageData() - if not self.text(lineno - 1).strip()\ - .endswith("__IGNORE_WARNING__"): + if "__IGNORE_WARNING__" not in Utilities.extractLineFlags( + self.text(lineno - 1).strip()): self.toggleFlakesWarning( lineno, True, message) except SyntaxError as err:
--- a/Utilities/__init__.py Fri Sep 09 09:33:19 2011 +0200 +++ b/Utilities/__init__.py Fri Sep 09 11:54:20 2011 +0200 @@ -546,6 +546,27 @@ return extractFlags(source) +def extractLineFlags(line, startComment="#", endComment=""): + """ + Function to extract flags starting and ending with '__' from a line comment. + + @param line line to extract flags from (string) + @keyparam startComment string identifying the start of the comment (string) + @keyparam endComment string identifying the end of a comment (string) + @return list containing the extracted flags (list of strings) + """ + flags = [] + + pos = line.rindex(startComment) + if pos >= 0: + comment = line[pos + len(startComment):].strip() + if endComment: + comment = comment.replace("endComment", "") + flags = [f.strip() for f in comment.split() + if (f.startswith("__") and f.endswith("__"))] + return flags + + def toNativeSeparators(path): """ Function returning a path, that is using native separator characters.
--- a/UtilitiesPython2/Py2SyntaxChecker.py Fri Sep 09 09:33:19 2011 +0200 +++ b/UtilitiesPython2/Py2SyntaxChecker.py Fri Sep 09 11:54:20 2011 +0200 @@ -12,7 +12,7 @@ import re import traceback -from Tools import readEncodedFile, normalizeCode +from Tools import readEncodedFile, normalizeCode, extractLineFlags from py2flakes.checker import Checker from py2flakes.messages import ImportStarUsed @@ -117,8 +117,7 @@ continue _fn, lineno, message = warning.getMessageData() - if not lines[lineno - 1].strip()\ - .endswith("__IGNORE_WARNING__"): + if "__IGNORE_WARNING__" not in extractLineFlags(lines[lineno - 1].strip()): strings.extend(["FLAKES_WARNING", _fn, lineno, message]) except SyntaxError as err: if err.text.strip():
--- a/UtilitiesPython2/Tools.py Fri Sep 09 09:33:19 2011 +0200 +++ b/UtilitiesPython2/Tools.py Fri Sep 09 11:54:20 2011 +0200 @@ -95,6 +95,27 @@ codestring = codestring + '\n' return codestring + + +def extractLineFlags(line, startComment="#", endComment=""): + """ + Function to extract flags starting and ending with '__' from a line comment. + @param line line to extract flags from (string) + @keyparam startComment string identifying the start of the comment (string) + @keyparam endComment string identifying the end of a comment (string) + @return list containing the extracted flags (list of strings) + """ + flags = [] + + pos = line.rindex(startComment) + if pos >= 0: + comment = line[pos + len(startComment):].strip() + if endComment: + comment = comment.replace("endComment", "") + flags = [f.strip() for f in comment.split() + if (f.startswith("__") and f.endswith("__"))] + return flags + # # eflag: FileType = Python2