Package: pyflakes
Version: 0.2.1-2
Severity: normal
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

here are some patches that fix various usability issues with the
current pyflakes program.

add_main_function
        - add a main() function for easier argument processing
always_close_fd
        - make sure all open()'d files are also closed again
check_encoding_errors
        - catch encoding errors; same patch as in bug#440750, but
          within this series of patches
set_exit_status
        - set exit status code when errors or warnings are found
series
        - order in which patches must be applied

I have also written a man page for pyflakes, which is based upon those
patches. Will send that to the according bug report.

Kind regards,
  Bastian



- -- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.22-ck1treasure4 (PREEMPT)
Locale: [EMAIL PROTECTED], [EMAIL PROTECTED] (charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/bash

Versions of packages pyflakes depends on:
ii  python                        2.4.4-6    An interactive high-level object-o
ii  python-central                0.5.15     register and build utility for Pyt

pyflakes recommends no packages.

- -- no debconf information

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFHBRoZeBwlBDLsbz4RAksiAKCaMuSHCuhb0WvvjCT9vy1xy4EbZwCgm+aQ
aTii/BjuwGQlHKw5qfY1vWY=
=BSHY
-----END PGP SIGNATURE-----
add_main_function
always_close_fd
set_exit_status
check_encoding_errors
Index: pyflakes-calvin/pyflakes
===================================================================
--- pyflakes-calvin.orig/pyflakes       2007-10-04 14:35:09.619485702 +0200
+++ pyflakes-calvin/pyflakes    2007-10-04 14:36:13.621856822 +0200
@@ -26,15 +26,21 @@ def check(codeString, filename):
 def checkPath(filename):
     return check(file(filename).read(), filename)
 
-args = sys.argv[1:]
-if args:
-    for arg in args:
-        if os.path.isdir(arg):
-            for dirpath, dirnames, filenames in os.walk(arg):
-                for filename in filenames:
-                    if filename.endswith('.py'):
-                        checkPath(os.path.join(dirpath, filename))
-        else:
-            checkPath(arg)
-else:
-    check(sys.stdin.read(), '<stdin>')
+
+def main (args):
+    if args:
+        for arg in args:
+            if os.path.isdir(arg):
+                for dirpath, dirnames, filenames in os.walk(arg):
+                    for filename in filenames:
+                        if filename.endswith('.py'):
+                            checkPath(os.path.join(dirpath, filename))
+            else:
+                checkPath(arg)
+    else:
+        check(sys.stdin.read(), '<stdin>')
+
+
+if __name__ == '__main__':
+    main(sys.argv[1:])
+
Index: pyflakes-calvin/pyflakes
===================================================================
--- pyflakes-calvin.orig/pyflakes       2007-10-04 14:38:16.126395183 +0200
+++ pyflakes-calvin/pyflakes    2007-10-04 14:38:51.127691645 +0200
@@ -24,7 +24,11 @@ def check(codeString, filename):
 
 
 def checkPath(filename):
-    return check(file(filename).read(), filename)
+    fd = file(filename)
+    try:
+        return check(fd.read(), filename)
+    finally:
+        fd.close()
 
 
 def main (args):
Index: pyflakes-calvin/pyflakes
===================================================================
--- pyflakes-calvin.orig/pyflakes       2007-10-04 14:42:48.636453416 +0200
+++ pyflakes-calvin/pyflakes    2007-10-04 14:44:22.639905673 +0200
@@ -20,6 +20,9 @@ def check(codeString, filename):
         print >> sys.stderr, line
         print >> sys.stderr, " " * (offset-2), "^"
         status = 2
+    except UnicodeError, msg:
+        print >> sys.stderr, 'encoding error at %r: %s' % (filename, msg)
+        status = 2
     else:
         w = pyflakes.Checker(tree, filename)
         w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
Index: pyflakes-calvin/pyflakes
===================================================================
--- pyflakes-calvin.orig/pyflakes	2007-10-04 14:39:54.130025588 +0200
+++ pyflakes-calvin/pyflakes	2007-10-04 14:42:28.135700655 +0200
@@ -4,8 +4,11 @@ import compiler, sys
 import os
 import pyflakes
 
+# exit status
+status = 0
 
 def check(codeString, filename):
+    global status
     try:
         tree = compiler.parse(codeString)
     except (SyntaxError, IndentationError):
@@ -16,11 +19,15 @@ def check(codeString, filename):
         print >> sys.stderr, 'could not compile %r:%d:' % (filename, lineno)
         print >> sys.stderr, line
         print >> sys.stderr, " " * (offset-2), "^"
+        status = 2
     else:
         w = pyflakes.Checker(tree, filename)
         w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
-        for warning in w.messages:
-            print warning
+        if w.messages:
+            if status == 0:
+                status = 1
+            for warning in w.messages:
+                print warning
 
 
 def checkPath(filename):
@@ -47,4 +54,5 @@ def main (args):
 
 if __name__ == '__main__':
     main(sys.argv[1:])
+    sys.exit(status)
 

Reply via email to