Skip to content

Commit

Permalink
Guard against mismatched --requirements-pex.
Browse files Browse the repository at this point in the history
Pex cannot yet handle turning installed wheel chroots back into wheel
files (see pex-tool#2299). As such, until that time, it must reject attempts
to combine PEXes with different wheel packaging.

Clarifies pex-tool#2391
  • Loading branch information
jsirois committed Mar 24, 2024
1 parent 2aeead3 commit a6bdb31
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pex/bin/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,27 @@ def build_pex(
"Adding distributions from pexes: {}".format(" ".join(options.requirements_pexes))
):
for requirements_pex in options.requirements_pexes:
if (
pex_info.deps_are_wheel_files
!= PexInfo.from_pex(requirements_pex).deps_are_wheel_files
):
die(
"The {option} option was selected but the --requirements-pex "
"{requirements_pex} is built with {opposite_option}. Any --requirements-pex "
"you want to merge into the main PEX must be built with {option}.".format(
option=(
"--no-pre-install-wheels"
if pex_info.deps_are_wheel_files
else "--pre-install-wheels"
),
requirements_pex=requirements_pex,
opposite_option=(
"--pre-install-wheels"
if pex_info.deps_are_wheel_files
else "--no-pre-install-wheels"
),
)
)
requirements_pex_info = dependency_manager.add_from_pex(requirements_pex)
excluded.extend(requirements_pex_info.excluded)

Expand Down
68 changes: 68 additions & 0 deletions tests/integration/test_issue_2391.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2014 Pex project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import os.path
import re
import subprocess

from pex.typing import TYPE_CHECKING
from testing import run_pex_command

if TYPE_CHECKING:
from typing import Any


def test_requirements_pex_wheel_type_mismatch(tmpdir):
# type: (Any)-> None

pre_installed_reqs_pex = os.path.join(str(tmpdir), "pre_installed_reqs.pex")
run_pex_command(args=["cowsay==5.0", "-o", pre_installed_reqs_pex]).assert_success()

wheel_file_reqs_pex = os.path.join(str(tmpdir), "wheel_file_reqs.pex")
run_pex_command(
args=["cowsay==5.0", "--no-pre-install-wheels", "-o", wheel_file_reqs_pex]
).assert_success()

pex = os.path.join(str(tmpdir), "pex")

def assert_pex():
# type: () -> None
assert "5.0" == subprocess.check_output(args=[pex, "--version"]).decode("utf-8").strip()

run_pex_command(
args=["--requirements-pex", pre_installed_reqs_pex, "-c" "cowsay", "-o", pex]
).assert_success()
assert_pex()

run_pex_command(
args=[
"--requirements-pex",
wheel_file_reqs_pex,
"--no-pre-install-wheels",
"-c",
"cowsay",
"-o",
pex,
]
).assert_success()
assert_pex()

run_pex_command(
args=["--no-pre-install-wheels", "--requirements-pex", pre_installed_reqs_pex], quiet=True
).assert_failure(
expected_error_re=re.escape(
"The --no-pre-install-wheels option was selected but the --requirements-pex {reqs_pex} "
"is built with --pre-install-wheels. Any --requirements-pex you want to merge into the "
"main PEX must be built with --no-pre-install-wheels.".format(
reqs_pex=pre_installed_reqs_pex
)
)
)

run_pex_command(args=["--requirements-pex", wheel_file_reqs_pex], quiet=True).assert_failure(
expected_error_re=re.escape(
"The --pre-install-wheels option was selected but the --requirements-pex {reqs_pex} is "
"built with --no-pre-install-wheels. Any --requirements-pex you want to merge into the "
"main PEX must be built with --pre-install-wheels.".format(reqs_pex=wheel_file_reqs_pex)
)
)

0 comments on commit a6bdb31

Please sign in to comment.