diff --git a/pex/bin/pex.py b/pex/bin/pex.py index 8ca249286..7313dfc88 100755 --- a/pex/bin/pex.py +++ b/pex/bin/pex.py @@ -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) diff --git a/tests/integration/test_issue_2391.py b/tests/integration/test_issue_2391.py new file mode 100644 index 000000000..c07db0907 --- /dev/null +++ b/tests/integration/test_issue_2391.py @@ -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) + ) + )