1. Lorenzo Gil Sánchez
  2. hghooks

Commits

ablanco  committed afa58f4 Merge

Merge last changes from lgs

  • Participants
  • Parent commits 6cafc43, 847bb8c
  • Branches default

Comments (0)

Files changed (4)

File .hgtags

View file
  • Ignore whitespace
 5b40b7eab309a057bae175b284f72e6d20e576ad 0.4.0
 7826cee9b3b1062aa04f518066bb4af4ad12bc55 0.4.1
 9a2c1bae82b84bec5b724f2bb00ff85de2ec6241 0.4.2
+79066bba0e71c1380ebccc9d39bc3d63ebfe9590 0.4.3

File CHANGES.txt

View file
  • Ignore whitespace
 Changes
 =======
 
-0.4.3dev (unreleased)
+0.4.4dev (unreleased)
 ---------------------
 - ...
 
+0.4.3 (2011-10-23)
+------------------
+- Works with pyflakes 0.5.0 and backwards compatibility for previous versions
+
 0.4.2 (2011-02-24)
 ------------------
 - Fix a bug with non ascii characters in the commit message

File hghooks/__init__.py

View file
  • Ignore whitespace
 import shutil
 import tempfile
 
-version = "0.4.3dev"
+version = "0.4.4dev"
 
 re_options = re.IGNORECASE | re.MULTILINE | re.DOTALL
 skip_pattern = re.compile('# hghooks: (.*)', re_options)

File hghooks/code.py

View file
  • Ignore whitespace
 import os
 import re
 import sys
+import _ast
 
 import pep8
 import pyflakes.checker
     return checker_manager.check(pdb_checker)
 
 
+def pyflakes_version():
+    return tuple([int(part) for part in pyflakes.__version__.split('.')])
+
+
 def pyflakes_check(data, filename):
     """
     Check the Python source given by C{data} for flakes.
     It's like pyflakes.scripts.check function but ignores those lines which
     ends with ends with a "pyflakes:ignore" comment.
 
-    Code adapted from http://djangosnippets.org/snippets/1762/ which is adapted
-    from pyflakes.scripts.pyflakes.check function.
+    Code adapted from pyflakes.scripts.pyflakes.check function.
     """
-    # Since compiler.parse does not reliably report syntax errors, use the
-    # built in compiler first to detect those.
+    # First, compile into an AST and handle syntax errors.
     try:
-        try:
-            compile(data, filename, "exec")
-        except MemoryError:
-            # Python 2.4 will raise MemoryError if the source can't be
-            # decoded.
-            if sys.version_info[:2] == (2, 4):
-                raise SyntaxError(None)
-            raise
-    except (SyntaxError, IndentationError), value:
+        tree = compile(data, filename, "exec", _ast.PyCF_ONLY_AST)
+    except SyntaxError, value:
         msg = value.args[0]
 
         (lineno, offset, text) = value.lineno, value.offset, value.text
                 offset = offset - (len(text) - len(line))
 
             print >> sys.stderr, '%s:%d: %s' % (filename, lineno, msg)
+            print >> sys.stderr, line
+
+            if offset is not None:
+                print >> sys.stderr, " " * offset, "^"
+
         return 1
     else:
-        # Okay, it's syntactically valid.  Now parse it into an ast and check
-        # it.
-        tree = compiler.parse(data)
+        if pyflakes_version() < (0, 5, 0):
+            tree = compiler.parse(data)
+
+        # Okay, it's syntactically valid.  Now check it.
         w = pyflakes.checker.Checker(tree, filename)
 
         lines = data.split('\n')