Skip to content
Browse files

Now compatible with pyflakes 0.4.0.

  • Loading branch information...
1 parent df057b9 commit 8a7e19b6578b0986cb7a88a6c10d6cd907af2057 @kevinw committed
Showing with 32 additions and 17 deletions.
  1. +3 −4 README.rst
  2. +5 −2 makerelease.py
  3. +24 −11 pyflakes.vim
View
7 README.rst
@@ -39,10 +39,9 @@ Installation
If you downloaded this from vim.org_, then just drop the contents of the zip
file into ``~/.vim/ftplugin/python``.
-Otherwise, you'll need PyFlakes on your PYTHONPATH somewhere. I recommend
-getting my PyFlakes_ fork, which uses the ``_ast`` module new to Python 2.5,
-and is faster and more current than PyFlakes' old usage of the deprecated
-``compiler`` module.
+Otherwise, if you're running "from source," you'll need PyFlakes on your
+PYTHONPATH somewhere. I recommend getting my PyFlakes_ fork, which retains
+column number information and has therfore has more specific error locations.
.. _vim.org: http://www.vim.org/scripts/script.php?script_id=2441
.. _PyFlakes: http://github.com/kevinw/pyflakes
View
7 makerelease.py
@@ -11,14 +11,17 @@ def get_directory():
return os.path.abspath(os.path.dirname(__file__))
def include_dir(d):
- return not d.startswith('.git')
+ return not any((d.startswith('.git'),
+ d.startswith('_trial_temp'),
+ d.startswith('.svn')))
def include_file(f):
return not any((f.endswith('.pyc'),
f.endswith('.zip'),
f.startswith('.git'),
f == __file__,
- f == '.DS_Store'))
+ f == '.DS_Store',
+ f.endswith('.diff')))
def make_dist():
z = zipfile.ZipFile(BUNDLE_FILENAME, 'w', zipfile.ZIP_DEFLATED)
View
35 pyflakes.vim
@@ -46,14 +46,20 @@ if sys.version_info[:2] < (2, 5):
scriptdir = os.path.join(os.path.dirname(vim.eval('expand("<sfile>")')), 'pyflakes')
sys.path.insert(0, scriptdir)
-from pyflakes import checker, ast, messages
+import ast
+from pyflakes import checker, messages
from operator import attrgetter
import re
+class loc(object):
+ def __init__(self, lineno, col=None):
+ self.lineno = lineno
+ self.col_offset = col
+
class SyntaxError(messages.Message):
message = 'could not compile: %s'
def __init__(self, filename, lineno, col, message):
- messages.Message.__init__(self, filename, lineno, col)
+ messages.Message.__init__(self, filename, loc(lineno, col))
self.message_args = (message,)
class blackhole(object):
@@ -67,13 +73,12 @@ def check(buffer):
# assume everything else that follows is encoded in the encoding.
encoding_found = False
for n, line in enumerate(contents):
- if not encoding_found and n < 2:
- if re.match(r'#.*coding[:=]\s*([-\w.]+)', line):
- encoding_found = True
- else:
- # skip all preceeding lines
- contents = [''] * n + contents[n:]
+ if n >= 2:
+ break
+ elif re.match(r'#.*coding[:=]\s*([-\w.]+)', line):
+ contents = ['']*(n+1) + contents[n+1:]
break
+
contents = '\n'.join(contents) + '\n'
vimenc = vim.eval('&encoding')
@@ -82,7 +87,7 @@ def check(buffer):
builtins = []
try:
- builtins = eval(vim.eval('string(g:pyflakes_builtins)'))
+ builtins = set(eval(vim.eval('string(g:pyflakes_builtins)')))
except Exception:
pass
@@ -104,7 +109,15 @@ def check(buffer):
return [SyntaxError(filename, lineno, offset, str(value))]
else:
- w = checker.Checker(tree, filename, builtins = builtins)
+ # pyflakes looks to _MAGIC_GLOBALS in checker.py to see which
+ # UndefinedNames to ignore
+ old_globals = getattr(checker,' _MAGIC_GLOBALS', [])
+ checker._MAGIC_GLOBALS = set(old_globals) | builtins
+
+ w = checker.Checker(tree, filename)
+
+ checker._MAGIC_GLOBALS = old_globals
+
w.messages.sort(key = attrgetter('lineno'))
return w.messages
@@ -233,7 +246,7 @@ for w in check(vim.current.buffer):
vim.command("let l:qf_item.text = '%s'" % vim_quote(w.message % w.message_args))
vim.command("let l:qf_item.type = 'E'")
- if w.col is None or isinstance(w, SyntaxError):
+ if getattr(w, 'col', None) is None or isinstance(w, SyntaxError):
# without column information, just highlight the whole line
# (minus the newline)
vim.command(r"let s:mID = matchadd('PyFlakes', '\%" + str(w.lineno) + r"l\n\@!')")

0 comments on commit 8a7e19b

Please sign in to comment.
Something went wrong with that request. Please try again.