Skip to content

Commit

Permalink
Implement `--executable' option (pypa#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taylor R Campbell committed Jan 15, 2025
1 parent ad82145 commit ca09d6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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
13 changes: 12 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def test_main_multiple_wheels(fancy_wheel, another_fancy_wheel, tmp_path):
def test_main_prefix(fancy_wheel, tmp_path):
destdir = tmp_path / "dest"

main([str(fancy_wheel), "-d", str(destdir), "-p", "/foo"], "python -m installer")
main(
[str(fancy_wheel), "-d", str(destdir), "-p", "/foo", "--executable", "/monty/python3.x"],
"python -m installer",
)

installed_py_files = list(destdir.rglob("*.py"))

Expand All @@ -73,6 +76,14 @@ def test_main_prefix(fancy_wheel, tmp_path):
"__main__",
}

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' or \
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 ca09d6f

Please sign in to comment.