blob: 7906769b9017957f55a2bad338d520e6e2f0d883 [file] [log] [blame]
Andrew Geissler517393d2023-01-13 08:55:19 -06001From 74fe171fa4a25c120607e9f8450cbdfee675c959 Mon Sep 17 00:00:00 2001
2From: Ross Burton <ross.burton@arm.com>
3Date: Mon, 14 Mar 2022 14:39:22 +0000
4Subject: [PATCH] python3-installer: add installer module
5
Andrew Geissler9aee5002022-03-30 16:27:02 +00006Let us override the hashbang directly (possibly upstreamable), and don't
7play games with hashbangs: for now assume that even hashbangs with spaces
8are simple (assume the spaces are only used to separate arguments) and
9we don't have long hashbangs.
10
11Upstream-Status: Inappropriate
12Signed-off-by: Ross Burton <ross.burton@arm.com>
13
Andrew Geissler517393d2023-01-13 08:55:19 -060014---
15 src/installer/__main__.py | 9 ++++++++-
16 src/installer/scripts.py | 15 +--------------
17 2 files changed, 9 insertions(+), 15 deletions(-)
18
Andrew Geissler9aee5002022-03-30 16:27:02 +000019diff --git a/src/installer/__main__.py b/src/installer/__main__.py
Andrew Geissler517393d2023-01-13 08:55:19 -060020index 51014b9..38de286 100644
Andrew Geissler9aee5002022-03-30 16:27:02 +000021--- a/src/installer/__main__.py
22+++ b/src/installer/__main__.py
Andrew Geissler517393d2023-01-13 08:55:19 -060023@@ -30,6 +30,13 @@ def _get_main_parser() -> argparse.ArgumentParser:
Andrew Geissler9aee5002022-03-30 16:27:02 +000024 type=str,
Andrew Geissler517393d2023-01-13 08:55:19 -060025 help="override prefix to install packages to",
Andrew Geissler9aee5002022-03-30 16:27:02 +000026 )
27+ parser.add_argument(
28+ "--interpreter",
29+ "-i",
30+ type=str,
31+ default=sys.executable,
32+ help=f"interpreter (defaults to {sys.executable})",
33+ )
34 parser.add_argument(
35 "--compile-bytecode",
36 action="append",
Andrew Geissler517393d2023-01-13 08:55:19 -060037@@ -86,7 +93,7 @@ def _main(cli_args: Sequence[str], program: Optional[str] = None) -> None:
Andrew Geissler9aee5002022-03-30 16:27:02 +000038 with WheelFile.open(args.wheel) as source:
39 destination = SchemeDictionaryDestination(
Andrew Geissler517393d2023-01-13 08:55:19 -060040 scheme_dict=_get_scheme_dict(source.distribution, prefix=args.prefix),
Andrew Geissler9aee5002022-03-30 16:27:02 +000041- interpreter=sys.executable,
42+ interpreter=args.interpreter,
43 script_kind=get_launcher_kind(),
44 bytecode_optimization_levels=bytecode_levels,
45 destdir=args.destdir,
46diff --git a/src/installer/scripts.py b/src/installer/scripts.py
47index 7e3c8fc..ba6ed5a 100644
48--- a/src/installer/scripts.py
49+++ b/src/installer/scripts.py
50@@ -59,20 +59,7 @@ def _build_shebang(executable: str, forlauncher: bool) -> bytes:
51 https://bitbucket.org/pypa/distlib/src/58cd5c6/distlib/scripts.py#lines-124
52 """
53 executable_bytes = executable.encode("utf-8")
54- if forlauncher: # The launcher can just use the command as-is.
55- return b"#!" + executable_bytes
56- if _is_executable_simple(executable_bytes):
57- return b"#!" + executable_bytes
58-
59- # Shebang support for an executable with a space in it is under-specified
60- # and platform-dependent, so we use a clever hack to generate a script to
61- # run in ``/bin/sh`` that should work on all reasonably modern platforms.
62- # Read the following message to understand how the hack works:
63- # https://github.com/pradyunsg/installer/pull/4#issuecomment-623668717
64-
65- quoted = shlex.quote(executable).encode("utf-8")
66- # I don't understand a lick what this is trying to do.
67- return b"#!/bin/sh\n'''exec' " + quoted + b' "$0" "$@"\n' + b"' '''"
68+ return b"#!" + executable_bytes
Andrew Geissler517393d2023-01-13 08:55:19 -060069
70
Andrew Geissler9aee5002022-03-30 16:27:02 +000071 class InvalidScript(ValueError):