Skip to content

Commit

Permalink
Work around pypa/pip#12156.
Browse files Browse the repository at this point in the history
It seems to be the case that PEP-658 metadata is backfilling which
triggers bugs in the legacy resolver under Pip 23.2.
  • Loading branch information
jsirois committed Feb 27, 2024
1 parent 41f926b commit 718d5bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pex/pip/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Pip(object):
_PATCHES_PACKAGE_NAME = "_pex_pip_patches"

_pip = attr.ib() # type: PipVenv
_version = attr.ib() # type: PipVersionValue
version = attr.ib() # type: PipVersionValue
_pip_cache = attr.ib() # type: str

@staticmethod
Expand Down Expand Up @@ -599,7 +599,7 @@ def _ensure_wheel_installed(self, package_index_configuration=None):
if not atomic_dir.is_finalized():
self.spawn_download_distributions(
download_dir=atomic_dir.work_dir,
requirements=[self._version.wheel_requirement],
requirements=[self.version.wheel_requirement],
package_index_configuration=package_index_configuration,
build_configuration=BuildConfiguration.create(allow_builds=False),
).wait()
Expand All @@ -617,7 +617,7 @@ def spawn_build_wheels(
):
# type: (...) -> Job

if self._version is PipVersion.VENDORED:
if self.version is PipVersion.VENDORED:
self._ensure_wheel_installed(package_index_configuration=package_index_configuration)

wheel_cmd = ["wheel", "--no-deps", "--wheel-dir", wheel_dir]
Expand Down
22 changes: 16 additions & 6 deletions tests/test_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pex.pip.version import PipVersion, PipVersionValue
from pex.platforms import Platform
from pex.resolve.configured_resolver import ConfiguredResolver
from pex.resolve.resolver_configuration import ResolverVersion
from pex.targets import AbbreviatedPlatform, LocalInterpreter, Target
from pex.typing import TYPE_CHECKING
from pex.variables import ENV
Expand Down Expand Up @@ -105,6 +106,17 @@ def test_no_duplicate_constraints_pex_warnings(
)


def package_index_configuration(pip_version):
# type: (PipVersionValue) -> Optional[PackageIndexConfiguration]
if pip_version is PipVersion.v23_2:
# N.B.: Pip 23.2 has a bug handling PEP-658 metadata with the legacy resolver; so we use the
# 2020 resolver to work around. See: https://github.com/pypa/pip/issues/12156
return PackageIndexConfiguration.create(
pip_version, resolver_version=ResolverVersion.PIP_2020
)
return None


@pytest.mark.skipif(
not IS_LINUX
or not any(
Expand All @@ -126,18 +138,15 @@ def test_download_platform_issues_1355(
pip = create_pip(py38, version=version)
download_dir = os.path.join(str(tmpdir), "downloads")

def download_pyarrow(
target=None, # type: Optional[Target]
package_index_configuration=None, # type: Optional[PackageIndexConfiguration]
):
# type: (...) -> Job
def download_pyarrow(target=None):
# type: (Optional[Target]) -> Job
safe_rmtree(download_dir)
return pip.spawn_download_distributions(
download_dir=download_dir,
requirements=["pyarrow==4.0.1"],
transitive=False,
target=target,
package_index_configuration=package_index_configuration,
package_index_configuration=package_index_configuration(pip.version),
)

def assert_pyarrow_downloaded(
Expand Down Expand Up @@ -256,6 +265,7 @@ def test_download_platform_markers_issue_1488(
constraint_files=[constraints_file],
download_dir=download_dir,
transitive=True,
package_index_configuration=package_index_configuration(version),
).wait()

assert (
Expand Down

0 comments on commit 718d5bf

Please sign in to comment.