Skip to content

Commit e175125

Browse files
committed
Remove import re from script template
1 parent a84a940 commit e175125

File tree

1 file changed

+13
-0
lines changed
  • src/pip/_internal/operations/install

1 file changed

+13
-0
lines changed

src/pip/_internal/operations/install/wheel.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,19 @@ def _raise_for_invalid_entrypoint(specification: str) -> None:
412412

413413

414414
class PipScriptMaker(ScriptMaker):
415+
# Override distlib's default script template with one that
416+
# doesn't import `re` module, allowing scripts to load faster.
417+
script_template = r"""# -*- coding: utf-8 -*-
418+
import sys
419+
from %(module)s import %(import_name)s
420+
if __name__ == '__main__':
421+
if sys.argv[0].endswith('-script.pyw'):
422+
sys.argv[0] = sys.argv[0][: -11]
423+
elif sys.argv[0].endswith('.exe'):
424+
sys.argv[0] = sys.argv[0][: -4]
425+
sys.exit(%(func)s())
426+
"""
427+
415428
def make(
416429
self, specification: str, options: Optional[Dict[str, Any]] = None
417430
) -> List[str]:

0 commit comments

Comments
 (0)