Skip to content

Commit 59f15e9

Browse files
myintsigmavirus24
authored andcommitted
Detect pythonw in shebang (#277)
Also add more tests. This addresses: #149 (comment)
1 parent e71a72f commit 59f15e9

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

pyflakes/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
__all__ = ['check', 'checkPath', 'checkRecursive', 'iterSourceCode', 'main']
1515

1616

17-
PYTHON_SHEBANG_REGEX = re.compile(br'^#!.*\bpython[23]?\b\s*$')
17+
PYTHON_SHEBANG_REGEX = re.compile(br'^#!.*\bpython[23w]?\b\s*$')
1818

1919

2020
def check(codeString, filename, reporter=None):

pyflakes/test/test_api.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,30 @@ def test_shebang(self):
192192
Find Python files that don't end with `.py`, but contain a Python
193193
shebang.
194194
"""
195-
apath = os.path.join(self.tempdir, 'a')
196-
fd = open(apath, 'w')
197-
fd.write('#!/usr/bin/env python\n')
198-
fd.close()
195+
python = os.path.join(self.tempdir, 'a')
196+
with open(python, 'w') as fd:
197+
fd.write('#!/usr/bin/env python\n')
199198

200199
self.makeEmptyFile('b')
201200

201+
with open(os.path.join(self.tempdir, 'c'), 'w') as fd:
202+
fd.write('hello\nworld\n')
203+
204+
python2 = os.path.join(self.tempdir, 'd')
205+
with open(python2, 'w') as fd:
206+
fd.write('#!/usr/bin/env python2\n')
207+
208+
python3 = os.path.join(self.tempdir, 'e')
209+
with open(python3, 'w') as fd:
210+
fd.write('#!/usr/bin/env python3\n')
211+
212+
pythonw = os.path.join(self.tempdir, 'f')
213+
with open(pythonw, 'w') as fd:
214+
fd.write('#!/usr/bin/env pythonw\n')
215+
202216
self.assertEqual(
203-
list(iterSourceCode([self.tempdir])),
204-
list([apath]))
217+
sorted(iterSourceCode([self.tempdir])),
218+
sorted([python, python2, python3, pythonw]))
205219

206220
def test_multipleDirectories(self):
207221
"""

0 commit comments

Comments
 (0)