-
-
Save WallGeckoPoint/f4d20d91400c35b230b38e7d3df333d2 to your computer and use it in GitHub Desktop.
PyFlakes Script for BBEdit 12 / python3
This file contains 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
#!/usr/bin/env python3 | |
""" | |
Fork of the original BBFlakes script to make it run under python3/BBEdit 12. | |
A quick script to install into your `Application Support/BBEdit/Scripts` folder. | |
This runs PyFlakes (requires PyFlakes to be installed at `/usr/local/bin` and | |
reformats the results so that they show up in BBEdit's search results / error / | |
warnings window. Then the errors can be stepped through one at a time. | |
I've bound this to control-shift-V. You must save your Python file first before | |
running the check. | |
""" | |
from __future__ import print_function | |
import os | |
import re | |
import sys | |
from subprocess import Popen, PIPE | |
if os.environ['BB_DOC_LANGUAGE'].lower() != 'python': | |
# Bail out quietly if language isn't Python | |
sys.exit(0) | |
doc_file = os.environ['BB_DOC_PATH'] | |
pyflakes = "/usr/local/bin/pyflakes" | |
stdout, stderr = Popen([pyflakes, doc_file], stdout=PIPE, stderr=PIPE).communicate() | |
output = stdout if stdout else stderr | |
if not output: | |
sys.exit(0) | |
line_format = re.compile('(?P<path>[^:]+):(?P<line>\d+):\s(?P<message>.*$)') | |
for line in output.splitlines(): | |
line = line.decode('utf-8') | |
m = line_format.match(line) | |
if not m: | |
continue | |
groups = m.groupdict() | |
print('''File "{path}", line {line}'''.format(**groups), file=sys.stderr) | |
print(groups['message'], file=sys.stderr) | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment