Skip to content

Commit

Permalink
Eliminate warnings for default use.
Browse files Browse the repository at this point in the history
Previously `pex` would warn for default usage scenarios under both
Python 3.11 and Python 3.12. For Python 3.12, the `--pip-version`
defaulted to 23.2 but a warning about vendored Pip 20.3.4 was issued
anyway; this is now fixed. For both Python 3.11 and Python 3.12, the
vendored version of packaging used the deprecated `sre_constants`
stdlib module; this is now fixed with packaging 23.1 being vendored
and selected for Python >= 3.7.

Fixes #2186
  • Loading branch information
jsirois committed Jul 23, 2023
1 parent 2ce43da commit 7215a61
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 10 deletions.
8 changes: 4 additions & 4 deletions pex/bin/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from pex.resolve.configured_resolve import resolve
from pex.resolve.requirement_configuration import RequirementConfiguration
from pex.resolve.resolvers import Unsatisfiable
from pex.result import catch
from pex.result import ResultError, catch, try_
from pex.targets import Targets
from pex.tracer import TRACER
from pex.typing import TYPE_CHECKING, cast
Expand Down Expand Up @@ -886,8 +886,8 @@ def main(args=None):
except target_configuration.InterpreterConstraintsNotSatisfied as e:
die(str(e), exit_code=CANNOT_SETUP_INTERPRETER)

resolver_configuration = finalize_resolve_config(
resolver_configuration, targets, context="PEX building"
resolver_configuration = try_(
finalize_resolve_config(resolver_configuration, targets, context="PEX building")
)

sys.exit(
Expand All @@ -902,7 +902,7 @@ def main(args=None):
env=env,
)
)
except GlobalConfigurationError as e:
except (GlobalConfigurationError, ResultError) as e:
die(str(e))


Expand Down
9 changes: 6 additions & 3 deletions pex/pip/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def _resolved_installation(
targets,
PipVersion.VENDORED,
context="Bootstrapping Pip {version}".format(version=version),
warn=False,
)
)
if bootstrap_pip_version is not PipVersion.VENDORED:
Expand Down Expand Up @@ -217,6 +218,7 @@ def compatible_version(
targets, # type: Targets
requested_version, # type: PipVersionValue
context, # type: str
warn=True, # type: bool
):
# type: (...) -> Union[PipVersionValue, Error]
try:
Expand All @@ -228,9 +230,10 @@ def compatible_version(
for version in remaining_versions:
try:
validate_targets(targets, version, context)
pex_warnings.warn(
"{err}\n" "\n" "Using Pip {version} instead.".format(err=e, version=version)
)
if warn:
pex_warnings.warn(
"{err}\n" "\n" "Using Pip {version} instead.".format(err=e, version=version)
)
return version
except RequiresPythonError:
continue
Expand Down
4 changes: 3 additions & 1 deletion pex/vendor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ def iter_vendor_specs(filter_requires_python=False):
yield VendorSpec.pinned(
"packaging", "20.9", import_path="packaging_20_9", constraints=("pyparsing<3",)
)
if not filter_requires_python or sys.version_info[:2] >= (3, 6):
if not filter_requires_python or sys.version_info[:2] == (3, 6):
# N.B.: The pyparsing constraint is needed because our import re-writer (RedBaron) chokes on
# newer versions.
yield VendorSpec.pinned(
"packaging", "21.3", import_path="packaging_21_3", constraints=("pyparsing<3",)
)
if not filter_requires_python or sys.version_info[:2] >= (3, 7):
yield VendorSpec.pinned("packaging", "23.1", import_path="packaging_23_1")

# We use toml to read pyproject.toml when building sdists from local source projects.
yield VendorSpec.pinned("toml", "0.10.2")
Expand Down
2 changes: 1 addition & 1 deletion scripts/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def build_pex_pex(output_file: PurePath, verbosity: int = 0) -> None:

def describe_git_rev() -> str:
git_describe = subprocess.run(
["git", "describe"], check=True, capture_output=True, encoding="utf-8"
["git", "describe"], check=True, stdout=subprocess.PIPE, encoding="utf-8"
)
return git_describe.stdout.strip()

Expand Down
78 changes: 78 additions & 0 deletions tests/integration/test_issue_2186.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from textwrap import dedent
from typing import NoReturn, Union

import pytest

from pex import targets
from pex.interpreter import PythonInterpreter
from pex.pip.version import PipVersion, PipVersionValue
from pex.testing import IntegResults, run_pex_command


def pex_execute_cowsay(*extra_pex_args):
# type: (*str) -> IntegResults
return run_pex_command(
args=list(extra_pex_args) + ["cowsay==5.0", "-c", "cowsay", "--", "Moo!"], quiet=True
)


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

result = pex_execute_cowsay()
result.assert_success()
assert not result.error
assert "Moo!" in result.output


@pytest.fixture
def incompatible_pip_version():
# type: () -> Union[PipVersionValue, NoReturn]
for pip_version in PipVersion.values():
if not pip_version.requires_python_applies(targets.current()):
return pip_version

pytest.skip(
"There is no supported Pip version incompatible with {interpreter}.".format(
interpreter=PythonInterpreter.get()
)
)
raise AssertionError("Unreachable: satisfy type checker.")


def expected_incompatible_pip_message(incompatible_pip_version):
# type: (PipVersionValue) -> str
return dedent(
"""\
Pip {pip_version} requires Python {python_req} and the following target does not apply:
1. {target}
""".format(
pip_version=incompatible_pip_version,
python_req=incompatible_pip_version.requires_python,
target=targets.current(),
)
)


def test_incompatible_resolve_warning(incompatible_pip_version):
# type: (PipVersionValue) -> None

result = pex_execute_cowsay("--pip-version", str(incompatible_pip_version))
result.assert_success()
assert expected_incompatible_pip_message(incompatible_pip_version) in result.error, result.error
assert "Moo!" in result.output, result.output


def test_incompatible_resolve_error(incompatible_pip_version):
# type: (PipVersionValue) -> None

result = pex_execute_cowsay(
"--pip-version", str(incompatible_pip_version), "--no-allow-pip-version-fallback"
)
result.assert_failure()
assert result.error.endswith(
expected_incompatible_pip_message(incompatible_pip_version)
), result.error
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ deps =
# Python < 3.6 in newer releases so we force low here.
more-itertools<=8.10.0; python_version < "3.6"
pytest==4.6.11; python_version < "3.6"
pytest==6.2.5; python_version >= "3.6"
pytest==6.2.5; python_version == "3.6"
pytest==7.4.0; python_version >= "3.7"
pkginfo==1.7.0
py{27,py27}: mock==3.0.5
subprocess: subprocess32
Expand Down

0 comments on commit 7215a61

Please sign in to comment.