diff options
author | Steven Myint <git@stevenmyint.com> | 2017-06-02 18:49:14 -0700 |
---|---|---|
committer | Steven Myint <git@stevenmyint.com> | 2017-06-02 18:49:14 -0700 |
commit | b68150a5abd4d03ef9206aafabed5bb8ee4eb3fa (patch) | |
tree | 1ef63130f9bd6e6a143ee962912ed5a5e486c420 | |
parent | e71a72fc7aab8938b2ec2be64a850f6ab6251e53 (diff) | |
download | pyflakes-shebang.tar.gz |
Detect `pythonw` in shebangshebang
Also add more tests.
This addresses:
https://github.com/PyCQA/pyflakes/issues/149#issuecomment-305881232
-rw-r--r-- | pyflakes/api.py | 2 | ||||
-rw-r--r-- | pyflakes/test/test_api.py | 26 |
2 files changed, 21 insertions, 7 deletions
diff --git a/pyflakes/api.py b/pyflakes/api.py index e30f920..49ee38d 100644 --- a/pyflakes/api.py +++ b/pyflakes/api.py @@ -14,7 +14,7 @@ from pyflakes import reporter as modReporter __all__ = ['check', 'checkPath', 'checkRecursive', 'iterSourceCode', 'main'] -PYTHON_SHEBANG_REGEX = re.compile(br'^#!.*\bpython[23]?\b\s*$') +PYTHON_SHEBANG_REGEX = re.compile(br'^#!.*\bpython[23w]?\b\s*$') def check(codeString, filename, reporter=None): diff --git a/pyflakes/test/test_api.py b/pyflakes/test/test_api.py index a1e0be2..3f54ca4 100644 --- a/pyflakes/test/test_api.py +++ b/pyflakes/test/test_api.py @@ -192,16 +192,30 @@ class TestIterSourceCode(TestCase): Find Python files that don't end with `.py`, but contain a Python shebang. """ - apath = os.path.join(self.tempdir, 'a') - fd = open(apath, 'w') - fd.write('#!/usr/bin/env python\n') - fd.close() + python = os.path.join(self.tempdir, 'a') + with open(python, 'w') as fd: + fd.write('#!/usr/bin/env python\n') self.makeEmptyFile('b') + with open(os.path.join(self.tempdir, 'c'), 'w') as fd: + fd.write('hello\nworld\n') + + python2 = os.path.join(self.tempdir, 'd') + with open(python2, 'w') as fd: + fd.write('#!/usr/bin/env python2\n') + + python3 = os.path.join(self.tempdir, 'e') + with open(python3, 'w') as fd: + fd.write('#!/usr/bin/env python3\n') + + pythonw = os.path.join(self.tempdir, 'f') + with open(pythonw, 'w') as fd: + fd.write('#!/usr/bin/env pythonw\n') + self.assertEqual( - list(iterSourceCode([self.tempdir])), - list([apath])) + sorted(iterSourceCode([self.tempdir])), + sorted([python, python2, python3, pythonw])) def test_multipleDirectories(self): """ |