Christoph Reiter a04e343fb4 python-docutils: create .exe launchers for all scripts
and port to build/installer while at it

motivated by virt-manager calling them without an interpreter
The next docutils will have a central .exe launcher and the old scripts
will be deprecated, so this should fix itself over time.
2023-03-05 08:54:36 +01:00

20 lines
507 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:
f.write(re.sub(b"^#![^\n\r]*", b'', 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")