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

strip extras properly from marker during dependency walk #209

Merged
merged 1 commit into from
Jun 4, 2023
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
2 changes: 1 addition & 1 deletion src/poetry_plugin_export/walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def walk_dependencies(
):
continue

base_marker = require.marker.intersect(requirement.marker.without_extras())
base_marker = require.marker.intersect(requirement.marker).without_extras()

if not base_marker.is_empty():
# So as to give ourselves enough flexibility in choosing a solution,
Expand Down
76 changes: 76 additions & 0 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2720,3 +2720,79 @@ def test_exporter_exports_extra_index_url_and_trusted_host(
foo==1.2.3 ; {MARKER_PY}
"""
assert content == expected


def test_exporter_not_confused_by_extras_in_sub_dependencies(
tmp_path: Path, poetry: Poetry
) -> None:
# Testcase derived from
# https://github.com/python-poetry/poetry-plugin-export/issues/208
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
"package": [
{
"name": "typer",
"python-versions": ">=3.6",
"version": "0.9.0",
"optional": False,
"files": [],
"dependencies": {
"click": ">=7.1.1,<9.0.0",
"colorama": {
"version": ">=0.4.3,<0.5.0",
"optional": True,
"markers": 'extra == "all"',
},
},
"extras": {"all": ["colorama (>=0.4.3,<0.5.0)"]},
},
{
"name": "click",
"python-versions": ">=3.7",
"version": "8.1.3",
"optional": False,
"files": [],
"dependencies": {
"colorama": {
"version": "*",
"markers": 'platform_system == "Windows"',
}
},
},
{
"name": "colorama",
"python-versions": ">=3.7",
"version": "0.4.6",
"optional": False,
"files": [],
},
],
"metadata": {
"lock-version": "2.0",
"python-versions": "^3.11",
"content-hash": (
"832b13a88e5020c27cbcd95faa577bf0dbf054a65c023b45dc9442b640d414e6"
),
},
}
)
root = poetry.package.with_dependency_groups([], only=True)
root.python_versions = "^3.11"
root.add_dependency(
Factory.create_dependency(
name="typer",
constraint={"version": "^0.9.0", "extras": ["all"]},
)
)
poetry._package = root

io = BufferedIO()
exporter = Exporter(poetry, NullIO())
exporter.export("requirements.txt", tmp_path, io)

expected = """\
click==8.1.3 ; python_version >= "3.11" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.11" and python_version < "4.0"
typer[all]==0.9.0 ; python_version >= "3.11" and python_version < "4.0"
"""
assert io.fetch_output() == expected