Commit 3bc1c5ae by Sébastien Eustace

Fix package resolution for legacy repositories

- Fix non-sha256 hashes retrieval
- Fix resolution of packages with Python 3 only wheel
parent a879e8ac
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
### Fixed ### Fixed
- Fixed an `AttributeError` in the editable builder. - Fixed an `AttributeError` in the editable builder.
- Fixed resolution of packages with only Python 3 wheels and sdist when resolving for legacy repositories.
- Fixed non-sha256 hashes retrieval for legacy repositories.
## [0.12.14] - 2019-04-26 ## [0.12.14] - 2019-04-26
......
...@@ -115,7 +115,11 @@ class PipInstaller(BaseInstaller): ...@@ -115,7 +115,11 @@ class PipInstaller(BaseInstaller):
if formatted and not package.source_type: if formatted and not package.source_type:
req = "{}=={}".format(package.name, package.version) req = "{}=={}".format(package.name, package.version)
for h in package.hashes: for h in package.hashes:
req += " --hash sha256:{}".format(h) hash_type = "sha256"
if ":" in h:
hash_type, h = h.split(":")
req += " --hash {}:{}".format(hash_type, h)
req += "\n" req += "\n"
......
...@@ -336,6 +336,7 @@ class LegacyRepository(PyPiRepository): ...@@ -336,6 +336,7 @@ class LegacyRepository(PyPiRepository):
"requires_dist": [], "requires_dist": [],
"requires_python": None, "requires_python": None,
"digests": [], "digests": [],
"_cache_version": str(self.CACHE_VERSION),
} }
links = list(page.links_for_version(Version.parse(version))) links = list(page.links_for_version(Version.parse(version)))
...@@ -358,6 +359,8 @@ class LegacyRepository(PyPiRepository): ...@@ -358,6 +359,8 @@ class LegacyRepository(PyPiRepository):
hash = link.hash hash = link.hash
if link.hash_name == "sha256": if link.hash_name == "sha256":
hashes.append(hash) hashes.append(hash)
else:
hashes.append(link.hash_name + ":" + hash)
data["digests"] = hashes data["digests"] = hashes
......
...@@ -420,6 +420,13 @@ class PyPiRepository(Repository): ...@@ -420,6 +420,13 @@ class PyPiRepository(Repository):
if info: if info:
return info return info
# Prefer non platform specific wheels
if universal_python3_wheel:
return self._get_info_from_wheel(universal_python3_wheel)
if universal_python2_wheel:
return self._get_info_from_wheel(universal_python2_wheel)
if platform_specific_wheels and "sdist" not in urls: if platform_specific_wheels and "sdist" not in urls:
# Pick the first wheel available and hope for the best # Pick the first wheel available and hope for the best
return self._get_info_from_wheel(platform_specific_wheels[0]) return self._get_info_from_wheel(platform_specific_wheels[0])
......
from poetry.installation.pip_installer import PipInstaller
from poetry.io import NullIO
from poetry.packages.package import Package
from poetry.utils.env import NullEnv
def test_requirement():
installer = PipInstaller(NullEnv(), NullIO())
package = Package("ipython", "7.5.0")
package.hashes = [
"md5:dbdc53e3918f28fa335a173432402a00",
"e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26",
]
result = installer.requirement(package, formatted=True)
expected = (
"ipython==7.5.0 "
"--hash md5:dbdc53e3918f28fa335a173432402a00 "
"--hash sha256:e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26"
"\n"
)
assert expected == result
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
<a href="https://files.pythonhosted.org/packages/52/19/aadde98d6bde1667d0bf431fb2d22451f880aaa373e0a241c7e7cb5815a0/ipython-5.7.0-py2-none-any.whl#sha256=707d1bbfc81e41e39ead1012af931bec6f80357b87e520af352e539cf5961dc0">ipython-5.7.0-py2-none-any.whl</a><br/> <a href="https://files.pythonhosted.org/packages/52/19/aadde98d6bde1667d0bf431fb2d22451f880aaa373e0a241c7e7cb5815a0/ipython-5.7.0-py2-none-any.whl#sha256=707d1bbfc81e41e39ead1012af931bec6f80357b87e520af352e539cf5961dc0">ipython-5.7.0-py2-none-any.whl</a><br/>
<a href="https://files.pythonhosted.org/packages/c7/b6/03e0b5b0972e6161d16c4cec8d41a20372bd0634f8cb4cc0c984b8a91db6/ipython-5.7.0-py3-none-any.whl#sha256=fc0464e68f9c65cd8c453474b4175432cc29ecb6c83775baedf6dbfcee9275ab">ipython-5.7.0-py3-none-any.whl</a><br/> <a href="https://files.pythonhosted.org/packages/c7/b6/03e0b5b0972e6161d16c4cec8d41a20372bd0634f8cb4cc0c984b8a91db6/ipython-5.7.0-py3-none-any.whl#sha256=fc0464e68f9c65cd8c453474b4175432cc29ecb6c83775baedf6dbfcee9275ab">ipython-5.7.0-py3-none-any.whl</a><br/>
<a href="https://files.pythonhosted.org/packages/3c/fd/559fead731a29eaa55cc235c8029807b2520976a937c30e9ee603f3bb566/ipython-5.7.0.tar.gz#sha256=8db43a7fb7619037c98626613ff08d03dda9d5d12c84814a4504c78c0da8323c">ipython-5.7.0.tar.gz</a><br/> <a href="https://files.pythonhosted.org/packages/3c/fd/559fead731a29eaa55cc235c8029807b2520976a937c30e9ee603f3bb566/ipython-5.7.0.tar.gz#sha256=8db43a7fb7619037c98626613ff08d03dda9d5d12c84814a4504c78c0da8323c">ipython-5.7.0.tar.gz</a><br/>
<a href="https://files.pythonhosted.org/packages/a9/2e/41dce4ed129057e05a555a7f9629aa2d5f81fdcd4d16568bc24b75a1d2c9/ipython-7.5.0-py3-none-any.whl#md5=dbdc53e3918f28fa335a173432402a00" data-requires-python="&gt;=3.5">ipython-7.5.0-py3-none-any.whl</a><br/>
<a href="https://files.pythonhosted.org/packages/75/74/9b0ef91c8e356c907bb12297000951acb804583b54eeaddc342c5bad4d96/ipython-7.5.0.tar.gz#sha256=e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26" data-requires-python="&gt;=3.5">ipython-7.5.0.tar.gz</a><br/>
</body> </body>
</html> </html>
<!--SERIAL 4837213--> <!--SERIAL 4837213-->
...@@ -205,3 +205,43 @@ def test_get_package_from_both_py2_and_py3_specific_wheels(): ...@@ -205,3 +205,43 @@ def test_get_package_from_both_py2_and_py3_specific_wheels():
package.requires[4].marker package.requires[4].marker
) )
assert 'sys_platform != "win32"' == str(package.requires[5].marker) assert 'sys_platform != "win32"' == str(package.requires[5].marker)
def test_get_package_with_dist_and_universal_py3_wheel():
repo = MockRepository()
package = repo.package("ipython", "7.5.0")
assert "ipython" == package.name
assert "7.5.0" == package.version.text
assert ">=3.5" == package.python_versions
expected = [
Dependency("appnope", "*"),
Dependency("backcall", "*"),
Dependency("colorama", "*"),
Dependency("decorator", "*"),
Dependency("jedi", ">=0.10"),
Dependency("pexpect", "*"),
Dependency("pickleshare", "*"),
Dependency("prompt-toolkit", ">=2.0.0,<2.1.0"),
Dependency("pygments", "*"),
Dependency("setuptools", ">=18.5"),
Dependency("traitlets", ">=4.2"),
Dependency("typing", "*"),
Dependency("win-unicode-console", ">=0.5"),
]
assert expected == sorted(package.requires, key=lambda dep: dep.name)
def test_get_package_retrieves_non_sha256_hashes():
repo = MockRepository()
package = repo.package("ipython", "7.5.0")
expected = [
"md5:dbdc53e3918f28fa335a173432402a00",
"e840810029224b56cd0d9e7719dc3b39cf84d577f8ac686547c8ba7a06eeab26",
]
assert expected == package.hashes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment