From 74b7a3af1b64368381a9b0078d395ab5732779cf Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:09:10 +0200 Subject: [PATCH] Remove `import re` from script template --- distlib/scripts.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/distlib/scripts.py b/distlib/scripts.py index b1fc705..79cbf1c 100644 --- a/distlib/scripts.py +++ b/distlib/scripts.py @@ -40,11 +40,13 @@ # check if Python is called on the first line with this expression FIRST_LINE_RE = re.compile(b'^#!.*pythonw?[0-9.]*([ \t].*)?$') SCRIPT_TEMPLATE = r'''# -*- coding: utf-8 -*- -import re import sys from %(module)s import %(import_name)s if __name__ == '__main__': - sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + if sys.argv[0].endswith('-script.pyw'): + sys.argv[0] = sys.argv[0][: -11] + elif sys.argv[0].endswith('.exe'): + sys.argv[0] = sys.argv[0][: -4] sys.exit(%(func)s()) '''