mirror of https://github.com/pypa/pip
Fallback to pyproject.toml-based builds if setuptools cannot be imported (#10717)
This fallback is only triggered if the project has a `setup.py` file. Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com> Co-authored-by: Pradyun Gedam <pradyunsg@gmail.com>
This commit is contained in:
parent
5570b4218f
commit
452d7da880
|
@ -0,0 +1 @@
|
|||
Fallback to pyproject.toml-based builds if ``setup.py`` is present in a project, but ``setuptools`` cannot be imported.
|
|
@ -10,6 +10,7 @@ pass on state. To be consistent, all options will follow this design.
|
|||
# The following comment should be removed at some point in the future.
|
||||
# mypy: strict-optional=False
|
||||
|
||||
import importlib.util
|
||||
import logging
|
||||
import os
|
||||
import textwrap
|
||||
|
@ -770,6 +771,12 @@ def _handle_no_use_pep517(
|
|||
"""
|
||||
raise_option_error(parser, option=option, msg=msg)
|
||||
|
||||
# If user doesn't wish to use pep517, we check if setuptools is installed
|
||||
# and raise error if it is not.
|
||||
if not importlib.util.find_spec("setuptools"):
|
||||
msg = "It is not possible to use --no-use-pep517 without setuptools installed."
|
||||
raise_option_error(parser, option=option, msg=msg)
|
||||
|
||||
# Otherwise, --no-use-pep517 was passed via the command-line.
|
||||
parser.values.use_pep517 = False
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import importlib.util
|
||||
import os
|
||||
from collections import namedtuple
|
||||
from typing import Any, List, Optional
|
||||
|
@ -89,9 +90,15 @@ def load_pyproject_toml(
|
|||
|
||||
# If we haven't worked out whether to use PEP 517 yet,
|
||||
# and the user hasn't explicitly stated a preference,
|
||||
# we do so if the project has a pyproject.toml file.
|
||||
# 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,
|
||||
# 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
|
||||
elif use_pep517 is None:
|
||||
use_pep517 = has_pyproject
|
||||
use_pep517 = has_pyproject or not importlib.util.find_spec("setuptools")
|
||||
|
||||
# At this point, we know whether we're going to use PEP 517.
|
||||
assert use_pep517 is not None
|
||||
|
|
Loading…
Reference in New Issue