Skip to content

Commit

Permalink
Fix lock downloads to use all lock info. (pex-tool#2396)
Browse files Browse the repository at this point in the history
Previously, the lock target systems and requires python configuration
were left out, which could lead to critical Pip runtime patches being
left off; causing downloads to fail when they should not.

Fixes pex-tool#2395
  • Loading branch information
jsirois committed Apr 12, 2024
1 parent 1921ba4 commit fa0995b
Show file tree
Hide file tree
Showing 12 changed files with 1,000 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
@@ -1,5 +1,12 @@
# Release Notes

## 2.3.1

This release fixes Pex to respect lock file interpreter constraints and
target systems when downloading artifacts.

* Fix lock downloads to use all lock info. (#2396)

## 2.3.0

This release introduces `pex3 lock sync` as a higher-level tool that
Expand Down
5 changes: 3 additions & 2 deletions pex/resolve/downloads.py
Expand Up @@ -15,7 +15,7 @@
from pex.pip.installation import get_pip
from pex.pip.tool import PackageIndexConfiguration, Pip
from pex.resolve import locker
from pex.resolve.locked_resolve import Artifact, FileArtifact, LockConfiguration, LockStyle
from pex.resolve.locked_resolve import Artifact, FileArtifact, LockConfiguration
from pex.resolve.resolved_requirement import ArtifactURL, Fingerprint, PartialArtifact
from pex.resolve.resolvers import Resolver
from pex.result import Error
Expand Down Expand Up @@ -50,6 +50,7 @@ def get_downloads_dir(pex_root=None):
@attr.s(frozen=True)
class ArtifactDownloader(object):
resolver = attr.ib() # type: Resolver
lock_configuration = attr.ib() # type: LockConfiguration
target = attr.ib(factory=LocalInterpreter.create) # type: Target
package_index_configuration = attr.ib(
factory=PackageIndexConfiguration.create
Expand Down Expand Up @@ -113,7 +114,7 @@ def _download(
# restrictions.
download_observer = DownloadObserver(
analyzer=None,
patch_set=locker.patch(lock_configuration=LockConfiguration(style=LockStyle.UNIVERSAL)),
patch_set=locker.patch(lock_configuration=self.lock_configuration),
)
return self.pip.spawn_download_distributions(
download_dir=download_dir,
Expand Down
6 changes: 6 additions & 0 deletions pex/resolve/lock_resolver.py
Expand Up @@ -27,6 +27,7 @@
DownloadableArtifact,
FileArtifact,
LocalProjectArtifact,
LockConfiguration,
VCSArtifact,
)
from pex.resolve.lockfile.download_manager import DownloadedArtifact, DownloadManager
Expand Down Expand Up @@ -281,6 +282,11 @@ def resolve_from_lock(
file_lock_style=file_lock_style,
downloader=ArtifactDownloader(
resolver=resolver,
lock_configuration=LockConfiguration(
style=lock.style,
requires_python=lock.requires_python,
target_systems=lock.target_systems,
),
target=resolved_subset.target,
package_index_configuration=PackageIndexConfiguration.create(
pip_version=pip_version,
Expand Down
1 change: 1 addition & 0 deletions pex/resolve/lockfile/create.py
Expand Up @@ -331,6 +331,7 @@ def lock(self, downloaded):
dist_metadatas=dist_metadatas_by_target[target],
fingerprinter=ArtifactDownloader(
resolver=self.resolver,
lock_configuration=self.lock_configuration,
target=target,
package_index_configuration=self.package_index_configuration,
max_parallel_jobs=self.max_parallel_jobs,
Expand Down
2 changes: 1 addition & 1 deletion pex/version.py
@@ -1,4 +1,4 @@
# Copyright 2015 Pex project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

__version__ = "2.3.0"
__version__ = "2.3.1"
14 changes: 9 additions & 5 deletions testing/cli.py
@@ -1,28 +1,32 @@
# Copyright 2022 Pex project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import absolute_import, division, print_function, unicode_literals
from __future__ import absolute_import

import subprocess
import sys

from pex.typing import TYPE_CHECKING
from pex.compatibility import to_unicode
from pex.typing import TYPE_CHECKING, cast
from testing import IntegResults

if TYPE_CHECKING:
from typing import Text # noqa
from typing import Any


def run_pex3(
*args, # type: str
**popen_kwargs # type: Any
**kwargs # type: Any
):
# type: (...) -> IntegResults

python = cast("Text", kwargs.pop("python", to_unicode(sys.executable)))
process = subprocess.Popen(
args=[sys.executable, "-mpex.cli"] + list(args),
args=[python, "-mpex.cli"] + list(args),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
**popen_kwargs
**kwargs
)
stdout, stderr = process.communicate()
return IntegResults(
Expand Down

0 comments on commit fa0995b

Please sign in to comment.