Skip to content

Commit

Permalink
repos: ensure wheel python constraints are merged
Browse files Browse the repository at this point in the history
This change ensures that when http repositories inspect package
metadata from py2 and py3 wheels, python version requirements are
merged. Without this change, in cases where these wheels have different
python constraints, attempting to lock these packages will lead to
solver errors.
  • Loading branch information
abn authored and neersighted committed May 16, 2022
1 parent c4e1b21 commit d872f2b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/poetry/repositories/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from poetry.core.packages.dependency import Dependency
from poetry.core.packages.utils.link import Link
from poetry.core.semver.helpers import parse_constraint
from poetry.core.version.markers import parse_marker

from poetry.repositories.cached import CachedRepository
Expand Down Expand Up @@ -148,6 +149,14 @@ def _get_info_from_urls(self, urls: dict[str, list[str]]) -> PackageInfo:
info = self._get_info_from_wheel(universal_python2_wheel)

py3_info = self._get_info_from_wheel(universal_python3_wheel)

if info.requires_python or py3_info.requires_python:
info.requires_python = str(
parse_constraint(info.requires_python or "^2.7").union(
parse_constraint(py3_info.requires_python or "^3")
)
)

if py3_info.requires_dist:
if not info.requires_dist:
info.requires_dist = py3_info.requires_dist
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Links for poetry-test-py2-py3-metadata-merge</title>
</head>
<body>
<h1>Links for ipython</h1>
<a href="https://files.pythonhosted.org/packages/52/19/poetry_test_py2_py3_metadata_merge-0.1.0-py2-none-any.whl">poetry_test_py2_py3_metadata_merge-0.1.0-py2-none-any.whl</a><br/>
<a href="https://files.pythonhosted.org/packages/c7/b6/poetry_test_py2_py3_metadata_merge-0.1.0-py3-none-any.whl">poetry_test_py2_py3_metadata_merge-0.1.0-py3-none-any.whl</a><br/>
</body>
</html>
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/repositories/test_legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ def test_get_package_from_both_py2_and_py3_specific_wheels():
assert str(required[5].marker) == 'sys_platform != "win32"'


def test_get_package_from_both_py2_and_py3_specific_wheels_python_constraint():
repo = MockRepository()

package = repo.package("poetry-test-py2-py3-metadata-merge", "0.1.0")

assert package.name == "poetry-test-py2-py3-metadata-merge"
assert package.version.text == "0.1.0"
assert package.python_versions == ">=2.7,<2.8 || >=3.7,<4.0"


def test_get_package_with_dist_and_universal_py3_wheel():
repo = MockRepository()

Expand Down

0 comments on commit d872f2b

Please sign in to comment.