Beispiel #1
0
def checkPyflakes(currentDocument=None, refresh=True):
    """Check the pyflakes errors of the document"""
    if not canCheckDocument(currentDocument):
        return
    if refresh:
        checkAll.f(currentDocument, ['checkPyflakes'],
                   exclude_all=not currentDocument)
    move_cursor = not currentDocument
    currentDocument = currentDocument or kate.activeDocument()

    path = currentDocument.url().path()
    mark_key = '%s-pyflakes' % path

    text = currentDocument.text()
    errors = pyflakes(text, path)
    errors_to_show = []

    if len(errors) == 0:
        showOk(i18n("Pyflakes Ok"))
        return

    # Prepare errors found for painting
    for error in errors:
        error_to_show = {
            "message": error.message % error.message_args,
            "line": error.lineno,
        }
        if getattr(error, 'col', None) is not None:
            error_to_show['column'] = error.col + 1
        errors_to_show.append(error_to_show)

    showErrors(i18n('Pyflakes Errors:'), errors_to_show,
               mark_key, currentDocument,
               move_cursor=move_cursor)
def checkPyflakes(currentDocument=None, refresh=True):
    """Check the pyflakes errors of the document"""
    if not canCheckDocument(currentDocument):
        return
    if refresh:
        checkAll.f(currentDocument, ['checkPyflakes'],
                 exclude_all=not currentDocument)
    move_cursor = not currentDocument
    currentDocument = currentDocument or kate.activeDocument()

    path = unicode(currentDocument.url().path())
    mark_key = '%s-pyflakes' % path

    text = unicode(currentDocument.text())
    errors = pyflakes(text.encode('utf-8', 'ignore'), path)
    errors_to_show = []

    if len(errors) == 0:
        showOk("Pyflakes Ok")
        return

    # Prepare errors found for painting
    for error in errors:
        errors_to_show.append({
            "message": error.message % error.message_args,
            "line": error.lineno,
            })

    showErrors('Pyflakes Errors:', errors_to_show,
                mark_key, currentDocument,
                move_cursor=move_cursor)
Beispiel #3
0
def checkPep8(currentDocument=None, refresh=True):
    """Check the pep8 errors of the document"""
    if not canCheckDocument(currentDocument):
        return
    if refresh:
        checkAll.f(currentDocument, ['checkPep8'],
                   exclude_all=not currentDocument)
    move_cursor = not currentDocument
    currentDocument = currentDocument or kate.activeDocument()

    if currentDocument.isModified():
        saveFirst()
        return
    path = currentDocument.url().path()
    if not path:
        saveFirst()
        return
    mark_key = '%s-pep8' % currentDocument.url().path()
    # Check the file for errors with PEP8
    sys.argv = [path]
    pep8.process_options([path])
    python_utils_conf = kate.configuration.root.get('python_utils', {})
    ignore_pep8_errors = python_utils_conf.get(_IGNORE_PEP8_ERRORS, DEFAULT_IGNORE_PEP8_ERRORS)
    if ignore_pep8_errors:
        ignore_pep8_errors = ignore_pep8_errors.split(",")
    else:
        ignore_pep8_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:
        showOk(i18n('Pep8 Ok'))
        return
    errors_to_show = []
    # Paint errors found
    for error in errors:
        errors_to_show.append({
            "line": error[0],
            "column": error[1] + 1,
            "message": error[3],
        })
    showErrors(i18n('Pep8 Errors:'),
               errors_to_show,
               mark_key,
               currentDocument,
               move_cursor=move_cursor)
def checkPep8(currentDocument=None, refresh=True):
    """Check the pep8 errors of the document"""
    if not canCheckDocument(currentDocument):
        return
    if refresh:
        checkAll.f(currentDocument, ['checkPep8'],
                   exclude_all=not currentDocument)
    move_cursor = not currentDocument
    currentDocument = currentDocument or kate.activeDocument()

    if currentDocument.isModified():
        saveFirst()
        return
    path = unicode(currentDocument.url().path())
    if not path:
        saveFirst()
        return
    mark_key = '%s-pep8' % unicode(currentDocument.url().path())
    # Check the file for errors with PEP8
    sys.argv = [path]
    pep8.process_options([path])
    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:
        showOk('Pep8 Ok')
        return
    errors_to_show = []
    # Paint errors found
    for error in errors:
        errors_to_show.append({
            "line": error[0],
            "column": error[1] + 1,
            "message": error[3],
        })
    showErrors('Pep8 Errors:',
               errors_to_show,
               mark_key,
               currentDocument,
               move_cursor=move_cursor)
Beispiel #5
0
def parseCode(doc=None, refresh=True):
    """Check the syntax errors of the document"""
    if not canCheckDocument(doc):
        return
    if refresh:
        checkAll.f(doc, ['parseCode'], exclude_all=not doc)
    move_cursor = not doc
    doc = doc or kate.activeDocument()
    text = doc.text()
    text = text.encode('utf-8', 'ignore')
    mark_key = '%s-parse-python' % doc.url().path()
    try:
        parse(text)
        showOk(i18n('Parse code Ok'))
    except SyntaxError as e:
        error = {}
        error['text'] = e.text
        error['line'] = e.lineno
        showErrors(i18n('Parse code Errors:'), [error], mark_key, doc,
                   move_cursor=move_cursor)
def parseCode(doc=None, refresh=True):
    """Check the syntax errors of the document"""
    if not canCheckDocument(doc):
        return
    if refresh:
        checkAll.f(doc, ['parseCode'], exclude_all=not doc)
    move_cursor = not doc
    doc = doc or kate.activeDocument()
    text = unicode(doc.text())
    text = text.encode('utf-8', 'ignore')
    mark_key = '%s-parse-python' % unicode(doc.url().path())
    try:
        compiler.parse(text)
        showOk('Parse code Ok')
    except SyntaxError, e:
        error = {}
        error['text'] = e.text
        error['line'] = e.lineno
        showErrors('Parse code Errors:', [error],
                   mark_key,
                   doc,
                   move_cursor=move_cursor)