Skip to content

Commit

Permalink
strip extras properly from marker during dependency walk (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored Jun 4, 2023
1 parent f5c1170 commit e142699
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
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

0 comments on commit e142699

Please sign in to comment.