From 2d4dafe1eab6f8f59188403176d3557dbded4c6a Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Mon, 11 Feb 2013 11:33:16 +0000 Subject: [PATCH 1/8] Added support for Sublime Text 3 --- python_checker.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/python_checker.py b/python_checker.py index bab8586..28c1f11 100644 --- a/python_checker.py +++ b/python_checker.py @@ -9,7 +9,7 @@ try: from local_settings import CHECKERS except ImportError as e: - print ''' + print (''' Please create file local_settings.py in the same directory with python_checker.py. Add to local_settings.py list of your checkers. @@ -33,7 +33,7 @@ ["/usr/bin/pyflakes", [] ] ] } -''' +''') global view_messages @@ -55,7 +55,8 @@ def on_selection_modified(self, view): global view_messages lineno = view.rowcol(view.sel()[0].end())[0] if view.id() in view_messages and lineno in view_messages[view.id()]: - view.set_status('python_checker', view_messages[view.id()][lineno]) + _message = (view_messages[view.id()][lineno]).decode('utf-8') + view.set_status('python_checker', _message) else: view.erase_status('python_checker') @@ -85,19 +86,21 @@ def check_and_mark(view): checker_messages += parse_messages(stdout) checker_messages += parse_messages(stderr) for line in checker_messages: - print "[%s] %s:%s:%s %s" % ( + print ("[%s] %s:%s:%s %s" % ( checker.split('/')[-1], view.file_name(), - line['lineno'] + 1, line['col'] + 1, line['text']) + line['lineno'] + 1, line['col'] + 1, line['text'])) messages += checker_messages except OSError: - print "Checker could not be found:", checker + print ("Checker could not be found:", checker) + except Exception as e: + print ("Generic error while running checker:", e) outlines = [view.full_line(view.text_point(m['lineno'], 0)) for m in messages] view.erase_regions('python_checker_outlines') view.add_regions('python_checker_outlines', outlines, - 'keyword', + 'keyword', flags= sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED) underlines = [] @@ -109,13 +112,13 @@ def check_and_mark(view): view.erase_regions('python_checker_underlines') view.add_regions('python_checker_underlines', underlines, - 'keyword', + 'keyword', flags= sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_OUTLINED) line_messages = {} for m in (m for m in messages if m['text']): if m['lineno'] in line_messages: - line_messages[m['lineno']] += ';' + m['text'] + line_messages[m['lineno']] += b';' + m['text'] else: line_messages[m['lineno']] = m['text'] @@ -144,8 +147,8 @@ def parse_messages(checker_output): c:\Python26\Scripts\pildriver.py:208: 'ImageFilter' imported but unused ''' - pep8_re = re.compile(r'.*:(\d+):(\d+):\s+(.*)') - pyflakes_re = re.compile(r'.*:(\d+):\s+(.*)') + pep8_re = re.compile(b'.*:(\d+):(\d+):\s+(.*)') + pyflakes_re = re.compile(b'.*:(\d+):\s+(.*)') messages = [] for i, line in enumerate(checker_output.splitlines()): From 6d83b4373bdeba901730d2258497f7a0d7ef783a Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Mon, 11 Feb 2013 18:27:10 +0000 Subject: [PATCH 2/8] Added support for separate coloring of pep8 and flakes, for better visibility --- README.markdown | 51 ++++++++++++++++++++++++++++++++++++++++++++++- python_checker.py | 29 ++++++++++++++++++++------- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/README.markdown b/README.markdown index d81df48..ab05d55 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,4 @@ -# Python PEP-8 and PyFlakes checker for SublimeText 2 editor +# Python PEP-8 and PyFlakes checker for SublimeText editor (2 and 3) This project is a plugin for [SublimeText 2](http://www.sublimetext.com/2) text editor. It checks all python files you opening and editing through two popular Python checkers - [pep8](http://pypi.python.org/pypi/pep8) @@ -35,6 +35,55 @@ but sublime text settings are prefered. (using syntax checker binary name) Restart SublimeText 2 and open some *.py file to see check results. You can see additional information in python console of your editor (go View -> Show Console). +You can also set the colloring of the highlights generated by the plugin. +By default it will use the color for "keyword" (for pep8 messages) and "invalid" +(for pyflakes messages). +You can customise it by using the specific strings, though: +keyword.python_checker.outline: outline around lines with pep8 flags +invalid.python_checker.outline: outline around lines with pyflakes flags +keyword.python_checker.underline: column-specific mark for flags which provide it + +An example used with a Solarized theme: +
+    
+        name
+        invalid.python_checker.outline
+        scope
+        invalid.python_checker.outline
+        settings
+        
+            background
+            #FF4A52
+            foreground
+            #FFFFFF
+        
+    
+    
+        name
+        keyword.python_checker.outline
+        scope
+        keyword.python_checker.outline
+        settings
+        
+            background
+            #DF9400
+            foreground
+            #FFFFFF
+        
+    
+    
+        name
+        keyword.python_checker.underline
+        scope
+        keyword.python_checker.underline
+        settings
+        
+            background
+            #FF0000
+        
+    
+
+
 ## Why not sublimelint
 
 Before creating this project I used [sublimelint](https://github.com/lunixbochs/sublimelint), which is multilanguage
diff --git a/python_checker.py b/python_checker.py
index 28c1f11..0d0066b 100644
--- a/python_checker.py
+++ b/python_checker.py
@@ -95,13 +95,25 @@ def check_and_mark(view):
         except Exception as e:
             print ("Generic error while running checker:", e)
 
-    outlines = [view.full_line(view.text_point(m['lineno'], 0))
-                for m in messages]
     view.erase_regions('python_checker_outlines')
-    view.add_regions('python_checker_outlines',
+
+    # Separate scopes for pep8 and flakes messages
+    # Will use keyword.python_checker for pep8
+    outlines = [view.full_line(view.text_point(m['lineno'], 0))
+                for m in messages if m['type'] == 'pep8']
+    view.erase_regions('python_checker_outlines_pep8')
+    view.add_regions('python_checker_outlines_pep8',
+        outlines,
+        'keyword.python_checker.outline', icon='circle',
+        flags=sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED)
+    # Will use invalid.python_checker for flakes
+    outlines = [view.full_line(view.text_point(m['lineno'], 0))
+                for m in messages if m['type'] == 'flakes']
+    view.erase_regions('python_checker_outlines_flakes')
+    view.add_regions('python_checker_outlines_flakes',
         outlines,
-        'keyword', flags=
-        sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED)
+        'invalid.python_checker.outline', icon='circle',
+        flags=sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED)
 
     underlines = []
     for m in messages:
@@ -112,7 +124,7 @@ def check_and_mark(view):
     view.erase_regions('python_checker_underlines')
     view.add_regions('python_checker_underlines',
         underlines,
-        'keyword', flags=
+        'keyword.python_checker.underline', flags=
         sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_OUTLINED)
 
     line_messages = {}
@@ -153,8 +165,10 @@ def parse_messages(checker_output):
     messages = []
     for i, line in enumerate(checker_output.splitlines()):
         if pep8_re.match(line):
+            mesg_type = 'pep8'
             lineno, col, text = pep8_re.match(line).groups()
         elif pyflakes_re.match(line):
+            mesg_type = 'flakes'
             lineno, text = pyflakes_re.match(line).groups()
             col = 1
             if text == 'invalid syntax':
@@ -163,7 +177,8 @@ def parse_messages(checker_output):
             continue
         messages.append({'lineno': int(lineno) - 1,
                          'col': int(col) - 1,
-                         'text': text})
+                         'text': text,
+                         'type': mesg_type})
 
     return messages
 

From da48c04175aa172f39cbfe69cb6ba1dd407277ca Mon Sep 17 00:00:00 2001
From: gcarvalho 
Date: Mon, 11 Feb 2013 18:30:00 +0000
Subject: [PATCH 3/8] Update README.markdown

---
 README.markdown | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.markdown b/README.markdown
index ab05d55..d98f127 100644
--- a/README.markdown
+++ b/README.markdown
@@ -44,7 +44,7 @@ invalid.python_checker.outline: outline around lines with pyflakes flags
 keyword.python_checker.underline: column-specific mark for flags which provide it
 
 An example used with a Solarized theme:
-
+```xml
     
         name
         invalid.python_checker.outline
@@ -82,7 +82,7 @@ An example used with a Solarized theme:
             #FF0000
         
     
-
+```
 
 ## Why not sublimelint
 

From 573a2addc8043b37cd255743bb3ff3114cd5ba79 Mon Sep 17 00:00:00 2001
From: Gustavo Carvalho 
Date: Thu, 14 Feb 2013 15:13:01 +0000
Subject: [PATCH 4/8] On-the-fly checking for some checkers, used with
 pyflakes. Adapted messaging system with some improvements.

---
 README.markdown   |  11 ++-
 python_checker.py | 192 +++++++++++++++++++++++++++++-----------------
 2 files changed, 128 insertions(+), 75 deletions(-)

diff --git a/README.markdown b/README.markdown
index d98f127..418fd08 100644
--- a/README.markdown
+++ b/README.markdown
@@ -13,11 +13,13 @@ Go to your Packages dir (Sublime Text 2 -> Preferences -> Browse Packages). Clon
 Go to sublimetext_python_checker/ and create file local_settings.py with list of your preferred checkers:
 
 
-    CHECKERS = [('/Users/vorushin/.virtualenvs/checkers/bin/pep8', []),
-                ('/Users/vorushin/.virtualenvs/checkers/bin/pyflakes', [])]
+    CHECKERS = [('/Users/vorushin/.virtualenvs/checkers/bin/pep8', [], False),
+                ('/Users/vorushin/.virtualenvs/checkers/bin/pyflakes', [], False)]
 
-First parameter is path to command, second - optional list of arguments. If you want to disable line length checking in pep8, set second parameter to ['--ignore=E501']. +First parameter is path to command. +Second - optional list of arguments, If you want to disable line length checking in pep8, set second parameter to ['--ignore=E501']. +third - do you want to run this checker on each change. Only works with pyflakes, ATM. You can also set syntax checkers using sublimetext settings (per file, global, per project, ...): @@ -27,7 +29,8 @@ per project, ...): "python_syntax_checkers": [ ["/usr/bin/pep8", ["--ignore=E501,E128,E221"] ] - ] + ], + false }
Both "CHECKERS local_settings" and sublime text settings will be used, diff --git a/python_checker.py b/python_checker.py index 0d0066b..c5afa6b 100644 --- a/python_checker.py +++ b/python_checker.py @@ -6,6 +6,25 @@ import sublime import sublime_plugin + +DEFAULT_CHECKERS = [ + [ + "/usr/bin/pep8", + [ + "--ignore=" + ], + False, + "keyword.python_checker.outline" + ], + [ + "/usr/bin/pyflakes", + [ + ], + True, + "invalid.python_checker.outline" + ] + ] + try: from local_settings import CHECKERS except ImportError as e: @@ -37,7 +56,11 @@ global view_messages +global view_lines +global view_totals view_messages = {} +view_lines = {} +view_totals = {} class PythonCheckerCommand(sublime_plugin.EventListener): @@ -45,97 +68,126 @@ def on_activated(self, view): signal.signal(signal.SIGALRM, lambda s, f: check_and_mark(view)) signal.alarm(1) + def on_modified(self, view): + signal.signal(signal.SIGALRM, lambda s, f: check_and_mark(view, True)) + signal.alarm(1) + def on_deactivated(self, view): signal.alarm(0) def on_post_save(self, view): - check_and_mark(view) + signal.signal(signal.SIGALRM, lambda s, f: check_and_mark(view)) + signal.alarm(1) + + def on_close(self, view): + global view_messages + view_messages[view.id()].clear() + del view_messages[view.id()] + del view_lines[view.id()] + view.erase_status('python_checker') def on_selection_modified(self, view): global view_messages lineno = view.rowcol(view.sel()[0].end())[0] - if view.id() in view_messages and lineno in view_messages[view.id()]: - _message = (view_messages[view.id()][lineno]).decode('utf-8') - view.set_status('python_checker', _message) + _message = '' + if view.id() in view_lines and lineno in view_lines[view.id()]: + for basename, basename_lines in view_messages[view.id()].items(): + if lineno in basename_lines: + _message += (basename_lines[lineno]).decode('utf-8') + ';' + if _message or view_totals.get(view.id(), ''): + view.set_status('python_checker', '{} ({} )'.format(_message, view_totals.get(view.id(), ''))) else: - view.erase_status('python_checker') + view.set_status('python_checker', 'OK') -def check_and_mark(view): +def check_and_mark(view, is_buffer=False): if not 'python' in view.settings().get('syntax').lower(): return - if not view.file_name(): # we check files (not buffers) + if not view.file_name() and not is_buffer: return checkers = view.settings().get('python_syntax_checkers', []) + checkers_basenames = [ + os.path.basename(checker[0]) for checker in checkers] - # Append "local_settings.CHECKERS" to checkers from settings + # TODO: improve settings and default handling + # TODO: just use the checkers in path if 'CHECKERS' in globals(): - checkers_basenames = [ - os.path.basename(checker[0]) for checker in checkers] checkers.extend([checker for checker in CHECKERS if os.path.basename(checker[0]) not in checkers_basenames]) - - messages = [] - for checker, args in checkers: - checker_messages = [] - try: - p = Popen([checker, view.file_name()] + args, stdout=PIPE, - stderr=PIPE) - stdout, stderr = p.communicate(None) - checker_messages += parse_messages(stdout) - checker_messages += parse_messages(stderr) - for line in checker_messages: - print ("[%s] %s:%s:%s %s" % ( - checker.split('/')[-1], view.file_name(), - line['lineno'] + 1, line['col'] + 1, line['text'])) - messages += checker_messages - except OSError: - print ("Checker could not be found:", checker) - except Exception as e: - print ("Generic error while running checker:", e) - - view.erase_regions('python_checker_outlines') - - # Separate scopes for pep8 and flakes messages - # Will use keyword.python_checker for pep8 - outlines = [view.full_line(view.text_point(m['lineno'], 0)) - for m in messages if m['type'] == 'pep8'] - view.erase_regions('python_checker_outlines_pep8') - view.add_regions('python_checker_outlines_pep8', - outlines, - 'keyword.python_checker.outline', icon='circle', - flags=sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED) - # Will use invalid.python_checker for flakes - outlines = [view.full_line(view.text_point(m['lineno'], 0)) - for m in messages if m['type'] == 'flakes'] - view.erase_regions('python_checker_outlines_flakes') - view.add_regions('python_checker_outlines_flakes', - outlines, - 'invalid.python_checker.outline', icon='circle', - flags=sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED) - - underlines = [] - for m in messages: - if m['col']: - a = view.text_point(m['lineno'], m['col']) - underlines.append(sublime.Region(a, a)) - - view.erase_regions('python_checker_underlines') - view.add_regions('python_checker_underlines', - underlines, - 'keyword.python_checker.underline', flags= - sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_OUTLINED) + checkers_basenames = [ + os.path.basename(checker[0]) for checker in checkers] + checkers.extend([checker for checker in DEFAULT_CHECKERS + if os.path.basename(checker[0]) not in checkers_basenames]) line_messages = {} - for m in (m for m in messages if m['text']): - if m['lineno'] in line_messages: - line_messages[m['lineno']] += b';' + m['text'] - else: - line_messages[m['lineno']] = m['text'] - + for checker, args, run_in_buffer, checker_scope in checkers: + checker_messages = [] + line_messages = {} + if not is_buffer or is_buffer and run_in_buffer: + try: + if not is_buffer: + p = Popen([checker, view.file_name()] + args, stdout=PIPE, + stderr=PIPE) + stdout, stderr = p.communicate(None) + else: + p = Popen([checker] + args, stdin=PIPE, stdout=PIPE, + stderr=PIPE) + stdout, stderr = p.communicate(bytes(view.substr(sublime.Region(0, view.size())), 'utf-8')) + checker_messages += parse_messages(stdout) + checker_messages += parse_messages(stderr) + except OSError: + print ("Checker could not be found:", checker) + except Exception as e: + print ("Generic error while running checker:", e) + else: + basename = os.path.basename(checker) + outline_name = 'python_checker_outlines_{}'.format(basename) + print("outline name {}".format(outline_name)) + underline_name = 'python_checker_underlines_{}'.format(basename) + outline_scope = checker_scope + outlines = [] + underlines = [] + for m in checker_messages: + print ("[%s] %s:%s:%s %s" % ( + checker.split('/')[-1], view.file_name(), + m['lineno'] + 1, m['col'] + 1, m['text'])) + outlines.append(view.full_line(view.text_point(m['lineno'], 0))) + if m['col']: + a = view.text_point(m['lineno'], m['col']) + underlines.append(sublime.Region(a, a)) + if m['text']: + if m['lineno'] in line_messages: + line_messages[m['lineno']] += b';' + m['text'] + else: + line_messages[m['lineno']] = m['text'] + view.erase_regions(outline_name) + view.add_regions(outline_name, outlines, outline_scope, + icon='circle', + flags=sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED) + view.erase_regions(underline_name) + view.add_regions(underline_name, underlines, + 'keyword.python_checker.underline', flags= + sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_OUTLINED) + checker_messages.clear() + add_messages(view.id(), basename, line_messages) + + +def add_messages(view_id, basename, basename_lines): global view_messages - view_messages[view.id()] = line_messages + global view_lines + global view_totals + if view_id not in view_messages: + view_messages[view_id] = {} + view_messages[view_id][basename] = basename_lines + lines = set() + view_totals[view_id] = '' + for basename, basename_lines in view_messages[view_id].items(): + lines.update(basename_lines.keys()) + if basename_lines.keys(): + view_totals[view_id] += ' {}:{}'.format(basename, len(basename_lines.keys())) + + view_lines[view_id] = lines def parse_messages(checker_output): @@ -165,10 +217,8 @@ def parse_messages(checker_output): messages = [] for i, line in enumerate(checker_output.splitlines()): if pep8_re.match(line): - mesg_type = 'pep8' lineno, col, text = pep8_re.match(line).groups() elif pyflakes_re.match(line): - mesg_type = 'flakes' lineno, text = pyflakes_re.match(line).groups() col = 1 if text == 'invalid syntax': @@ -178,7 +228,7 @@ def parse_messages(checker_output): messages.append({'lineno': int(lineno) - 1, 'col': int(col) - 1, 'text': text, - 'type': mesg_type}) + }) return messages From 13eed0b573409a8877759d57ff8c8b3394ef86d3 Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Fri, 15 Feb 2013 14:58:38 +0000 Subject: [PATCH 5/8] Use new async events for on-the-fly checking. Will now work with pep8 --- python_checker.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/python_checker.py b/python_checker.py index c5afa6b..357a089 100644 --- a/python_checker.py +++ b/python_checker.py @@ -1,6 +1,5 @@ import os import re -import signal from subprocess import Popen, PIPE import sublime @@ -64,20 +63,14 @@ class PythonCheckerCommand(sublime_plugin.EventListener): - def on_activated(self, view): - signal.signal(signal.SIGALRM, lambda s, f: check_and_mark(view)) - signal.alarm(1) + def on_activated_async(self, view): + check_and_mark(view) - def on_modified(self, view): - signal.signal(signal.SIGALRM, lambda s, f: check_and_mark(view, True)) - signal.alarm(1) + def on_modified_async(self, view): + check_and_mark(view, True) - def on_deactivated(self, view): - signal.alarm(0) - - def on_post_save(self, view): - signal.signal(signal.SIGALRM, lambda s, f: check_and_mark(view)) - signal.alarm(1) + def on_post_save_async(self, view): + check_and_mark(view) def on_close(self, view): global view_messages From 6793e4c6610f94c5f76acf6202de0dfa8b778d9b Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Fri, 15 Feb 2013 16:15:33 +0000 Subject: [PATCH 6/8] reduce debug messages --- python_checker.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python_checker.py b/python_checker.py index 357a089..e8d95f9 100644 --- a/python_checker.py +++ b/python_checker.py @@ -136,15 +136,14 @@ def check_and_mark(view, is_buffer=False): else: basename = os.path.basename(checker) outline_name = 'python_checker_outlines_{}'.format(basename) - print("outline name {}".format(outline_name)) underline_name = 'python_checker_underlines_{}'.format(basename) outline_scope = checker_scope outlines = [] underlines = [] for m in checker_messages: - print ("[%s] %s:%s:%s %s" % ( - checker.split('/')[-1], view.file_name(), - m['lineno'] + 1, m['col'] + 1, m['text'])) + # print ("[%s] %s:%s:%s %s" % ( + # checker.split('/')[-1], view.file_name(), + # m['lineno'] + 1, m['col'] + 1, m['text'])) outlines.append(view.full_line(view.text_point(m['lineno'], 0))) if m['col']: a = view.text_point(m['lineno'], m['col']) @@ -180,6 +179,7 @@ def add_messages(view_id, basename, basename_lines): if basename_lines.keys(): view_totals[view_id] += ' {}:{}'.format(basename, len(basename_lines.keys())) + print (view_totals[view_id]) view_lines[view_id] = lines From e6de946fafe76edb929882689026ee32ddf3761d Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Wed, 27 Feb 2013 14:17:22 +0000 Subject: [PATCH 7/8] followed some pylint suggestions --- python_checker.py | 80 ++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/python_checker.py b/python_checker.py index e8d95f9..2ed7625 100644 --- a/python_checker.py +++ b/python_checker.py @@ -21,7 +21,17 @@ ], True, "invalid.python_checker.outline" - ] + ], + [ + "/usr/local/bin/pylint", + [ + "-fparseable", + "-iy", + "-d C0301,C0302,C0111,C0103,R0911,R0912,R0913,R0914,R0915,W0142" + ], + False, + "comment.python_checker.outline" + ], ] try: @@ -54,51 +64,52 @@ ''') -global view_messages -global view_lines -global view_totals -view_messages = {} -view_lines = {} -view_totals = {} +VIEW_MESSAGES = {} +VIEW_LINES = {} +VIEW_TOTALS = {} class PythonCheckerCommand(sublime_plugin.EventListener): def on_activated_async(self, view): - check_and_mark(view) + if view.id() not in VIEW_LINES: # TODO use change_count() + check_and_mark(view) def on_modified_async(self, view): + if view.id() in VIEW_LINES: + del VIEW_LINES[view.id()] check_and_mark(view, True) def on_post_save_async(self, view): check_and_mark(view) def on_close(self, view): - global view_messages - view_messages[view.id()].clear() - del view_messages[view.id()] - del view_lines[view.id()] + if view.id() in VIEW_MESSAGES: + VIEW_MESSAGES[view.id()].clear() + del VIEW_MESSAGES[view.id()] + del VIEW_LINES[view.id()] view.erase_status('python_checker') def on_selection_modified(self, view): - global view_messages - lineno = view.rowcol(view.sel()[0].end())[0] + lineno = view.rowcol(view.sel()[0].begin())[0] _message = '' - if view.id() in view_lines and lineno in view_lines[view.id()]: - for basename, basename_lines in view_messages[view.id()].items(): + if view.id() in VIEW_LINES and lineno in VIEW_LINES[view.id()]: + for _, basename_lines in VIEW_MESSAGES[view.id()].items(): if lineno in basename_lines: _message += (basename_lines[lineno]).decode('utf-8') + ';' - if _message or view_totals.get(view.id(), ''): - view.set_status('python_checker', '{} ({} )'.format(_message, view_totals.get(view.id(), ''))) + if _message or VIEW_TOTALS.get(view.id(), ''): + view.set_status('python_checker', '{} ({} )'.format(_message, VIEW_TOTALS.get(view.id(), ''))) else: view.set_status('python_checker', 'OK') def check_and_mark(view, is_buffer=False): - if not 'python' in view.settings().get('syntax').lower(): + if view.settings().get('syntax', None) and \ + not 'python' in view.settings().get('syntax', '').lower(): return if not view.file_name() and not is_buffer: return - + mesg_quick = '' if is_buffer else '(everything)' + view.set_status('python_checker_running', 'Checking Python {}...'.format(mesg_quick)) checkers = view.settings().get('python_syntax_checkers', []) checkers_basenames = [ os.path.basename(checker[0]) for checker in checkers] @@ -120,8 +131,11 @@ def check_and_mark(view, is_buffer=False): if not is_buffer or is_buffer and run_in_buffer: try: if not is_buffer: - p = Popen([checker, view.file_name()] + args, stdout=PIPE, - stderr=PIPE) + params = [checker, view.file_name()] + for arg in args: + params.insert(1, arg) + p = Popen(params, stdout=PIPE, + stderr=PIPE) stdout, stderr = p.communicate(None) else: p = Popen([checker] + args, stdin=PIPE, stdout=PIPE, @@ -163,24 +177,24 @@ def check_and_mark(view, is_buffer=False): sublime.DRAW_EMPTY_AS_OVERWRITE | sublime.DRAW_OUTLINED) checker_messages.clear() add_messages(view.id(), basename, line_messages) + view.erase_status('python_checker_running') def add_messages(view_id, basename, basename_lines): - global view_messages - global view_lines - global view_totals - if view_id not in view_messages: - view_messages[view_id] = {} - view_messages[view_id][basename] = basename_lines + if view_id not in VIEW_MESSAGES: + VIEW_MESSAGES[view_id] = {} + VIEW_MESSAGES[view_id][basename] = basename_lines lines = set() - view_totals[view_id] = '' - for basename, basename_lines in view_messages[view_id].items(): + VIEW_TOTALS[view_id] = '' + for basename, basename_lines in VIEW_MESSAGES[view_id].items(): lines.update(basename_lines.keys()) if basename_lines.keys(): - view_totals[view_id] += ' {}:{}'.format(basename, len(basename_lines.keys())) + VIEW_TOTALS[view_id] += ' {}:{}'.format(basename, len(basename_lines.keys())) - print (view_totals[view_id]) - view_lines[view_id] = lines + if lines: + VIEW_LINES[view_id] = lines + else: + VIEW_LINES[view_id] = 'OK' def parse_messages(checker_output): From 6e0a4b47175632c073bb989dc76cd44c662f9b87 Mon Sep 17 00:00:00 2001 From: Gustavo Carvalho Date: Mon, 4 Mar 2013 14:46:04 +0000 Subject: [PATCH 8/8] No more TypeErrors --- python_checker.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python_checker.py b/python_checker.py index 2ed7625..dbe5d0c 100644 --- a/python_checker.py +++ b/python_checker.py @@ -193,8 +193,6 @@ def add_messages(view_id, basename, basename_lines): if lines: VIEW_LINES[view_id] = lines - else: - VIEW_LINES[view_id] = 'OK' def parse_messages(checker_output):