Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate platform_machine in --platform resolve. #1489

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pex/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,29 @@ def marker_environment(self, default_unknown=True):

if "linux" in self.platform:
env["os_name"] = "posix"
if self.platform.startswith(
("linux_", "manylinux1_", "manylinux2010_", "manylinux2014_")
):
# E.G.:
# + linux_x86_64
# + manylinux{1,2010,2014}_x86_64
# For the manylinux* See:
# + manylinux1: https://www.python.org/dev/peps/pep-0513/
# + manylinux2010: https://www.python.org/dev/peps/pep-0571/
# + manylinux2014: https://www.python.org/dev/peps/pep-0599/
env["platform_machine"] = self.platform.split("_", 1)[-1]
else:
# E.G.: manylinux_<glibc major>_<glibc_minor>_x86_64
# See: https://www.python.org/dev/peps/pep-0600/
env["platform_machine"] = self.platform.split("_", 3)[-1]
env["platform_system"] = "Linux"
env["sys_platform"] = "linux2" if major_version == 2 else "linux"
elif "mac" in self.platform:
env["os_name"] = "posix"
# E.G:
# + macosx_10_15_x86_64
# + macosx_11_0_arm64
env["platform_machine"] = self.platform.split("_", 3)[-1]
env["platform_system"] = "Darwin"
env["sys_platform"] = "darwin"

Expand Down
35 changes: 35 additions & 0 deletions tests/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,38 @@ def test_download_platform_markers_issue_1366_indeterminate(
"evaluation of unknown environment marker: 'python_full_version' does not exist in "
"evaluation environment."
) in str(exc_info.value)


def test_download_platform_markers_issue_1488(
create_pip, # type: CreatePip
tmpdir, # type: Any
):
# type: (...) -> None

constraints_file = os.path.join(str(tmpdir), "constraints.txt")
with open(constraints_file, "w") as fp:
fp.write("greenlet==1.1.2")

download_dir = os.path.join(str(tmpdir), "downloads")

python39_platform = Platform.create("linux-x86_64-cp-39-cp39")
create_pip(None).spawn_download_distributions(
target=DistributionTarget.for_platform(python39_platform, manylinux="manylinux2014"),
requirements=["SQLAlchemy==1.4.25"],
constraint_files=[constraints_file],
download_dir=download_dir,
transitive=True,
).wait()

assert (
sorted(
[
(
"SQLAlchemy-1.4.25-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64"
".manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
),
"greenlet-1.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
]
)
== sorted(os.listdir(download_dir))
)
22 changes: 21 additions & 1 deletion tests/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def assert_known_marker(expression):
assert_known_marker("python_version == '3.7'")
assert_known_marker("implementation_name == 'cpython'")
assert_known_marker("platform_system == 'Linux'")
assert_known_marker("platform_machine == 'x86_64'")

def assert_unknown_marker(expression):
# type: (str) -> None
Expand All @@ -123,4 +124,23 @@ def assert_unknown_marker(expression):
assert_unknown_marker("python_full_version == '3.7.10'")
assert_unknown_marker("platform_release == '5.12.12-arch1-1'")
assert_unknown_marker("platform_version == '#1 SMP PREEMPT Fri, 18 Jun 2021 21:59:22 +0000'")
assert_unknown_marker("platform_machine == 'x86_64'")


def test_platform_marker_environment_issue_1488():
# type: () -> None

def assert_platform_machine(
expected, # type: str
platform, # type: str
):
assert expected == Platform.create(platform).marker_environment()["platform_machine"]

assert_platform_machine("x86_64", "linux-x86_64-cp-37-cp37m")
assert_platform_machine("x86_64", "manylinux1-x86_64-cp-37-cp37m")
assert_platform_machine("x86_64", "manylinux2010-x86_64-cp-37-cp37m")
assert_platform_machine("x86_64", "manylinux2014-x86_64-cp-37-cp37m")
assert_platform_machine("x86_64", "manylinux_2_5-x86_64-cp-37-cp37m")
assert_platform_machine("aarch64", "manylinux_2_77-aarch64-cp-37-cp37m")

assert_platform_machine("x86_64", "macosx-10.15-x86_64-cp-38-m")
assert_platform_machine("arm64", "macosx-11.0-arm64-cp-39-cp39")