From e7a790a2e75cfaf92896e7c301c9f89aade303c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hrn=C4=8Diar?= Date: Wed, 8 Dec 2021 15:36:30 +0100 Subject: [PATCH 1/4] Fallback to pep517 if setup.py is present and setuptools cannot be imported --- news/10717.bugfix.rst | 1 + src/pip/_internal/cli/cmdoptions.py | 8 ++++++++ src/pip/_internal/pyproject.py | 11 +++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 news/10717.bugfix.rst diff --git a/news/10717.bugfix.rst b/news/10717.bugfix.rst new file mode 100644 index 00000000000..e2877d51b1c --- /dev/null +++ b/news/10717.bugfix.rst @@ -0,0 +1 @@ +Fallback to pep517 if setup.py is present and setuptools cannot be imported diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 71b1d190691..19bb4017870 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -10,6 +10,7 @@ # 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 @@ -775,6 +776,13 @@ 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 diff --git a/src/pip/_internal/pyproject.py b/src/pip/_internal/pyproject.py index e183eaf8658..1e9119f3e5c 100644 --- a/src/pip/_internal/pyproject.py +++ b/src/pip/_internal/pyproject.py @@ -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 From 7776a6df787f5efaf8cfdc087d41e34c66852282 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 30 Mar 2022 20:46:16 +0800 Subject: [PATCH 2/4] Avoid unnecessary linebreak in long message --- src/pip/_internal/cli/cmdoptions.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 19bb4017870..3c723853143 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -779,8 +779,7 @@ def _handle_no_use_pep517( # 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.""" + 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. From 12404db9b353cc0b8aefc1b2e7c73c4e7f746503 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 13 Apr 2022 06:40:29 +0800 Subject: [PATCH 3/4] News fragment format --- news/10717.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/10717.bugfix.rst b/news/10717.bugfix.rst index e2877d51b1c..099b2e9961f 100644 --- a/news/10717.bugfix.rst +++ b/news/10717.bugfix.rst @@ -1 +1 @@ -Fallback to pep517 if setup.py is present and setuptools cannot be imported +Fallback to PEP 517 if ``setup.py`` is present in a project, but ``setuptools`` cannot be imported From f4b1a238f5919a8bd1ac28c4e812e76cbd928d1b Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Sat, 23 Apr 2022 15:56:27 +0100 Subject: [PATCH 4/4] Update news/10717.bugfix.rst --- news/10717.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/10717.bugfix.rst b/news/10717.bugfix.rst index 099b2e9961f..950a4521763 100644 --- a/news/10717.bugfix.rst +++ b/news/10717.bugfix.rst @@ -1 +1 @@ -Fallback to PEP 517 if ``setup.py`` is present in a project, but ``setuptools`` cannot be imported +Fallback to pyproject.toml-based builds if ``setup.py`` is present in a project, but ``setuptools`` cannot be imported.