[gnome-code-assistance] [backends/python] Check for PEP8 coding-style errors



commit a31c0d7dbcfa4b9956770d206aec56f2d04fb634
Author: Elad Alfassa <elad fedoraproject org>
Date:   Mon Mar 3 23:56:16 2014 +0200

    [backends/python] Check for PEP8 coding-style errors
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725621

 backends/python/__init__.py |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/backends/python/__init__.py b/backends/python/__init__.py
index f4d5634..eaaa308 100644
--- a/backends/python/__init__.py
+++ b/backends/python/__init__.py
@@ -1,5 +1,6 @@
 # gnome code assistance python backend
 # Copyright (C) 2013  Jesse van den Kieboom <jessevdk gnome org>
+# Copyright (C) 2014  Elad Alfassa <elad fedoraproject 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
@@ -16,6 +17,8 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 import ast
+import subprocess
+import re
 
 from gnome.codeassistance import transport, types
 
@@ -34,7 +37,22 @@ class Service(transport.Service):
             loc = types.SourceLocation(line=e.lineno, column=e.offset)
             severity = types.Diagnostic.Severity.ERROR
 
-            doc.diagnostics = [types.Diagnostic(severity=severity, locations=[loc.to_range()], 
message=e.msg)]
+            doc.diagnostics.append(types.Diagnostic(severity=severity, locations=[loc.to_range()], 
message=e.msg))
+
+        # PEP8 checks
+        try:
+            p = subprocess.Popen(['pep8', doc.data_path], stdout=subprocess.PIPE)
+            for line in iter(p.stdout.readline, ''):
+                if not line:
+                    break
+                line = line.decode()
+                result = re.search(':(\d*):(\d*): (.*)', line).groups()
+                loc = types.SourceLocation(line=result[0], column=result[1])
+                severity = types.Diagnostic.Severity.INFO
+                doc.diagnostics.append(types.Diagnostic(severity=severity, locations=[loc.to_range()], 
message=result[2]))
+        except FileNotFoundError:
+            # PEP8 is not installed. Do nothing.
+            pass
 
 class Document(transport.Document, transport.Diagnostics):
     pass


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]