Skip to content
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

Fix dropped markers in dependency walk #4686

Merged
merged 1 commit into from
Nov 14, 2021
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
17 changes: 8 additions & 9 deletions poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,15 @@ def __walk_dependency_level(
locked_package.to_dependency().constraint
)

if key not in nested_dependencies:
for require in locked_package.requires:
if require.marker.is_empty():
require.marker = requirement.marker
else:
require.marker = require.marker.intersect(
requirement.marker
)
for require in locked_package.requires:
if require.marker.is_empty():
require.marker = requirement.marker
else:
require.marker = require.marker.intersect(requirement.marker)

require.marker = require.marker.intersect(locked_package.marker)

require.marker = require.marker.intersect(locked_package.marker)
if key not in nested_dependencies:
next_level_dependencies.append(require)

if requirement.name in project_level_dependencies and level == 0:
Expand Down
73 changes: 73 additions & 0 deletions tests/utils/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,79 @@ def test_exporter_can_export_requirements_txt_with_nested_packages_cyclic(
assert expected == content


def test_exporter_can_export_requirements_txt_with_nested_packages_and_multiple_markers(
tmp_dir, poetry
):
poetry.locker.mock_lock_data(
{
"package": [
{
"name": "foo",
"version": "1.2.3",
"category": "main",
"optional": False,
"python-versions": "*",
"dependencies": {
"bar": [
{
"version": ">=1.2.3,<7.8.10",
"markers": 'platform_system != "Windows"',
},
{
"version": ">=4.5.6,<7.8.10",
"markers": 'platform_system == "Windows"',
},
]
},
},
{
"name": "bar",
"version": "7.8.9",
"category": "main",
"optional": True,
"python-versions": "*",
"dependencies": {
"baz": {
"version": "!=10.11.12",
"markers": 'platform_system == "Windows"',
}
},
},
{
"name": "baz",
"version": "10.11.13",
"category": "main",
"optional": True,
"python-versions": "*",
},
],
"metadata": {
"python-versions": "*",
"content-hash": "123456789",
"hashes": {"foo": [], "bar": [], "baz": []},
},
}
)
set_package_requires(poetry)

exporter = Exporter(poetry)

exporter.export(
"requirements.txt", Path(tmp_dir), "requirements.txt", with_hashes=False
)

with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
content = f.read()

expected = """\
bar==7.8.9; platform_system != "Windows" or platform_system == "Windows"
baz==10.11.13; platform_system == "Windows"
foo==1.2.3
"""

assert expected == content


def test_exporter_can_export_requirements_txt_with_git_packages_and_markers(
tmp_dir, poetry
):
Expand Down