Skip to content

Commit

Permalink
Since we no longer use wheel code, remove it. (#2302)
Browse files Browse the repository at this point in the history
Lots of changes over a long time have led to this point. The last small
one is in this change, installing wheel in the vendored Pip venv just in
time when wheel building is required by using vendored Pip itself and
the user configured indexes, etc.
  • Loading branch information
jsirois authored Dec 14, 2023
1 parent efe709f commit 8a6fe31
Show file tree
Hide file tree
Showing 35 changed files with 75 additions and 2,879 deletions.
32 changes: 20 additions & 12 deletions pex/build_system/pep_517.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

from __future__ import absolute_import

import itertools
import json
import os
import subprocess
import sys
from collections import defaultdict
from textwrap import dedent

from pex import third_party
Expand All @@ -24,7 +26,7 @@
from pex.util import named_temporary_file

if TYPE_CHECKING:
from typing import Any, Dict, Iterable, Mapping, Optional, Text, Union
from typing import Any, DefaultDict, Dict, Iterable, List, Mapping, Optional, Set, Text, Union

_DEFAULT_BUILD_SYSTEMS = {} # type: Dict[PipVersionValue, BuildSystem]

Expand All @@ -43,32 +45,38 @@ def _default_build_system(
"Building {build_backend} build_backend PEX".format(build_backend=DEFAULT_BUILD_BACKEND)
):
extra_env = {} # type: Dict[str, str]
resolved_reqs = set() # type: Set[str]
resolved_dists = [] # type: List[Distribution]
if selected_pip_version is PipVersion.VENDORED:
requires = ["setuptools", "wheel"]
resolved = tuple(
requires = ["setuptools", selected_pip_version.wheel_requirement]
resolved_dists.extend(
Distribution.load(dist_location)
for dist_location in third_party.expose(
requires, interpreter=target.get_interpreter()
["setuptools"], interpreter=target.get_interpreter()
)
)
resolved_reqs.add("setuptools")
extra_env.update(__PEX_UNVENDORED__="1")
else:
requires = [
selected_pip_version.setuptools_requirement,
selected_pip_version.wheel_requirement,
]
resolved = tuple(
resolved_distribution.fingerprinted_distribution.distribution
for resolved_distribution in resolver.resolve_requirements(
requirements=requires,
targets=Targets.from_target(target),
).distributions
)
unresolved = [
requirement for requirement in requires if requirement not in resolved_reqs
]
resolved_dists.extend(
resolved_distribution.fingerprinted_distribution.distribution
for resolved_distribution in resolver.resolve_requirements(
requirements=unresolved,
targets=Targets.from_target(target),
).distributions
)
build_system = try_(
BuildSystem.create(
interpreter=target.get_interpreter(),
requires=requires,
resolved=resolved,
resolved=resolved_dists,
build_backend=DEFAULT_BUILD_BACKEND,
backend_path=(),
**extra_env
Expand Down
9 changes: 0 additions & 9 deletions pex/pex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,20 +641,11 @@ def _prepare_bootstrap(self):
# although we don't use pyparsing directly, packaging.markers, which we
# do use at runtime, does.
root_module_names = ["attr", "packaging", "pkg_resources", "pyparsing"]
include_dist_info = set()
if self._pex_info.includes_tools:
# The `repository extract` tool needs setuptools and wheel to build sdists and wheels
# and distutils needs .dist-info to discover setuptools (and wheel).
for project in "setuptools", "wheel":
root_module_names.append(project)
include_dist_info.add(project)

prepared_sources = vendor.vendor_runtime(
chroot=self._chroot,
dest_basedir=self._pex_info.bootstrap,
label="bootstrap",
root_module_names=root_module_names,
include_dist_info=include_dist_info,
)

bootstrap_digest = hashlib.sha1()
Expand Down
4 changes: 2 additions & 2 deletions pex/pip/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _pip_installation(
pip_cache = os.path.join(pip_root, "pip_cache")
pip_pex = ensure_venv(PEX(pip_pex_path, interpreter=pip_interpreter))
pip_venv = PipVenv(venv_dir=pip_pex.venv_dir, execute_args=tuple(pip_pex.execute_args()))
return Pip(pip=pip_venv, pip_cache=pip_cache)
return Pip(pip=pip_venv, version=version, pip_cache=pip_cache)


def _vendored_installation(interpreter=None):
Expand All @@ -84,7 +84,7 @@ def _vendored_installation(interpreter=None):
return _pip_installation(
version=PipVersion.VENDORED,
iter_distribution_locations=lambda: third_party.expose(
("pip", "setuptools", "wheel"), interpreter=interpreter
("pip", "setuptools"), interpreter=interpreter
),
interpreter=interpreter,
)
Expand Down
36 changes: 35 additions & 1 deletion pex/pip/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import absolute_import, print_function

import glob
import hashlib
import os
import re
import subprocess
Expand All @@ -13,23 +15,26 @@
from textwrap import dedent

from pex import dist_metadata, targets
from pex.atomic_directory import atomic_directory
from pex.auth import PasswordEntry
from pex.common import safe_mkdir, safe_mkdtemp
from pex.compatibility import get_stderr_bytes_buffer, shlex_quote, urlparse
from pex.interpreter import PythonInterpreter, spawn_python_job
from pex.jobs import Job
from pex.network_configuration import NetworkConfiguration
from pex.pep_427 import install_wheel_interpreter
from pex.pip import foreign_platform
from pex.pip.download_observer import DownloadObserver
from pex.pip.log_analyzer import ErrorAnalyzer, ErrorMessage, LogAnalyzer, LogScrapeJob
from pex.pip.tailer import Tailer
from pex.pip.version import PipVersionValue
from pex.pip.version import PipVersion, PipVersionValue
from pex.platforms import Platform
from pex.resolve.resolver_configuration import ReposConfiguration, ResolverVersion
from pex.targets import LocalInterpreter, Target
from pex.tracer import TRACER
from pex.typing import TYPE_CHECKING
from pex.variables import ENV
from pex.venv.virtualenv import Virtualenv

if TYPE_CHECKING:
from typing import (
Expand Down Expand Up @@ -228,13 +233,18 @@ def execute_args(self, *args):
# type: (*str) -> List[str]
return list(self._execute_args + args)

def get_interpreter(self):
# type: () -> PythonInterpreter
return Virtualenv(self.venv_dir).interpreter


@attr.s(frozen=True)
class Pip(object):
_PATCHES_PACKAGE_ENV_VAR_NAME = "_PEX_PIP_RUNTIME_PATCHES_PACKAGE"
_PATCHES_PACKAGE_NAME = "_pex_pip_patches"

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

@staticmethod
Expand Down Expand Up @@ -565,6 +575,26 @@ def finalizer(_):
else:
return Job(command, process)

def _ensure_wheel_installed(self, package_index_configuration=None):
# type: (Optional[PackageIndexConfiguration]) -> None
pip_interpreter = self._pip.get_interpreter()
with atomic_directory(
os.path.join(
self._pip_cache,
".wheel-install",
hashlib.sha1(pip_interpreter.binary.encode("utf-8")).hexdigest(),
)
) as atomic_dir:
if not atomic_dir.is_finalized():
self.spawn_download_distributions(
download_dir=atomic_dir.work_dir,
requirements=[self._version.wheel_requirement],
package_index_configuration=package_index_configuration,
build=False,
).wait()
for wheel in glob.glob(os.path.join(atomic_dir.work_dir, "*.whl")):
install_wheel_interpreter(wheel_path=wheel, interpreter=pip_interpreter)

def spawn_build_wheels(
self,
distributions, # type: Iterable[str]
Expand All @@ -577,6 +607,10 @@ def spawn_build_wheels(
verify=True, # type: bool
):
# type: (...) -> Job

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]
extra_env = {} # type: Dict[str, str]

Expand Down
1 change: 1 addition & 0 deletions pex/pip/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def values(cls):
requirement=(
"pip @ git+https://github.com/pantsbuild/pip@386a54f097ece66775d0c7f34fd29bb596c6b0be"
),
wheel_version="0.37.1",
requires_python="<3.12",
)

Expand Down
3 changes: 0 additions & 3 deletions pex/vendor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ def iter_vendor_specs(filter_requires_python=None):
],
)

# We expose this to pip at buildtime for legacy builds.
yield VendorSpec.pinned("wheel", "0.37.1", rewrite=False)


def vendor_runtime(
chroot, # type: Chroot
Expand Down
1 change: 0 additions & 1 deletion pex/vendor/_vendored/wheel/.layout.json

This file was deleted.

8 changes: 0 additions & 8 deletions pex/vendor/_vendored/wheel/.prefix/bin/wheel

This file was deleted.

1 change: 0 additions & 1 deletion pex/vendor/_vendored/wheel/constraints.txt

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions pex/vendor/_vendored/wheel/wheel-0.37.1.dist-info/LICENSE.txt

This file was deleted.

69 changes: 0 additions & 69 deletions pex/vendor/_vendored/wheel/wheel-0.37.1.dist-info/METADATA

This file was deleted.

Empty file.
6 changes: 0 additions & 6 deletions pex/vendor/_vendored/wheel/wheel-0.37.1.dist-info/WHEEL

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion pex/vendor/_vendored/wheel/wheel/__init__.py

This file was deleted.

19 changes: 0 additions & 19 deletions pex/vendor/_vendored/wheel/wheel/__main__.py

This file was deleted.

Loading

0 comments on commit 8a6fe31

Please sign in to comment.