Files
MINGW-packages/mingw-w64-gobject-introspection/pyscript2exe.py
Christoph Reiter d394f202ab Add exe launchers for Python scripts in glib2 and gobject-introspection; Reenable G-I for json-glib (#2942)
* Add exe launchers to glib2 to fix the upgrade naming conflict as pacman
  can't see the difference between the new Python script without extension
  and the old .exe file.
* Also add exe laucnhers for gobject-introspection so that meson can execute them.
  The scripts currently have a broken shebang including an absolute path
  (also the case on Linux), and fixing that would at least work for meson as it has
  a shebang parser. But the exe launcher seems less error prone and also works
  with other tools.
* The last update to json-glib disabled introspection due to the above mentioned
  bug. This reenables it and also enables gtk-doc building while at it.
  (first package fully build using only mingw tools \o/)
2017-09-21 16:35:52 +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")