From b9125325d99aa555ef303ed6729f6e36561483d1 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Wed, 15 Jan 2025 21:40:53 +0000 Subject: [PATCH] Implement `--executable' option (#257) --- src/installer/__main__.py | 9 ++++++++- tests/test_main.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/installer/__main__.py b/src/installer/__main__.py index 00c7df5..b2dbea5 100644 --- a/src/installer/__main__.py +++ b/src/installer/__main__.py @@ -31,6 +31,13 @@ def _get_main_parser() -> argparse.ArgumentParser: type=str, help="override prefix to install packages to", ) + parser.add_argument( + "--executable", + metavar="path", + default=sys.executable, + type=str, + help="#! executable to install scripts with (default=sys.executable)", + ) parser.add_argument( "--compile-bytecode", action="append", @@ -103,7 +110,7 @@ def _main(cli_args: Sequence[str], program: Optional[str] = None) -> None: source.validate_record(validate_contents=args.validate_record == "all") destination = SchemeDictionaryDestination( scheme_dict=_get_scheme_dict(source.distribution, prefix=args.prefix), - interpreter=sys.executable, + interpreter=args.executable, script_kind=get_launcher_kind(), bytecode_optimization_levels=bytecode_levels, destdir=args.destdir, diff --git a/tests/test_main.py b/tests/test_main.py index cb09b3d..3200819 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -74,6 +74,28 @@ def test_main_prefix(fancy_wheel, tmp_path): } +def test_main_executable(fancy_wheel, tmp_path): + destdir = tmp_path / "dest" + + main( + [ + str(fancy_wheel), + "-d", + str(destdir), + "--executable", + "/monty/python3.x", + ], + "python -m installer", + ) + + installed_scripts = destdir.rglob("bin/*") + + for f in installed_scripts: + with f.open("rb") as fp: + shebang = fp.readline() + assert shebang == b"#!/monty/python3.x\n" + + def test_main_no_pyc(fancy_wheel, tmp_path): destdir = tmp_path / "dest"