Skip to content

Commit

Permalink
Implement `--executable' option (#257) (#258)
Browse files Browse the repository at this point in the history
Co-authored-by: Taylor R Campbell <[email protected]>
  • Loading branch information
riastradh and Taylor R Campbell authored Jan 29, 2025
1 parent 4c9fd28 commit 375cd94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/installer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 375cd94

Please sign in to comment.