Files
MINGW-packages/mingw-w64-glib2-git/pyscript2exe.py
2018-05-21 08:27:10 +03:00

21 lines
587 B
Python

"""
Creates an exe launcher for Python scripts for the executing interpreter.
foobar.py -> foobar.exe + foobar-script.py
"""
import sys
import re
import os
from setuptools.command.easy_install import get_win_launcher
path = sys.argv[1]
with open(path, "rb") as f:
data = f.read()
with open(path, "wb") as f:
shebang = "#!/usr/bin/env " + os.path.basename(sys.executable)
f.write(re.sub(b"^#![^\n\r]*", shebang.encode(), data))
root, ext = os.path.splitext(path)
with open(root + ".exe", "wb") as f:
f.write(get_win_launcher("cli"))
os.rename(path, root + "-script.py")