Skip to content
Browse files

Now works from pypi, Improvement to pep8 checker

  • Loading branch information...
1 parent 84c410f commit 31814347a2c665de819a8abefc07fa4291d65610 @goinnn committed Mar 11, 2013
Showing with 70 additions and 39 deletions.
  1. +7 −0 CHANGES.rst
  2. +4 −2 MANIFEST.in
  3. +59 −37 kate_plugins/pyte_plugins/check_plugins/pep8_plugins.py
View
7 CHANGES.rst
@@ -1,6 +1,13 @@
Releases
========
+0.2.1 (2012-03-11)
+-------------------
+
+* This release is out of support
+* Now works from pypi
+* Improvement to pep8 checker
+
0.2.0 (2012-02-12)
-------------------
View
6 MANIFEST.in
@@ -1,7 +1,9 @@
include README.rst
include AUTHORS
-include CHANGES
+include CHANGES.rst
include *.py
recursive-include kate_plugins/jste_plugins *.py
+recursive-include kate_plugins/jste_plugins *.json
+recursive-include kate_plugins/jste_plugins *.json.gen
recursive-include kate_plugins/pyte_plugins *.py
-recursive-include kate_plugins/pyte_plugins/djte_plugins *.py
+recursive-include kate_plugins/pyte_plugins/djte_plugins *.py
View
96 kate_plugins/pyte_plugins/check_plugins/pep8_plugins.py
@@ -23,41 +23,66 @@
from pyte_plugins.check_plugins import commons
from pyte_plugins.check_plugins.check_all_plugins import checkAll
+OLD_PEP8_VERSIONS = ['1.0.1', '1.1', '1.2']
-class StoreErrorsChecker(pep8.Checker):
- def __init__(self, *args, **kwargs):
- super(StoreErrorsChecker, self).__init__(*args, **kwargs)
- self.error_list = []
+if pep8.__version__ not in OLD_PEP8_VERSIONS:
+ class KateReport(pep8.BaseReport):
- def report_error(self, line_number, offset, text, check):
- """
- Store the error
- """
- self.file_errors += 1
- self.error_list.append([line_number, offset, text[0:4], text])
+ def __init__(self, options):
+ super(KateReport, self).__init__(options)
+ self.error_list = []
+ self.ignore = options.ignore
- def get_errors(self):
- """
- Get the errors, and reset the checker
- """
- result, self.error_list = self.error_list, []
- self.file_errors = 0
- return result
+ def error(self, line_number, offset, text, check):
+ code = super(KateReport, self).error(line_number, offset, text, check)
+ self.error_list.append([line_number, offset, text[0:4], text])
+ return code
+
+ def get_errors(self):
+ """
+ Get the errors, and reset the checker
+ """
+ result, self.error_list = self.error_list, []
+ return result
+else:
+ class StoreErrorsChecker(pep8.Checker):
+
+ def __init__(self, *args, **kwargs):
+ super(StoreErrorsChecker, self).__init__(*args, **kwargs)
+ self.error_list = []
+
+ def report_error(self, line_number, offset, text, check):
+ """
+ Store the error
+ """
+ self.file_errors += 1
+ error_code = text[0:4]
+ if not pep8.ignore_code(error_code):
+ self.error_list.append([line_number, offset, error_code, text])
+
+ def get_errors(self):
+ """
+ Get the errors, and reset the checker
+ """
+ result, self.error_list = self.error_list, []
+ self.file_errors = 0
+ return result
def saveFirst():
kate.gui.popup('You must save the file first', 3,
- icon='dialog-warning', minTextWidth=200)
+ icon='dialog-warning', minTextWidth=200)
@kate.action(**KATE_ACTIONS['checkPep8'])
def checkPep8(currentDocument=None, refresh=True):
+ """Check the pep8 errors of the document"""
if not commons.canCheckDocument(currentDocument):
return
if refresh:
checkAll.f(currentDocument, ['checkPep8'],
- exclude_all=not currentDocument)
+ exclude_all=not currentDocument)
move_cursor = not currentDocument
currentDocument = currentDocument or kate.activeDocument()
@@ -72,31 +97,28 @@ def checkPep8(currentDocument=None, refresh=True):
# Check the file for errors with PEP8
sys.argv = [path]
pep8.process_options([path])
- checker = StoreErrorsChecker(path)
- checker.check_all()
- errors = checker.get_errors()
-
+ if pep8.__version__ in OLD_PEP8_VERSIONS:
+ checker = StoreErrorsChecker(path)
+ pep8.options.ignore = IGNORE_PEP8_ERRORS
+ checker.check_all()
+ errors = checker.get_errors()
+ else:
+ checker = pep8.Checker(path, reporter=KateReport, ignore=IGNORE_PEP8_ERRORS)
+ checker.check_all()
+ errors = checker.report.get_errors()
if len(errors) == 0:
commons.showOk('Pep8 Ok')
return
-
errors_to_show = []
- if IGNORE_PEP8_ERRORS:
- pep8.options.ignore.extend(IGNORE_PEP8_ERRORS)
- pep8.options.ignore = list(set(pep8.options.ignore))
# Paint errors found
for error in errors:
- if pep8.ignore_code(error[2]):
- continue
errors_to_show.append({
"line": error[0],
"column": error[1] + 1,
- "filename": path,
"message": error[3],
- })
- if errors_to_show:
- commons.showErrors('Pep8 Errors:', errors_to_show,
- mark_key, currentDocument,
- move_cursor=move_cursor)
- else:
- commons.showOk('Pep8 Ok')
+ })
+ commons.showErrors('Pep8 Errors:',
+ errors_to_show,
+ mark_key,
+ currentDocument,
+ move_cursor=move_cursor)

0 comments on commit 3181434

Please sign in to comment.
Something went wrong with that request. Please try again.