Skip to content

Commit ae6b6b9

Browse files
committed
unix: avoid rewriting non-Python shebangs
Before, we rewrote shebangs in all files with a shebang. This incorrectly rewrote the `#!/bin/sh` shebangs in `pythonX.Y-config`. This commit introduces logic to check for non-Python shebangs and ignores them appropriately. Closes #136.
1 parent d40ac22 commit ae6b6b9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cpython-unix/build-cpython.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,16 @@ for f in sorted(os.listdir(ROOT)):
11041104
if not initial.startswith(b"#!"):
11051105
continue
11061106
1107-
print("rewriting shebang in %s" % full)
1107+
# Make sure it is a Python script and not something else.
1108+
with open(full, "r", encoding="utf-8") as fh:
1109+
initial = fh.readline()
1110+
initial = initial.strip()
1111+
1112+
if "python" not in initial:
1113+
print("ignoring %s due to non-python shebang (%s)" % (full, initial))
1114+
continue
1115+
1116+
print("rewriting Python shebang (%s) in %s" % (initial, full))
11081117
11091118
lines = []
11101119

0 commit comments

Comments
 (0)