Skip to content

Commit 8f32c5b

Browse files
authored
Merge pull request #1595 from Celeborn2BeAlive/1583-wrong-shebang-line-win10-pyenvwin
Drop python.exe extension on windows in shebang line to fix pyenv-win setup
2 parents 8e9f927 + 273326b commit 8f32c5b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pre_commit/commands/install_uninstall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def is_our_script(filename: str) -> bool:
5555

5656
def shebang() -> str:
5757
if sys.platform == 'win32':
58-
py = SYS_EXE
58+
py, _ = os.path.splitext(SYS_EXE)
5959
else:
6060
exe_choices = [
6161
f'python{sys.version_info[0]}.{sys.version_info[1]}',

tests/commands/install_uninstall_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ def patch_sys_exe(exe):
5656

5757

5858
def test_shebang_windows():
59+
with patch_platform('win32'), patch_sys_exe('python'):
60+
assert shebang() == '#!/usr/bin/env python'
61+
62+
63+
def test_shebang_windows_drop_ext():
5964
with patch_platform('win32'), patch_sys_exe('python.exe'):
60-
assert shebang() == '#!/usr/bin/env python.exe'
65+
assert shebang() == '#!/usr/bin/env python'
6166

6267

6368
def test_shebang_posix_not_on_path():

0 commit comments

Comments
 (0)