Skip to content

Commit 25dd005

Browse files
authored
Merge pull request #11022 from SpecLad/download-propagate-pep517
pip download: make sure that --use-pep517 is propagated to the dependencies
2 parents 4ecf68e + 28d7730 commit 25dd005

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

news/9523.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Make the ``--use-pep517`` option of the ``download`` command apply not just
2+
to the requirements specified on the command line, but to their dependencies,
3+
as well.

src/pip/_internal/commands/download.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def run(self, options: Values, args: List[str]) -> int:
122122
finder=finder,
123123
options=options,
124124
ignore_requires_python=options.ignore_requires_python,
125+
use_pep517=options.use_pep517,
125126
py_version_info=options.python_version,
126127
)
127128

tests/functional/test_download.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99

1010
from pip._internal.cli.status_codes import ERROR
1111
from tests.conftest import MockServer, ScriptFactory
12-
from tests.lib import PipTestEnvironment, TestData, create_really_basic_wheel
12+
from tests.lib import (
13+
PipTestEnvironment,
14+
TestData,
15+
create_basic_sdist_for_package,
16+
create_really_basic_wheel,
17+
)
1318
from tests.lib.server import file_response
1419

1520

@@ -1166,3 +1171,46 @@ def test_download_editable(
11661171
downloads = os.listdir(download_dir)
11671172
assert len(downloads) == 1
11681173
assert downloads[0].endswith(".zip")
1174+
1175+
1176+
def test_download_use_pep517_propagation(
1177+
script: PipTestEnvironment, tmpdir: Path, common_wheels: Path
1178+
) -> None:
1179+
"""
1180+
Check that --use-pep517 applies not just to the requirements specified
1181+
on the command line, but to their dependencies too.
1182+
"""
1183+
1184+
create_basic_sdist_for_package(script, "fake_proj", "1.0", depends=["fake_dep"])
1185+
1186+
# If --use-pep517 is in effect, then setup.py should be running in an isolated
1187+
# environment that doesn't have pip in it.
1188+
create_basic_sdist_for_package(
1189+
script,
1190+
"fake_dep",
1191+
"1.0",
1192+
setup_py_prelude=textwrap.dedent(
1193+
"""\
1194+
try:
1195+
import pip
1196+
except ImportError:
1197+
pass
1198+
else:
1199+
raise Exception(f"not running in isolation")
1200+
"""
1201+
),
1202+
)
1203+
1204+
download_dir = tmpdir / "download_dir"
1205+
script.pip(
1206+
"download",
1207+
f"--dest={download_dir}",
1208+
"--no-index",
1209+
f"--find-links={common_wheels}",
1210+
f"--find-links={script.scratch_path}",
1211+
"--use-pep517",
1212+
"fake_proj",
1213+
)
1214+
1215+
downloads = os.listdir(download_dir)
1216+
assert len(downloads) == 2

tests/lib/__init__.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,12 +1222,17 @@ def create_basic_sdist_for_package(
12221222
*,
12231223
fails_egg_info: bool = False,
12241224
fails_bdist_wheel: bool = False,
1225+
depends: Optional[List[str]] = None,
1226+
setup_py_prelude: str = "",
12251227
) -> pathlib.Path:
12261228
files = {
1227-
"setup.py": f"""\
1229+
"setup.py": textwrap.dedent(
1230+
"""\
12281231
import sys
12291232
from setuptools import find_packages, setup
12301233
1234+
{setup_py_prelude}
1235+
12311236
fails_bdist_wheel = {fails_bdist_wheel!r}
12321237
fails_egg_info = {fails_egg_info!r}
12331238
@@ -1237,19 +1242,22 @@ def create_basic_sdist_for_package(
12371242
if fails_bdist_wheel and "bdist_wheel" in sys.argv:
12381243
raise Exception("Simulated failure for building a wheel.")
12391244
1240-
setup(name={name!r}, version={version!r})
1241-
""",
1245+
setup(name={name!r}, version={version!r},
1246+
install_requires={depends!r})
1247+
"""
1248+
).format(
1249+
name=name,
1250+
version=version,
1251+
depends=depends or [],
1252+
setup_py_prelude=setup_py_prelude,
1253+
fails_bdist_wheel=fails_bdist_wheel,
1254+
fails_egg_info=fails_egg_info,
1255+
),
12421256
}
12431257

12441258
# Some useful shorthands
12451259
archive_name = f"{name}-{version}.tar.gz"
12461260

1247-
# Replace key-values with formatted values
1248-
for key, value in list(files.items()):
1249-
del files[key]
1250-
key = key.format(name=name)
1251-
files[key] = textwrap.dedent(value)
1252-
12531261
# Add new files after formatting
12541262
if extra_files:
12551263
files.update(extra_files)

0 commit comments

Comments
 (0)