Skip to content

Commit

Permalink
Always use pep 517 when the 'wheel' package is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Mar 18, 2023
1 parent e798211 commit 666f3e3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 59 deletions.
2 changes: 2 additions & 0 deletions news/8559.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When the ``wheel`` package is not installed, pip now uses the default build backend
instead of ``setup.py install`` for project without ``pyproject.toml``.
9 changes: 7 additions & 2 deletions src/pip/_internal/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ def load_pyproject_toml(
# we do so if the project has a pyproject.toml file
# or if we cannot import setuptools.

# We fallback to PEP 517 when without setuptools,
# We fallback to PEP 517 when without setuptools or without the wheel package,
# so setuptools can be installed as a default build backend.
# For more info see:
# https://discuss.python.org/t/pip-without-setuptools-could-the-experience-be-improved/11810/9
# https://github.com/pypa/pip/issues/8559
elif use_pep517 is None:
use_pep517 = has_pyproject or not importlib.util.find_spec("setuptools")
use_pep517 = (
has_pyproject
or not importlib.util.find_spec("setuptools")
or not importlib.util.find_spec("wheel")
)

# At this point, we know whether we're going to use PEP 517.
assert use_pep517 is not None
Expand Down
14 changes: 0 additions & 14 deletions src/pip/_internal/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,3 @@ def emit_deprecation(self, name: str) -> None:
issue=8368,
emit_after_success=True,
)


LegacyInstallReasonMissingWheelPackage = LegacyInstallReason(
reason=(
"{name} is being installed using the legacy "
"'setup.py install' method, because it does not have a "
"'pyproject.toml' and the 'wheel' package "
"is not installed."
),
replacement="to enable the '--use-pep517' option",
gone_in="23.1",
issue=8559,
emit_before_install=True,
)
12 changes: 0 additions & 12 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,18 +614,6 @@ def hash_file(path: str, blocksize: int = 1 << 20) -> Tuple[Any, int]:
return h, length


def is_wheel_installed() -> bool:
"""
Return whether the wheel package is installed.
"""
try:
import wheel # noqa: F401
except ImportError:
return False

return True


def pairwise(iterable: Iterable[Any]) -> Iterator[Tuple[Any, Any]]:
"""
Return paired elements.
Expand Down
11 changes: 1 addition & 10 deletions src/pip/_internal/wheel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
from pip._internal.operations.build.wheel_editable import build_wheel_editable
from pip._internal.operations.build.wheel_legacy import build_wheel_legacy
from pip._internal.req.req_install import InstallRequirement
from pip._internal.utils.deprecation import LegacyInstallReasonMissingWheelPackage
from pip._internal.utils.logging import indent_log
from pip._internal.utils.misc import ensure_dir, hash_file, is_wheel_installed
from pip._internal.utils.misc import ensure_dir, hash_file
from pip._internal.utils.setuptools_build import make_setuptools_clean_args
from pip._internal.utils.subprocess import call_subprocess
from pip._internal.utils.temp_dir import TempDirectory
Expand Down Expand Up @@ -73,14 +72,6 @@ def _should_build(
# we only build PEP 660 editable requirements
return req.supports_pyproject_editable()

if req.use_pep517:
return True

if not is_wheel_installed():
# we don't build legacy requirements if wheel is not installed
req.legacy_install_reason = LegacyInstallReasonMissingWheelPackage
return False

return True


Expand Down
21 changes: 0 additions & 21 deletions tests/unit/test_wheel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
from pathlib import Path
from typing import Optional, cast
from unittest import mock

import pytest

Expand Down Expand Up @@ -117,26 +116,6 @@ def test_should_build_for_wheel_command(req: ReqMock, expected: bool) -> None:
assert should_build is expected


@mock.patch("pip._internal.wheel_builder.is_wheel_installed")
def test_should_build_legacy_wheel_not_installed(is_wheel_installed: mock.Mock) -> None:
is_wheel_installed.return_value = False
legacy_req = ReqMock(use_pep517=False)
should_build = wheel_builder.should_build_for_install_command(
cast(InstallRequirement, legacy_req),
)
assert not should_build


@mock.patch("pip._internal.wheel_builder.is_wheel_installed")
def test_should_build_legacy_wheel_installed(is_wheel_installed: mock.Mock) -> None:
is_wheel_installed.return_value = True
legacy_req = ReqMock(use_pep517=False)
should_build = wheel_builder.should_build_for_install_command(
cast(InstallRequirement, legacy_req),
)
assert should_build


@pytest.mark.parametrize(
"req, expected",
[
Expand Down

0 comments on commit 666f3e3

Please sign in to comment.