Skip to content

Commit ffcf590

Browse files
committed
Always use pep 517 when the 'wheel' package is absent
1 parent e798211 commit ffcf590

File tree

7 files changed

+18
-63
lines changed

7 files changed

+18
-63
lines changed

news/8559.removal.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
When the ``wheel`` package is not installed, pip now uses the default build backend
2+
instead of ``setup.py install`` for project without ``pyproject.toml``.

src/pip/_internal/cli/cmdoptions.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -783,11 +783,15 @@ def _handle_no_use_pep517(
783783
"""
784784
raise_option_error(parser, option=option, msg=msg)
785785

786-
# If user doesn't wish to use pep517, we check if setuptools is installed
786+
# If user doesn't wish to use pep517, we check if setuptools and wheel are installed
787787
# and raise error if it is not.
788-
if not importlib.util.find_spec("setuptools"):
789-
msg = "It is not possible to use --no-use-pep517 without setuptools installed."
790-
raise_option_error(parser, option=option, msg=msg)
788+
for package in ("setuptools", "wheel"):
789+
if not importlib.util.find_spec(package):
790+
msg = (
791+
f"It is not possible to use --no-use-pep517 "
792+
f"without {package} installed."
793+
)
794+
raise_option_error(parser, option=option, msg=msg)
791795

792796
# Otherwise, --no-use-pep517 was passed via the command-line.
793797
parser.values.use_pep517 = False

src/pip/_internal/pyproject.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,17 @@ def load_pyproject_toml(
9393
# we do so if the project has a pyproject.toml file
9494
# or if we cannot import setuptools.
9595

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

103108
# At this point, we know whether we're going to use PEP 517.
104109
assert use_pep517 is not None

src/pip/_internal/utils/deprecation.py

-14
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,3 @@ def emit_deprecation(self, name: str) -> None:
159159
issue=8368,
160160
emit_after_success=True,
161161
)
162-
163-
164-
LegacyInstallReasonMissingWheelPackage = LegacyInstallReason(
165-
reason=(
166-
"{name} is being installed using the legacy "
167-
"'setup.py install' method, because it does not have a "
168-
"'pyproject.toml' and the 'wheel' package "
169-
"is not installed."
170-
),
171-
replacement="to enable the '--use-pep517' option",
172-
gone_in="23.1",
173-
issue=8559,
174-
emit_before_install=True,
175-
)

src/pip/_internal/utils/misc.py

-12
Original file line numberDiff line numberDiff line change
@@ -614,18 +614,6 @@ def hash_file(path: str, blocksize: int = 1 << 20) -> Tuple[Any, int]:
614614
return h, length
615615

616616

617-
def is_wheel_installed() -> bool:
618-
"""
619-
Return whether the wheel package is installed.
620-
"""
621-
try:
622-
import wheel # noqa: F401
623-
except ImportError:
624-
return False
625-
626-
return True
627-
628-
629617
def pairwise(iterable: Iterable[Any]) -> Iterator[Tuple[Any, Any]]:
630618
"""
631619
Return paired elements.

src/pip/_internal/wheel_builder.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
from pip._internal.operations.build.wheel_editable import build_wheel_editable
2020
from pip._internal.operations.build.wheel_legacy import build_wheel_legacy
2121
from pip._internal.req.req_install import InstallRequirement
22-
from pip._internal.utils.deprecation import LegacyInstallReasonMissingWheelPackage
2322
from pip._internal.utils.logging import indent_log
24-
from pip._internal.utils.misc import ensure_dir, hash_file, is_wheel_installed
23+
from pip._internal.utils.misc import ensure_dir, hash_file
2524
from pip._internal.utils.setuptools_build import make_setuptools_clean_args
2625
from pip._internal.utils.subprocess import call_subprocess
2726
from pip._internal.utils.temp_dir import TempDirectory
@@ -73,14 +72,6 @@ def _should_build(
7372
# we only build PEP 660 editable requirements
7473
return req.supports_pyproject_editable()
7574

76-
if req.use_pep517:
77-
return True
78-
79-
if not is_wheel_installed():
80-
# we don't build legacy requirements if wheel is not installed
81-
req.legacy_install_reason = LegacyInstallReasonMissingWheelPackage
82-
return False
83-
8475
return True
8576

8677

tests/unit/test_wheel_builder.py

-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
from pathlib import Path
44
from typing import Optional, cast
5-
from unittest import mock
65

76
import pytest
87

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

119118

120-
@mock.patch("pip._internal.wheel_builder.is_wheel_installed")
121-
def test_should_build_legacy_wheel_not_installed(is_wheel_installed: mock.Mock) -> None:
122-
is_wheel_installed.return_value = False
123-
legacy_req = ReqMock(use_pep517=False)
124-
should_build = wheel_builder.should_build_for_install_command(
125-
cast(InstallRequirement, legacy_req),
126-
)
127-
assert not should_build
128-
129-
130-
@mock.patch("pip._internal.wheel_builder.is_wheel_installed")
131-
def test_should_build_legacy_wheel_installed(is_wheel_installed: mock.Mock) -> None:
132-
is_wheel_installed.return_value = True
133-
legacy_req = ReqMock(use_pep517=False)
134-
should_build = wheel_builder.should_build_for_install_command(
135-
cast(InstallRequirement, legacy_req),
136-
)
137-
assert should_build
138-
139-
140119
@pytest.mark.parametrize(
141120
"req, expected",
142121
[

0 commit comments

Comments
 (0)