This commit is contained in:
Duc Le 2023-11-10 14:21:45 -06:00 committed by GitHub
commit ac10f407a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

1
news/10661.feature.rst Normal file
View File

@ -0,0 +1 @@
Script shebang "#!python" replacement now preserves all arguments after the first space (e.g. "#!python -i")

View File

@ -103,7 +103,9 @@ def fix_script(path: str) -> bool:
if not firstline.startswith(b"#!python"):
return False
exename = sys.executable.encode(sys.getfilesystemencoding())
firstline = b"#!" + exename + os.linesep.encode("ascii")
parts = firstline.split(maxsplit=1)
postinterp = b" " + parts[1].rstrip() if len(parts) > 1 else b""
firstline = b"#!" + exename + postinterp + os.linesep.encode("ascii")
rest = script.read()
with open(path, "wb") as script:
script.write(firstline)