summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuediger Pluem <r.pluem@gmx.de>2019-10-11 13:36:50 (GMT)
committerVictor Stinner <vstinner@python.org>2019-10-11 13:36:50 (GMT)
commit2b7dc40b2af6578181808ba73c1533fc114e55df (patch)
tree4d570ccad09538a1da458e8eb8c84730966455a3
parentcbb548130caf24275fa16100bccc537570cb46df (diff)
downloadcpython-2b7dc40b2af6578181808ba73c1533fc114e55df.zip
cpython-2b7dc40b2af6578181808ba73c1533fc114e55df.tar.gz
cpython-2b7dc40b2af6578181808ba73c1533fc114e55df.tar.bz2
bpo-38347: find pathfix for Python scripts whose name contain a '-' (GH-16536)
pathfix.py: Assume all files that end on '.py' are Python scripts when working recursively.
-rw-r--r--Lib/test/test_tools/test_pathfix.py34
-rw-r--r--Misc/NEWS.d/next/Tools-Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst1
-rwxr-xr-xTools/scripts/pathfix.py5
3 files changed, 30 insertions, 10 deletions
diff --git a/Lib/test/test_tools/test_pathfix.py b/Lib/test/test_tools/test_pathfix.py
index a879924..ec36117 100644
--- a/Lib/test/test_tools/test_pathfix.py
+++ b/Lib/test/test_tools/test_pathfix.py
@@ -14,25 +14,34 @@ class TestPathfixFunctional(unittest.TestCase):
script = os.path.join(scriptsdir, 'pathfix.py')
def setUp(self):
- self.temp_file = support.TESTFN
self.addCleanup(support.unlink, support.TESTFN)
- def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr=''):
- with open(self.temp_file, 'w', encoding='utf8') as f:
+ def pathfix(self, shebang, pathfix_flags, exitcode=0, stdout='', stderr='',
+ directory=''):
+ if directory:
+ # bpo-38347: Test filename should contain lowercase, uppercase,
+ # "-", "_" and digits.
+ filename = os.path.join(directory, 'script-A_1.py')
+ pathfix_arg = directory
+ else:
+ filename = support.TESTFN
+ pathfix_arg = filename
+
+ with open(filename, 'w', encoding='utf8') as f:
f.write(f'{shebang}\n' + 'print("Hello world")\n')
proc = subprocess.run(
[sys.executable, self.script,
- *pathfix_flags, '-n', self.temp_file],
+ *pathfix_flags, '-n', pathfix_arg],
capture_output=True, text=1)
if stdout == '' and proc.returncode == 0:
- stdout = f'{self.temp_file}: updating\n'
+ stdout = f'{filename}: updating\n'
self.assertEqual(proc.returncode, exitcode, proc)
self.assertEqual(proc.stdout, stdout, proc)
self.assertEqual(proc.stderr, stderr, proc)
- with open(self.temp_file, 'r', encoding='utf8') as f:
+ with open(filename, 'r', encoding='utf8') as f:
output = f.read()
lines = output.split('\n')
@@ -44,6 +53,19 @@ class TestPathfixFunctional(unittest.TestCase):
return new_shebang
+ def test_recursive(self):
+ tmpdir = support.TESTFN + '.d'
+ self.addCleanup(support.rmtree, tmpdir)
+ os.mkdir(tmpdir)
+ expected_stderr = f"recursedown('{os.path.basename(tmpdir)}')\n"
+ self.assertEqual(
+ self.pathfix(
+ '#! /usr/bin/env python',
+ ['-i', '/usr/bin/python3'],
+ directory=tmpdir,
+ stderr=expected_stderr),
+ '#! /usr/bin/python3')
+
def test_pathfix(self):
self.assertEqual(
self.pathfix(
diff --git a/Misc/NEWS.d/next/Tools-Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst b/Misc/NEWS.d/next/Tools-Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst
new file mode 100644
index 0000000..ae64a31
--- /dev/null
+++ b/Misc/NEWS.d/next/Tools-Demos/2019-10-02-09-48-42.bpo-38347.2Tq5D1.rst
@@ -0,0 +1 @@
+pathfix.py: Assume all files that end on '.py' are Python scripts when working recursively.
diff --git a/Tools/scripts/pathfix.py b/Tools/scripts/pathfix.py
index 237a3d9..d252321 100755
--- a/Tools/scripts/pathfix.py
+++ b/Tools/scripts/pathfix.py
@@ -89,11 +89,8 @@ def main():
sys.exit(bad)
-ispythonprog = re.compile(r'^[a-zA-Z0-9_]+\.py$')
-
-
def ispython(name):
- return bool(ispythonprog.match(name))
+ return name.endswith('.py')
def recursedown(dirname):