Skip to content

Commit 123e8a4

Browse files
authored
Merge pull request #11871 from sbidoul/always-use-pep517-when-wheel-absent-sbi
Always use pep 517 when the 'wheel' package is absent
2 parents b0a2841 + e4d291c commit 123e8a4

29 files changed

+69
-230
lines changed

news/8559.removal.rst

Lines changed: 2 additions & 0 deletions
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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,14 @@ 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."
788+
packages = ("setuptools", "wheel")
789+
if not all(importlib.util.find_spec(package) for package in packages):
790+
msg = (
791+
f"It is not possible to use --no-use-pep517 "
792+
f"without {' and '.join(packages)} installed."
793+
)
790794
raise_option_error(parser, option=option, msg=msg)
791795

792796
# Otherwise, --no-use-pep517 was passed via the command-line.

src/pip/_internal/pyproject.py

Lines changed: 7 additions & 2 deletions
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

Lines changed: 0 additions & 14 deletions
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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -615,18 +615,6 @@ def hash_file(path: str, blocksize: int = 1 << 20) -> Tuple[Any, int]:
615615
return h, length
616616

617617

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

src/pip/_internal/wheel_builder.py

Lines changed: 1 addition & 10 deletions
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/conftest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def virtualenv_template(
429429
tmpdir_factory: pytest.TempPathFactory,
430430
pip_src: Path,
431431
setuptools_install: Path,
432+
wheel_install: Path,
432433
coverage_install: Path,
433434
) -> Iterator[VirtualEnvironment]:
434435

@@ -442,8 +443,9 @@ def virtualenv_template(
442443
tmpdir = tmpdir_factory.mktemp("virtualenv")
443444
venv = VirtualEnvironment(tmpdir.joinpath("venv_orig"), venv_type=venv_type)
444445

445-
# Install setuptools and pip.
446+
# Install setuptools, wheel and pip.
446447
install_pth_link(venv, "setuptools", setuptools_install)
448+
install_pth_link(venv, "wheel", wheel_install)
447449
pip_editable = tmpdir_factory.mktemp("pip") / "pip"
448450
shutil.copytree(pip_src, pip_editable, symlinks=True)
449451
# noxfile.py is Python 3 only
@@ -501,11 +503,6 @@ def virtualenv(
501503
yield virtualenv_factory(tmpdir.joinpath("workspace", "venv"))
502504

503505

504-
@pytest.fixture
505-
def with_wheel(virtualenv: VirtualEnvironment, wheel_install: Path) -> None:
506-
install_pth_link(virtualenv, "wheel", wheel_install)
507-
508-
509506
class ScriptFactory(Protocol):
510507
def __call__(
511508
self,

tests/data/packages/BrokenEmitsUTF8/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class FakeError(Exception):
88
pass
99

1010

11-
if sys.argv[1] == "install":
11+
if sys.argv[1] in ("install", "bdist_wheel"):
1212
if hasattr(sys.stdout, "buffer"):
1313
sys.stdout.buffer.write(
1414
"\nThis package prints out UTF-8 stuff like:\n".encode("utf-8")

tests/functional/test_download.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@ def make_wheel_with_python_requires(
659659
return package_dir / "dist" / file_name
660660

661661

662-
@pytest.mark.usefixtures("with_wheel")
663662
def test_download__python_version_used_for_python_requires(
664663
script: PipTestEnvironment, data: TestData
665664
) -> None:
@@ -700,7 +699,6 @@ def make_args(python_version: str) -> List[str]:
700699
script.pip(*args) # no exception
701700

702701

703-
@pytest.mark.usefixtures("with_wheel")
704702
def test_download_ignore_requires_python_dont_fail_with_wrong_python(
705703
script: PipTestEnvironment,
706704
) -> None:

tests/functional/test_freeze.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def test_exclude_and_normalization(script: PipTestEnvironment, tmpdir: Path) ->
104104
assert "Normalizable_Name" not in result.stdout
105105

106106

107-
@pytest.mark.usefixtures("with_wheel")
108107
def test_freeze_multiple_exclude_with_all(script: PipTestEnvironment) -> None:
109108
result = script.pip("freeze", "--all")
110109
assert "pip==" in result.stdout
@@ -962,7 +961,6 @@ def test_freeze_path_multiple(
962961
_check_output(result.stdout, expected)
963962

964963

965-
@pytest.mark.usefixtures("with_wheel")
966964
def test_freeze_direct_url_archive(
967965
script: PipTestEnvironment, shared_data: TestData
968966
) -> None:
@@ -1005,7 +1003,6 @@ def test_freeze_include_work_dir_pkg(script: PipTestEnvironment) -> None:
10051003
assert "simple==1.0" in result.stdout
10061004

10071005

1008-
@pytest.mark.usefixtures("with_wheel")
10091006
def test_freeze_pep610_editable(script: PipTestEnvironment) -> None:
10101007
"""
10111008
Test that a package installed with a direct_url.json with editable=true

tests/functional/test_inspect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ def test_inspect_basic(simple_script: PipTestEnvironment) -> None:
3131
result = simple_script.pip("inspect")
3232
report = json.loads(result.stdout)
3333
installed = report["installed"]
34-
assert len(installed) == 4
34+
assert len(installed) == 5
3535
installed_by_name = {i["metadata"]["name"]: i for i in installed}
3636
assert installed_by_name.keys() == {
3737
"pip",
3838
"setuptools",
39+
"wheel",
3940
"coverage",
4041
"simplewheel",
4142
}

0 commit comments

Comments
 (0)