diff --git a/news/11915.feature.rst b/news/11915.feature.rst new file mode 100644 index 00000000000..e2e1fd7ce8f --- /dev/null +++ b/news/11915.feature.rst @@ -0,0 +1,2 @@ +Automatically use the setuptools PEP 517 build backend when ``--config-settings`` is +used for projects without ``pyproject.toml``. diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index b622402270c..a65611c320b 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -181,6 +181,16 @@ def __init__( # but after loading this flag should be treated as read only. self.use_pep517 = use_pep517 + # If config settings are provided, enforce PEP 517. + if self.config_settings: + if self.use_pep517 is False: + logger.warning( + "--no-use-pep517 ignored for %s " + "because --config-settings are specified.", + self, + ) + self.use_pep517 = True + # This requirement needs more preparation before it can be built self.needs_more_preparation = False @@ -508,15 +518,7 @@ def load_pyproject_toml(self) -> None: ) if pyproject_toml_data is None: - if self.config_settings: - deprecated( - reason=f"Config settings are ignored for project {self}.", - replacement=( - "to use --use-pep517 or add a " - "pyproject.toml file to the project" - ), - gone_in="24.0", - ) + assert not self.config_settings self.use_pep517 = False return @@ -827,6 +829,13 @@ def install( ) if self.editable and not self.is_wheel: + if self.config_settings: + logger.warning( + "--config-settings ignored for legacy editable install of %s. " + "Consider upgrading to a version of setuptools " + "that supports PEP 660 (>= 64).", + self, + ) install_editable_legacy( global_options=global_options if global_options is not None else [], prefix=prefix, diff --git a/tests/functional/test_config_settings.py b/tests/functional/test_config_settings.py index f3975de2af5..3f88d9c3924 100644 --- a/tests/functional/test_config_settings.py +++ b/tests/functional/test_config_settings.py @@ -107,6 +107,26 @@ def make_project( return name, version, project_dir +def test_config_settings_implies_pep517( + script: PipTestEnvironment, tmp_path: Path +) -> None: + """Test that setup.py bdist_wheel is not used when config settings are.""" + pkg_path = tmp_path / "pkga" + pkg_path.mkdir() + pkg_path.joinpath("setup.py").write_text( + "from setuptools import setup; setup(name='pkga')\n" + ) + result = script.pip( + "wheel", + "--config-settings", + "FOO=Hello", + pkg_path, + cwd=tmp_path, + ) + assert "Successfully built pkga" in result.stdout + assert "Preparing metadata (pyproject.toml)" in result.stdout + + def test_backend_sees_config(script: PipTestEnvironment) -> None: name, version, project_dir = make_project(script.scratch_path) script.pip(