Skip to content

shebang "..\python.exe" vs "python.exe" #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,10 @@ def _create_launchers(self):
"""Create launchers"""
self._print("Creating launchers")
self.create_launcher('WinPython Command Prompt.exe', 'cmd.ico',
command='$SYSDIR\cmd.exe',
args='/k', workdir='${WINPYDIR}')
command=r'${WINPYDIR}\Scripts\ptpython.exe',
args='/k', workdir=r'${WINPYDIR}\Scripts')
# command='$SYSDIR\cmd.exe',
# args='/k', workdir='${WINPYDIR}')
self.create_launcher('WinPython Interpreter.exe', 'python.ico')
#self.create_launcher('IDLE (Python GUI).exe', 'python.ico',
# args='idle.pyw',
Expand Down Expand Up @@ -688,19 +690,17 @@ def _create_batch_scripts(self):

self.create_batch_script('make_winpython_movable.bat',r"""@echo off
call %~dp0env.bat
echo patch pip and current launchers fopr move
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()))' )"
echo patch pip and current launchers for move

%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)"
%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)"
pause
""")

self.create_batch_script('make_winpython_fix.bat',r"""@echo off
call %~dp0env.bat
echo patch pip and current launchers for non-move
%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()' )"

%WINPYDIR%\python.exe -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_all_shebang(to_movable=False)"
%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)"
pause
""")

Expand Down
15 changes: 9 additions & 6 deletions winpython/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ def get_python_long_version(path):
# =============================================================================
# Patch chebang line (courtesy of Christoph Gohlke)
# =============================================================================
def patch_shebang_line(fname, pad=b' ', to_movable=True):
def patch_shebang_line(fname, pad=b' ', to_movable=True, targetdir="..\\"):
"""Remove absolute path to python.exe in shebang lines, or re-add it"""

import re
import sys
import os
target_dir = ""
target_dir = targetdir # movable option
if to_movable == False:
target_dir = os.path.abspath(os.path.dirname(fname))
target_dir = os.path.abspath(os.path.join(target_dir, r'..')) + '\\'
Expand All @@ -309,19 +309,22 @@ def patch_shebang_line(fname, pad=b' ', to_movable=True):
target_dir = target_dir.encode('utf-8')
with open(fname, 'rb') as fh:
initial_content = fh.read()

fh.close
fh = None
content = shebang_line.split(initial_content, maxsplit=1)
if len(content) != 3:
return

exe = os.path.basename(content[1][2:])
content[1] = b'#!' + target_dir + exe + (pad * (len(content[1]) - len(exe) - 2))
content[1] = b'#!' + target_dir + exe #+ (pad * (len(content[1]) - len(exe) - 2))
final_content = b''.join(content)
if initial_content == final_content:
return
try:
with open(fname, 'wb') as fh:
fh.write(final_content)
with open(fname, 'wb') as fo:
fo.write(final_content)
fo.close
fo = None
print("patched", fname)
except Exception:
print("failed to patch", fname)
Expand Down
26 changes: 20 additions & 6 deletions winpython/wppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def do_pip_action(self, actions=None, install_options=None):
print("Failed!")
raise

def patch_standard_packages(self, package_name=''):
def patch_standard_packages(self, package_name='', to_movable=True):
"""patch Winpython packages in need"""
import filecmp
# 'pywin32' minimal post-install (pywin32_postinstall.py do too much)
Expand All @@ -459,11 +459,25 @@ def patch_standard_packages(self, package_name=''):
# rational: https://github.com/pypa/pip/issues/2328
if package_name.lower() == "pip" or package_name == '':
# ensure pip will create movable launchers
utils.patch_sourcefile(
self.target + (
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py"),
" executable = get_executable()",
" executable = os.path.join(os.path.basename(get_executable()))")
# sheb_mov1 = old way up to WinPython 2016-01, sheb_mov2 = new way
sheb_fix = " executable = get_executable()"
sheb_mov1 = " executable = os.path.join(os.path.basename(get_executable()))"
sheb_mov2 = " executable = os.path.join('..',os.path.basename(get_executable()))"
if to_movable:
utils.patch_sourcefile(self.target +
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
sheb_fix, sheb_mov2)
utils.patch_sourcefile(self.target +
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
sheb_mov1, sheb_mov2)
else:
utils.patch_sourcefile(self.target +
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
sheb_mov1, sheb_fix)
utils.patch_sourcefile(self.target +
r"\Lib\site-packages\pip\_vendor\distlib\scripts.py",
sheb_mov2, sheb_fix)

# ensure pip wheel will register relative PATH in 'RECORD' files
utils.patch_sourcefile(
self.target + (
Expand Down