Skip to content

Commit

Permalink
Fix download --constraint for legacy-resolver. (pypa#8)
Browse files Browse the repository at this point in the history
Download was not filtering out constraint-only requirements prior to
attempting to save them. Add a failing test under `--resolver=legacy`
and fix by adding in the filtering.

See: pypa@b28e2c4#r45135982

Fixes pypa#9283
  • Loading branch information
jsirois authored and cosmicexplorer committed Aug 5, 2023
1 parent 3c0147a commit a3d7f40
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/9283.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the download command when using --constraint with the legacy-resolver.
2 changes: 1 addition & 1 deletion src/pip/_internal/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def run(self, options: Values, args: List[str]) -> int:

downloaded: List[str] = []
for req in requirement_set.requirements.values():
if req.satisfied_by is None:
if req.link and req.satisfied_by is None:
assert req.name is not None
preparer.save_linked_requirement(req)
downloaded.append(req.name)
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ def test_download_wheel(script: PipTestEnvironment, data: TestData) -> None:
result.did_not_create(script.site_packages / "piptestpackage")


def test_download_wheel_constraints(script, data):
"""
Test using "pip download" to download a *.whl with constraints.
"""
script.scratch_path.joinpath("constraints.txt").write_text(textwrap.dedent("""
meta==1.0
parent==0.1
"""))
result = script.pip(
'download',
'--no-index',
'-f', data.packages,
'-d', '.', 'meta',
'--constraint', script.scratch_path / 'constraints.txt',
)
result.did_create(Path('scratch') / 'meta-1.0-py2.py3-none-any.whl')
result.did_not_create(script.site_packages / 'piptestpackage')


@pytest.mark.network
def test_single_download_from_requirements_file(script: PipTestEnvironment) -> None:
"""
Expand Down

0 comments on commit a3d7f40

Please sign in to comment.