diff --git a/news/9523.bugfix.rst b/news/9523.bugfix.rst new file mode 100644 index 00000000000..de5e757fa9e --- /dev/null +++ b/news/9523.bugfix.rst @@ -0,0 +1,3 @@ +Make the ``--use-pep517`` option of the ``download`` command apply not just +to the requirements specified on the command line, but to their dependencies, +as well. diff --git a/src/pip/_internal/commands/download.py b/src/pip/_internal/commands/download.py index a6d7e628f2b..c0af570aa5b 100644 --- a/src/pip/_internal/commands/download.py +++ b/src/pip/_internal/commands/download.py @@ -121,6 +121,7 @@ def run(self, options: Values, args: List[str]) -> int: finder=finder, options=options, ignore_requires_python=options.ignore_requires_python, + use_pep517=options.use_pep517, py_version_info=options.python_version, ) diff --git a/tests/functional/test_download.py b/tests/functional/test_download.py index ace2ff74c5b..14a903bb6fc 100644 --- a/tests/functional/test_download.py +++ b/tests/functional/test_download.py @@ -9,7 +9,12 @@ from pip._internal.cli.status_codes import ERROR from pip._internal.utils.urls import path_to_url from tests.conftest import MockServer, ScriptFactory -from tests.lib import PipTestEnvironment, TestData, create_really_basic_wheel +from tests.lib import ( + PipTestEnvironment, + TestData, + create_basic_sdist_for_package, + create_really_basic_wheel, +) from tests.lib.path import Path from tests.lib.server import file_response @@ -1163,3 +1168,33 @@ def test_download_editable( downloads = os.listdir(download_dir) assert len(downloads) == 1 assert downloads[0].endswith(".zip") + + +def test_download_use_pep517_propagation( + script: PipTestEnvironment, tmpdir: Path, common_wheels: Path +) -> None: + """ + Check that --use-pep517 applies not just to the requirements specified + on the command line, but to their dependencies too. + """ + + # Remove setuptools to ensure that metadata retrieval fails unless PEP 517 + # is used. + script.pip("uninstall", "-y", "setuptools") + + create_basic_sdist_for_package(script, "fake_proj", "1.0", depends=["fake_dep"]) + create_basic_sdist_for_package(script, "fake_dep", "1.0") + + download_dir = tmpdir / "download_dir" + script.pip( + "download", + f"--dest={download_dir}", + "--no-index", + f"--find-links={common_wheels}", + f"--find-links={script.scratch_path}", + "--use-pep517", + "fake_proj", + ) + + downloads = os.listdir(download_dir) + assert len(downloads) == 2 diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index c8d68fea9b0..7f4a56d3e78 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -1188,6 +1188,7 @@ def create_basic_sdist_for_package( *, fails_egg_info: bool = False, fails_bdist_wheel: bool = False, + depends: Optional[List[str]] = None, ) -> Path: files = { "setup.py": f"""\ @@ -1203,7 +1204,8 @@ def create_basic_sdist_for_package( if fails_bdist_wheel and "bdist_wheel" in sys.argv: raise Exception("Simulated failure for building a wheel.") - setup(name={name!r}, version={version!r}) + setup(name={name!r}, version={version!r}, + install_requires={depends or []!r}) """, }