Skip to content

Commit c8f34dd

Browse files
authored
Merge pull request #4908 from jfly/issue-4885-custom-indices-lacking-hashes
Use a PackageFinder with `ignore_compatibility` when collecting hashes
2 parents b0ebaf0 + 34652df commit c8f34dd

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

news/4885.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regression where lockfiles would only include the hashes for releases for the platform generating the lockfile

pipenv/utils.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ def __init__(
428428
self._parsed_constraints = None
429429
self._resolver = None
430430
self._finder = None
431+
self._ignore_compatibility_finder = None
431432
self._session = None
432433
self._constraint_file = None
433434
self._pip_options = None
@@ -798,6 +799,22 @@ def finder(self):
798799
)
799800
return self._finder
800801

802+
@property
803+
def ignore_compatibility_finder(self):
804+
from pipenv.vendor.pip_shims import shims
805+
if self._ignore_compatibility_finder is None:
806+
ignore_compatibility_finder = shims.get_package_finder(
807+
install_cmd=self.pip_command,
808+
options=self.pip_options,
809+
session=self.session,
810+
)
811+
# It would be nice if `shims.get_package_finder` took an
812+
# `ignore_compatibility` parameter, but that's some vendorered code
813+
# we'd rather avoid touching.
814+
ignore_compatibility_finder._ignore_compatibility = True
815+
self._ignore_compatibility_finder = ignore_compatibility_finder
816+
return self._ignore_compatibility_finder
817+
801818
@property
802819
def parsed_constraints(self):
803820
from pipenv.vendor.pip_shims import shims
@@ -950,7 +967,7 @@ def collect_hashes(self, ireq):
950967
if hashes:
951968
return hashes
952969

953-
applicable_candidates = self.finder.find_best_candidate(
970+
applicable_candidates = self.ignore_compatibility_finder.find_best_candidate(
954971
ireq.name, ireq.specifier
955972
).iter_applicable()
956973
return {

pipenv/vendor/pip_shims/compat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ def get_package_finder(
693693
and "ignore_requires_python" in builder_args.args
694694
):
695695
build_kwargs["ignore_requires_python"] = ignore_requires_python
696+
696697
return install_cmd._build_package_finder(**build_kwargs) # type: ignore
697698

698699

tests/integration/test_lock.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77

8+
import pytest_pypi.app
89
from flaky import flaky
910
from vistir.misc import to_text
1011
from pipenv.utils import temp_environ
@@ -57,6 +58,41 @@ def test_lock_requirements_file(PipenvInstance):
5758
assert req in d.stdout
5859

5960

61+
@pytest.mark.lock
62+
def test_lock_includes_hashes_for_all_platforms(PipenvInstance):
63+
""" Locking should include hashes for *all* platforms, not just the
64+
platform we're running lock on. """
65+
66+
releases = pytest_pypi.app.packages['yarl'].releases
67+
def get_hash(release_name):
68+
# Convert a specific filename to a hash like what would show up in a Pipfile.lock.
69+
# For example:
70+
# 'yarl-1.3.0-cp35-cp35m-manylinux1_x86_64.whl' -> 'sha256:3890ab952d508523ef4881457c4099056546593fa05e93da84c7250516e632eb'
71+
return f"sha256:{releases[release_name].hash}"
72+
73+
with PipenvInstance() as p:
74+
with open(p.pipfile_path, 'w') as f:
75+
contents = """
76+
[packages]
77+
yarl = "==1.3.0"
78+
""".strip()
79+
f.write(contents)
80+
81+
c = p.pipenv('lock')
82+
assert c.returncode == 0
83+
84+
lock = p.lockfile
85+
assert 'yarl' in lock['default']
86+
assert set(lock['default']['yarl']['hashes']) == {
87+
get_hash('yarl-1.3.0-cp35-cp35m-manylinux1_x86_64.whl'),
88+
get_hash('yarl-1.3.0-cp35-cp35m-win_amd64.whl'),
89+
get_hash('yarl-1.3.0-cp36-cp36m-manylinux1_x86_64.whl'),
90+
get_hash('yarl-1.3.0-cp36-cp36m-win_amd64.whl'),
91+
get_hash('yarl-1.3.0-cp37-cp37m-win_amd64.whl'),
92+
get_hash('yarl-1.3.0.tar.gz'),
93+
}
94+
95+
6096
@pytest.mark.lock
6197
@pytest.mark.keep_outdated
6298
def test_lock_keep_outdated(PipenvInstance):

0 commit comments

Comments
 (0)