forked from pex-tool/pex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use appropriate shebang for multi-platform PEXes. (pex-tool#2296)
Although it's not always possible to derive an appropriate shebang that will work for multi-platform PEXes, we now do so when possible and warn when we cannot. Fixes pex-tool#1540
- Loading branch information
Showing
5 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import absolute_import | ||
|
||
import os.path | ||
from textwrap import dedent | ||
|
||
from pex.interpreter import PythonInterpreter | ||
from pex.typing import TYPE_CHECKING | ||
from testing import run_pex_command | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
|
||
def test_derive_consistent_shebang_platforms( | ||
tmpdir, # type: Any | ||
current_interpreter, # type: PythonInterpreter | ||
): | ||
# type: (...) -> None | ||
|
||
pex = os.path.join(str(tmpdir), "pex") | ||
|
||
def read_pex_shebang(): | ||
# type: () -> bytes | ||
with open(pex, "rb") as fp: | ||
return fp.readline() | ||
|
||
run_pex_command(args=["--platform", "linux_x86_64-cp-311-cp311", "-o", pex]).assert_success() | ||
assert b"#!/usr/bin/env python3.11\n" == read_pex_shebang() | ||
|
||
run_pex_command( | ||
args=[ | ||
"--platform", | ||
"linux_x86_64-cp-311-cp311", | ||
"--platform", | ||
"macosx_10.9_x86_64-cp-311-cp311", | ||
"-o", | ||
pex, | ||
] | ||
).assert_success() | ||
assert b"#!/usr/bin/env python3.11\n" == read_pex_shebang() | ||
|
||
run_pex_command( | ||
args=[ | ||
"--platform", | ||
"linux_x86_64-cp-3.11.5-cp311", | ||
"--platform", | ||
"macosx_10.9_x86_64-cp-311-cp311", | ||
"-o", | ||
pex, | ||
] | ||
).assert_success() | ||
assert b"#!/usr/bin/env python3.11\n" == read_pex_shebang() | ||
|
||
result = run_pex_command( | ||
args=[ | ||
"--platform", | ||
"linux_x86_64-cp-310-cp310", | ||
"--platform", | ||
"macosx_10.9_x86_64-cp-311-cp311", | ||
"-o", | ||
pex, | ||
] | ||
) | ||
result.assert_success() | ||
current_interpreter_shebang = current_interpreter.identity.hashbang() | ||
assert ( | ||
"{shebang}\n".format(shebang=current_interpreter_shebang).encode("utf-8") | ||
== read_pex_shebang() | ||
) | ||
assert ( | ||
dedent( | ||
"""\ | ||
PEXWarning: Could not calculate a targeted shebang for: | ||
abbreviated platform cp310-cp310-linux_x86_64 | ||
abbreviated platform cp311-cp311-macosx_10_9_x86_64 | ||
Using shebang: {shebang} | ||
If this is not appropriate, you can specify a custom shebang using the --python-shebang option. | ||
""" | ||
).format(shebang=current_interpreter_shebang) | ||
in result.error | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters