Skip to content

Commit

Permalink
Merge pull request #11917 from sbidoul/config-settings-implies-pep517…
Browse files Browse the repository at this point in the history
…-sbi

Let --config-settings imply PEP 517
  • Loading branch information
sbidoul authored Jan 30, 2024
2 parents 89950c5 + cfab072 commit cfe5f9a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
2 changes: 2 additions & 0 deletions news/11915.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Automatically use the setuptools PEP 517 build backend when ``--config-settings`` is
used for projects without ``pyproject.toml``.
27 changes: 18 additions & 9 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/test_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cfe5f9a

Please sign in to comment.