X Tutup
Skip to content

Commit fe1b790

Browse files
Make binaries movable in WinPython3.x
1 parent 65eb359 commit fe1b790

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

winpython/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,29 @@ def patch_shebang_line(fname, pad=b' ', to_movable=True, targetdir=""):
312312
print("failed to patch", fname)
313313

314314

315+
# =============================================================================
316+
# Patch shebang line in .py files
317+
# =============================================================================
318+
def patch_shebang_line_py(fname, to_movable=True, targetdir=""):
319+
"""Changes shebang line in '.py' file to relative or absolue path"""
320+
import fileinput
321+
import re
322+
import sys
323+
324+
if sys.version_info[0] == 2:
325+
# Python 2.x doesn't create .py files for .exe files. So, Moving
326+
# WinPython doesn't break running executable files.
327+
return
328+
if to_movable:
329+
exec_path = '#!.\python.exe'
330+
else:
331+
exec_path = '#!' + sys.executable
332+
for line in fileinput.input(fname, inplace=True):
333+
if re.match('^#\!.*python\.exe$', line) is not None:
334+
print(exec_path)
335+
else:
336+
print(line, end='')
337+
315338
# =============================================================================
316339
# Patch sourcefile (instead of forking packages)
317340
# =============================================================================

winpython/wppm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ def patch_all_shebang(self, to_movable=True, max_exe_size=999999, targetdir=""):
393393
if size <= max_exe_size:
394394
utils.patch_shebang_line(ffname, to_movable=to_movable,
395395
targetdir=targetdir)
396+
for ffname in glob.glob(r'%s\Scripts\*.py' % self.target):
397+
utils.patch_shebang_line_py(ffname, to_movable=to_movable,
398+
targetdir=targetdir)
396399

397400

398401
def install(self, package, install_options=None):

0 commit comments

Comments
 (0)
X Tutup