Created
January 9, 2019 07:20
-
-
Save thendrix/97707f421c1b4b088b6b1e5c3e7d78b4 to your computer and use it in GitHub Desktop.
Sublime Text 3 save listener to auto run pyflakes (lint) python files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sublime | |
import sublime_plugin | |
import webbrowser | |
REG_RENAME = re.compile("\.(py)$") | |
EXT = re.compile(".*\.(py)$") | |
COMMAND = "pyflakes3 " | |
def is_python_file(file_name): | |
return EXT.match(file_name) is not None | |
class PyflakesSaveListener(sublime_plugin.EventListener): | |
def on_post_save(self, view): | |
file_name = view.file_name() | |
if is_python_file(file_name): | |
sublime.status_message("pyflakes3 linting... " + file_name) | |
self.run_shell_command(view, COMMAND + " " + file_name) | |
def run_shell_command(self, view, command): | |
if not command: | |
return False | |
view.window().run_command("exec", { | |
"cmd": [command], | |
"shell": True, | |
"quiet": True | |
}) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment