Skip to content

Commit e7a790a

Browse files
committed
Fallback to pep517 if setup.py is present and setuptools cannot be imported
1 parent a4f7508 commit e7a790a

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

news/10717.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fallback to pep517 if setup.py is present and setuptools cannot be imported

src/pip/_internal/cli/cmdoptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# The following comment should be removed at some point in the future.
1111
# mypy: strict-optional=False
1212

13+
import importlib.util
1314
import logging
1415
import os
1516
import textwrap
@@ -775,6 +776,13 @@ def _handle_no_use_pep517(
775776
"""
776777
raise_option_error(parser, option=option, msg=msg)
777778

779+
# If user doesn't wish to use pep517, we check if setuptools is installed
780+
# and raise error if it is not.
781+
if not importlib.util.find_spec("setuptools"):
782+
msg = """It is not possible to use --no-use-pep517 without setuptools
783+
installed."""
784+
raise_option_error(parser, option=option, msg=msg)
785+
778786
# Otherwise, --no-use-pep517 was passed via the command-line.
779787
parser.values.use_pep517 = False
780788

src/pip/_internal/pyproject.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.util
12
import os
23
from collections import namedtuple
34
from typing import Any, List, Optional
@@ -89,9 +90,15 @@ def load_pyproject_toml(
8990

9091
# If we haven't worked out whether to use PEP 517 yet,
9192
# and the user hasn't explicitly stated a preference,
92-
# we do so if the project has a pyproject.toml file.
93+
# we do so if the project has a pyproject.toml file
94+
# or if we cannot import setuptools.
95+
96+
# We fallback to PEP 517 when without setuptools,
97+
# so setuptools can be installed as a default build backend.
98+
# For more info see:
99+
# https://discuss.python.org/t/pip-without-setuptools-could-the-experience-be-improved/11810/9
93100
elif use_pep517 is None:
94-
use_pep517 = has_pyproject
101+
use_pep517 = has_pyproject or not importlib.util.find_spec("setuptools")
95102

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

0 commit comments

Comments
 (0)