Skip to content

Commit 7fb607b

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

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/pip/_internal/cli/cmdoptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import textwrap
1515
import warnings
16+
import importlib.util
1617
from functools import partial
1718
from optparse import SUPPRESS_HELP, Option, OptionGroup, OptionParser, Values
1819
from textwrap import dedent
@@ -774,6 +775,13 @@ def _handle_no_use_pep517(
774775
"""
775776
raise_option_error(parser, option=option, msg=msg)
776777

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

src/pip/_internal/pyproject.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import importlib.util
23
from collections import namedtuple
34
from typing import Any, List, Optional
45

@@ -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)