Skip to content

pip download: make sure that --use-pep517 is propagated to the dependencies #11022

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 2 commits into from
Jun 24, 2022
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
3 changes: 3 additions & 0 deletions news/9523.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions src/pip/_internal/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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,
)

Expand Down
50 changes: 49 additions & 1 deletion tests/functional/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

from pip._internal.cli.status_codes import ERROR
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.server import file_response


Expand Down Expand Up @@ -1166,3 +1171,46 @@ 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.
"""

create_basic_sdist_for_package(script, "fake_proj", "1.0", depends=["fake_dep"])

# If --use-pep517 is in effect, then setup.py should be running in an isolated
# environment that doesn't have pip in it.
create_basic_sdist_for_package(
script,
"fake_dep",
"1.0",
setup_py_prelude=textwrap.dedent(
"""\
try:
import pip
except ImportError:
pass
else:
raise Exception(f"not running in isolation")
"""
),
)

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
26 changes: 17 additions & 9 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,17 @@ def create_basic_sdist_for_package(
*,
fails_egg_info: bool = False,
fails_bdist_wheel: bool = False,
depends: Optional[List[str]] = None,
setup_py_prelude: str = "",
) -> pathlib.Path:
files = {
"setup.py": f"""\
"setup.py": textwrap.dedent(
"""\
import sys
from setuptools import find_packages, setup

{setup_py_prelude}

fails_bdist_wheel = {fails_bdist_wheel!r}
fails_egg_info = {fails_egg_info!r}

Expand All @@ -1226,19 +1231,22 @@ 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!r})
"""
).format(
name=name,
version=version,
depends=depends or [],
setup_py_prelude=setup_py_prelude,
fails_bdist_wheel=fails_bdist_wheel,
fails_egg_info=fails_egg_info,
),
}

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

# Replace key-values with formatted values
for key, value in list(files.items()):
del files[key]
key = key.format(name=name)
files[key] = textwrap.dedent(value)

# Add new files after formatting
if extra_files:
files.update(extra_files)
Expand Down