Skip to content

Commit 375cd94

Browse files
riastradhTaylor R Campbell
andauthored
Implement `--executable' option (#257) (#258)
Co-authored-by: Taylor R Campbell <[email protected]>
1 parent 4c9fd28 commit 375cd94

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/installer/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ def _get_main_parser() -> argparse.ArgumentParser:
3131
type=str,
3232
help="override prefix to install packages to",
3333
)
34+
parser.add_argument(
35+
"--executable",
36+
metavar="path",
37+
default=sys.executable,
38+
type=str,
39+
help="#! executable to install scripts with (default=sys.executable)",
40+
)
3441
parser.add_argument(
3542
"--compile-bytecode",
3643
action="append",
@@ -103,7 +110,7 @@ def _main(cli_args: Sequence[str], program: Optional[str] = None) -> None:
103110
source.validate_record(validate_contents=args.validate_record == "all")
104111
destination = SchemeDictionaryDestination(
105112
scheme_dict=_get_scheme_dict(source.distribution, prefix=args.prefix),
106-
interpreter=sys.executable,
113+
interpreter=args.executable,
107114
script_kind=get_launcher_kind(),
108115
bytecode_optimization_levels=bytecode_levels,
109116
destdir=args.destdir,

tests/test_main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ def test_main_prefix(fancy_wheel, tmp_path):
7474
}
7575

7676

77+
def test_main_executable(fancy_wheel, tmp_path):
78+
destdir = tmp_path / "dest"
79+
80+
main(
81+
[
82+
str(fancy_wheel),
83+
"-d",
84+
str(destdir),
85+
"--executable",
86+
"/monty/python3.x",
87+
],
88+
"python -m installer",
89+
)
90+
91+
installed_scripts = destdir.rglob("bin/*")
92+
93+
for f in installed_scripts:
94+
with f.open("rb") as fp:
95+
shebang = fp.readline()
96+
assert shebang == b"#!/monty/python3.x\n"
97+
98+
7799
def test_main_no_pyc(fancy_wheel, tmp_path):
78100
destdir = tmp_path / "dest"
79101

0 commit comments

Comments
 (0)