Skip to content

Let --config-settings imply PEP 517 #11917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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