Skip to content

Commit 806dfd4

Browse files
author
stonebig
committed
shebang "..\python.exe" vs "python.exe"
1 parent a81ff5f commit 806dfd4

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

make.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,10 @@ def _create_launchers(self):
515515
"""Create launchers"""
516516
self._print("Creating launchers")
517517
self.create_launcher('WinPython Command Prompt.exe', 'cmd.ico',
518-
command='$SYSDIR\cmd.exe',
519-
args='/k', workdir='${WINPYDIR}')
518+
command=r'${WINPYDIR}\Scripts\ptpython.exe',
519+
args='/k', workdir=r'${WINPYDIR}\Scripts')
520+
# command='$SYSDIR\cmd.exe',
521+
# args='/k', workdir='${WINPYDIR}')
520522
self.create_launcher('WinPython Interpreter.exe', 'python.ico')
521523
#self.create_launcher('IDLE (Python GUI).exe', 'python.ico',
522524
# args='idle.pyw',
@@ -688,19 +690,17 @@ def _create_batch_scripts(self):
688690

689691
self.create_batch_script('make_winpython_movable.bat',r"""@echo off
690692
call %~dp0env.bat
691-
echo patch pip and current launchers fopr move
692-
rem %WINPYDIR%\python.exe -c "from winpython.utils import patch_sourcefile;patch_sourcefile(r'%WINPYDIR%\Lib\site-packages\pip\_vendor\distlib\scripts.py', 'executable = get_executable()', 'executable = os.path.join(os.path.basename(get_executable()))' )"
693+
echo patch pip and current launchers for move
693694
694-
%WINPYDIR%\python.exe -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip');dist.patch_all_shebang(to_movable=True)"
695+
%WINPYDIR%\python.exe -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip', to_movable=True);dist.patch_all_shebang(to_movable=True)"
695696
pause
696697
""")
697698

698699
self.create_batch_script('make_winpython_fix.bat',r"""@echo off
699700
call %~dp0env.bat
700701
echo patch pip and current launchers for non-move
701-
%WINPYDIR%\python.exe -c "from winpython.utils import patch_sourcefile;patch_sourcefile(r'%WINPYDIR%\Lib\site-packages\pip\_vendor\distlib\scripts.py', 'executable = os.path.join(os.path.basename(get_executable()))', 'executable = get_executable()' )"
702702
703-
%WINPYDIR%\python.exe -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_all_shebang(to_movable=False)"
703+
%WINPYDIR%\python.exe -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip', to_movable=False);dist.patch_all_shebang(to_movable=False)"
704704
pause
705705
""")
706706

winpython/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,13 @@ def get_python_long_version(path):
290290
# =============================================================================
291291
# Patch chebang line (courtesy of Christoph Gohlke)
292292
# =============================================================================
293-
def patch_shebang_line(fname, pad=b' ', to_movable=True):
293+
def patch_shebang_line(fname, pad=b' ', to_movable=True, targetdir="..\\"):
294294
"""Remove absolute path to python.exe in shebang lines, or re-add it"""
295295

296296
import re
297297
import sys
298298
import os
299-
target_dir = ""
299+
target_dir = targetdir # movable option
300300
if to_movable == False:
301301
target_dir = os.path.abspath(os.path.dirname(fname))
302302
target_dir = os.path.abspath(os.path.join(target_dir, r'..')) + '\\'
@@ -309,19 +309,22 @@ def patch_shebang_line(fname, pad=b' ', to_movable=True):
309309
target_dir = target_dir.encode('utf-8')
310310
with open(fname, 'rb') as fh:
311311
initial_content = fh.read()
312-
312+
fh.close
313+
fh = None
313314
content = shebang_line.split(initial_content, maxsplit=1)
314315
if len(content) != 3:
315316
return
316317

317318
exe = os.path.basename(content[1][2:])
318-
content[1] = b'#!' + target_dir + exe + (pad * (len(content[1]) - len(exe) - 2))
319+
content[1] = b'#!' + target_dir + exe #+ (pad * (len(content[1]) - len(exe) - 2))
319320
final_content = b''.join(content)
320321
if initial_content == final_content:
321322
return
322323
try:
323-
with open(fname, 'wb') as fh:
324-
fh.write(final_content)
324+
with open(fname, 'wb') as fo:
325+
fo.write(final_content)
326+
fo.close
327+
fo = None
325328
print("patched", fname)
326329
except Exception:
327330
print("failed to patch", fname)

winpython/wppm.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def do_pip_action(self, actions=None, install_options=None):
442442
print("Failed!")
443443
raise
444444

445-
def patch_standard_packages(self, package_name=''):
445+
def patch_standard_packages(self, package_name='', to_movable=True):
446446
"""patch Winpython packages in need"""
447447
import filecmp
448448
# 'pywin32' minimal post-install (pywin32_postinstall.py do too much)
@@ -459,11 +459,25 @@ def patch_standard_packages(self, package_name=''):
459459
# rational: https://github.com/pypa/pip/issues/2328
460460
if package_name.lower() == "pip" or package_name == '':
461461
# ensure pip will create movable launchers
462-
utils.patch_sourcefile(
463-
self.target + (
464-
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py"),
465-
" executable = get_executable()",
466-
" executable = os.path.join(os.path.basename(get_executable()))")
462+
# sheb_mov1 = old way up to WinPython 2016-01, sheb_mov2 = new way
463+
sheb_fix = " executable = get_executable()"
464+
sheb_mov1 = " executable = os.path.join(os.path.basename(get_executable()))"
465+
sheb_mov2 = " executable = os.path.join('..',os.path.basename(get_executable()))"
466+
if to_movable:
467+
utils.patch_sourcefile(self.target +
468+
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
469+
sheb_fix, sheb_mov2)
470+
utils.patch_sourcefile(self.target +
471+
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
472+
sheb_mov1, sheb_mov2)
473+
else:
474+
utils.patch_sourcefile(self.target +
475+
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
476+
sheb_mov1, sheb_fix)
477+
utils.patch_sourcefile(self.target +
478+
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
479+
sheb_mov2, sheb_fix)
480+
467481
# ensure pip wheel will register relative PATH in 'RECORD' files
468482
utils.patch_sourcefile(
469483
self.target + (

0 commit comments

Comments
 (0)