Patchwork [2,of,4] test-pyflakes: do not parse file that is unlikely a Python script

login
register
mail settings
Submitter Yuya Nishihara
Date May 2, 2014, 4:28 a.m.
Message ID <9428e9853f59843545ea.1399004938@gimlet>
Download mbox | patch
Permalink /patch/4483/
State Changes Requested
Headers show

Comments

Yuya Nishihara - May 2, 2014, 4:28 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1398743365 -32400
#      Tue Apr 29 12:49:25 2014 +0900
# Branch stable
# Node ID 9428e9853f59843545eac04caf8463ebf1d5efa2
# Parent  ab91be7bb1a363e7ff320bece1e238dcf8d634e1
test-pyflakes: do not parse file that is unlikely a Python script

This eliminates false alarm triggered by parsing shell scripts or template
map files.  For example, "pyflakes mercurial/templates/atom/map" reports
many "undefined name"s.
Matt Mackall - May 2, 2014, 5:21 a.m.
On Fri, 2014-05-02 at 13:28 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1398743365 -32400
> #      Tue Apr 29 12:49:25 2014 +0900
> # Branch stable
> # Node ID 9428e9853f59843545eac04caf8463ebf1d5efa2
> # Parent  ab91be7bb1a363e7ff320bece1e238dcf8d634e1
> test-pyflakes: do not parse file that is unlikely a Python script
> 
> This eliminates false alarm triggered by parsing shell scripts or template
> map files.  For example, "pyflakes mercurial/templates/atom/map" reports
> many "undefined name"s.
> 
> diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t
> --- a/tests/test-check-pyflakes.t
> +++ b/tests/test-check-pyflakes.t
> @@ -2,10 +2,9 @@
>  
>    $ cd "`dirname "$TESTDIR"`"
>  
> -run pyflakes on all tracked files ending in .py or without a file ending
> -(skipping binary file random-seed)
> +run pyflakes on all tracked python scripts
>  
> -  $ hg locate -r. -I '**.py' -I 'relre:^[^.]*$' -X 'relre:/random_seed$' \
> +  $ hg locate -r. -I '**.py' -I 'set: "relre:^[^.]*$" and grep("^#!.*python")' \

Great idea, but we can simplify it further (and make it more inclusive)
thusly:

     $ hg locate 'set:**.py or grep("^!#.*python")'

- we want to include tracked but uncommitted files
- we want to include files with names like *.cgi
- we can use fileset operators rather than -I and -X

I've queued a version that does this locally.

Patch

diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t
--- a/tests/test-check-pyflakes.t
+++ b/tests/test-check-pyflakes.t
@@ -2,10 +2,9 @@ 
 
   $ cd "`dirname "$TESTDIR"`"
 
-run pyflakes on all tracked files ending in .py or without a file ending
-(skipping binary file random-seed)
+run pyflakes on all tracked python scripts
 
-  $ hg locate -r. -I '**.py' -I 'relre:^[^.]*$' -X 'relre:/random_seed$' \
+  $ hg locate -r. -I '**.py' -I 'set: "relre:^[^.]*$" and grep("^#!.*python")' \
   > 2>/dev/null | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
   contrib/win32/hgwebdir_wsgi.py:*: 'win32traceutil' imported but unused (glob)
   setup.py:*: 'sha' imported but unused (glob)