diff options
| author | Igor Gnatenko <ignatenko@src.gnome.org> | 2015-01-10 14:46:27 (GMT) |
|---|---|---|
| committer | Igor Gnatenko <ignatenko@src.gnome.org> | 2015-01-10 15:53:27 (GMT) |
| commit | eb26d525c5cd4fc7320c6ab7baa5c4e7f8b377a6 (patch) | |
| tree | d703490e77bcb69154c7d5d26ff657c3bc605a82 | |
| parent | 051b058a4153cdf717e7c172f434a1cbcb8bd937 (diff) | |
| download | gnome-code-assistance-eb26d525c5cd4fc7320c6ab7baa5c4e7f8b377a6.zip gnome-code-assistance-eb26d525c5cd4fc7320c6ab7baa5c4e7f8b377a6.tar.xz | |
[backends/python] check via pylint
https://bugzilla.gnome.org/show_bug.cgi?id=742658
| -rw-r--r-- | README | 1 | ||||
| -rw-r--r-- | backends/python/__init__.py | 51 |
2 files changed, 52 insertions, 0 deletions
@@ -185,6 +185,7 @@ Dependencies : python, python-dbus, python-simplejson ### Python Dependencies : python, python-dbus +Optional dependencies : pylint (enabled only if you will pass "pylint" in "options" to dbus service) ### Ruby Dependencies : ruby, ruby-dbus diff --git a/backends/python/__init__.py b/backends/python/__init__.py index eaaa308..9476d6f 100644 --- a/backends/python/__init__.py +++ b/backends/python/__init__.py @@ -1,6 +1,7 @@ # gnome code assistance python backend # Copyright (C) 2013 Jesse van den Kieboom <jessevdk@gnome.org> # Copyright (C) 2014 Elad Alfassa <elad@fedoraproject.org> +# Copyright (C) 2015 Igor Gnatenko <ignatenko@src.gnome.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,8 +21,50 @@ import ast import subprocess import re +try: + from pylint import lint + from pylint.reporters.text import TextReporter +except ImportError: + pass + from gnome.codeassistance import transport, types +class PyLint(object): + def __init__(self, data_path): + self.diagnostics = [] + self.data_path = data_path + + def write(self, st): + if st != "\n" and not st.startswith("*"): + result = st.split(":") + col = int(result[1]) + 1 + loc = types.SourceLocation(line=result[0], column=col) + + """ + * (C) convention, for programming standard violation + * (R) refactor, for bad code smell + * (W) warning, for python specific problems + * (E) error, for much probably bugs in the code + * (F) fatal, if an error occurred which prevented pylint from doing + further processing. + """ + if result[2] == "C" or result[2] == "R" or result[2] == "W": + severity = types.Diagnostic.Severity.INFO + else: + severity = types.Diagnostic.Severity.ERROR + + self.diagnostics.append( + types.Diagnostic(severity=severity, + locations=[loc.to_range()], + message=result[3])) + + def run(self): + args = [self.data_path, "-r", "n", + "--msg-template='{line}:{column}:{C}:{msg_id} {msg}'"] + lint.Run(args, reporter=TextReporter(self), exit=False) + return self.diagnostics + + class Service(transport.Service): language = 'python' @@ -54,6 +97,14 @@ class Service(transport.Service): # PEP8 is not installed. Do nothing. pass + if "pylint" in options and options["pylint"]: + pylint = PyLint(doc.data_path) + diagnostics = pylint.run() + + for diag in diagnostics: + doc.diagnostics.append(diag) + + class Document(transport.Document, transport.Diagnostics): pass |
