Skip to content

Instantly share code, notes, and snippets.

@coryalder
Forked from jshell/BBFlakes.py
Created August 10, 2012 20:46

Revisions

  1. coryalder revised this gist Aug 11, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion BBFlakes.py
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    original script: https://gist.github.com/1157742
    Port for
    Ported to work with:
    - flake8 --version: 1.4 (pyflakes: 0.5.0, pep8: 1.2)
    - python --version: Python 2.7.2
    BBEdit 10.1.2 (MAS)
  2. coryalder revised this gist Aug 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion BBFlakes.py
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@
    pyflakes = "/usr/local/bin/flake8"
    line_length = 256 # I don't like PEP8 warning be about long lines.

    stdout, stderr = Popen([pyflakes, doc_file, "--max-line-length="+str(line_length)], stdout=PIPE, stderr=PIPE).communicate()
    stdout, stderr = Popen([pyflakes, doc_file, "--max-line-length=" + str(line_length)], stdout=PIPE, stderr=PIPE).communicate()
    output = stdout if stdout else stderr

    if not output:
  3. coryalder revised this gist Aug 10, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions BBFlakes.py
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #!/usr/bin/env python
    """
    A quick script to install into your `Application Support/BBEdit/Scripts` folder.
    This runs PyFlakes (requires PyFlakes to be installed at `/usr/local/bin` -
    try ``/usr/bin/easy_install-2.6 pyflakes==0.4.0``) and reformats the results
    This runs flake8 (requires flake8 to be installed at `/usr/local/bin` -
    try ``pip install flake8``) 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
    I've bound this to control-shift-l. You must save your Python file first before
    running the check.
    original script: https://gist.github.com/1157742
    @@ -29,7 +29,7 @@

    doc_file = os.environ['BB_DOC_PATH']
    pyflakes = "/usr/local/bin/flake8"
    line_length = 256
    line_length = 256 # I don't like PEP8 warning be about long lines.

    stdout, stderr = Popen([pyflakes, doc_file, "--max-line-length="+str(line_length)], stdout=PIPE, stderr=PIPE).communicate()
    output = stdout if stdout else stderr
  4. coryalder revised this gist Aug 10, 2012. 1 changed file with 18 additions and 7 deletions.
    25 changes: 18 additions & 7 deletions BBFlakes.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/usr/bin/env python2.6
    #!/usr/bin/env python
    """
    A quick script to install into your `Application Support/BBEdit/Scripts` folder.
    This runs PyFlakes (requires PyFlakes to be installed at `/usr/local/bin` -
    @@ -8,6 +8,14 @@
    I've bound this to control-shift-V. You must save your Python file first before
    running the check.
    original script: https://gist.github.com/1157742
    Port for
    - flake8 --version: 1.4 (pyflakes: 0.5.0, pep8: 1.2)
    - python --version: Python 2.7.2
    BBEdit 10.1.2 (MAS)
    Here: https://gist.github.com/3317713
    """
    from __future__ import print_function
    import os
    @@ -20,22 +28,25 @@
    sys.exit(0)

    doc_file = os.environ['BB_DOC_PATH']
    pyflakes = "/usr/local/bin/pyflakes"
    pyflakes = "/usr/local/bin/flake8"
    line_length = 256

    stdout, stderr = Popen([pyflakes, doc_file], stdout=PIPE, stderr=PIPE).communicate()
    stdout, stderr = Popen([pyflakes, doc_file, "--max-line-length="+str(line_length)], 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>.*$)')
    line_format = re.compile('(?P<path>[^:]+):(?P<line>\d+):(?P<character>\d+:)?\s(?P<message>.*$)')
    for line in output.splitlines():
    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)
    outstr = ""
    if groups['character']:
    outstr = "At column " + groups['character'] + " "
    print(outstr + groups['message'], file=sys.stderr)
    print('^', file=sys.stderr)

    sys.exit(1)
    sys.exit(1)
  5. @jshell jshell revised this gist Jul 10, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion BBFlakes.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    #!/usr/bin/env python2.6
    """
    A quick script to install into your `Application Support/BBEdit/Scripts` folder.
  6. @jshell jshell revised this gist Jul 10, 2012. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions BBFlakes.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@

    #!/usr/bin/env python2.6
    """
    A quick script to install into your `Application Support/BBEdit/Scripts` folder.
    @@ -15,14 +16,15 @@
    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"

    out, err = Popen([pyflakes, doc_file], stdout=PIPE, stderr=PIPE).communicate()
    if out:
    output = out
    else:
    output = err
    stdout, stderr = Popen([pyflakes, doc_file], stdout=PIPE, stderr=PIPE).communicate()
    output = stdout if stdout else stderr

    if not output:
    sys.exit(0)
  7. @jshell jshell created this gist Aug 19, 2011.
    40 changes: 40 additions & 0 deletions BBFlakes.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/env python2.6
    """
    A quick script to install into your `Application Support/BBEdit/Scripts` folder.
    This runs PyFlakes (requires PyFlakes to be installed at `/usr/local/bin` -
    try ``/usr/bin/easy_install-2.6 pyflakes==0.4.0``) 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

    doc_file = os.environ['BB_DOC_PATH']
    pyflakes = "/usr/local/bin/pyflakes"

    out, err = Popen([pyflakes, doc_file], stdout=PIPE, stderr=PIPE).communicate()
    if out:
    output = out
    else:
    output = err

    if not output:
    sys.exit(0)

    line_format = re.compile('(?P<path>[^:]+):(?P<line>\d+):\s(?P<message>.*$)')
    for line in output.splitlines():
    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)
    print('^', file=sys.stderr)

    sys.exit(1)