-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.py
32 lines (30 loc) · 1.2 KB
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sublime
import sublime_plugin
import subprocess
import os
class Pep8Command(sublime_plugin.TextCommand):
"""pep8 command"""
def run(self, view):
if self.view.is_dirty():
sublime.message_dialog("Please save the file")
else:
filename = self.view.file_name()
if filename is None:
sublime.message_dialog('Wirte some code, save it and then run \
this command')
return
name, ext = os.path.splitext(filename)
if ext == ".py":
try:
p = subprocess.Popen(['pep8', str(filename)],
stdout=subprocess.PIPE)
(output, _) = p.communicate()
output = output.decode('utf-8')
if output == "" or output is None:
sublime.message_dialog('No pep8 errors found.')
else:
sublime.message_dialog(output)
except subprocess.CalledProcessError as e:
sublime.message_dialog(str(e.output))
else:
sublime.message_dialog("This is not a Python file")