Skip to content

Commit

Permalink
tolerate a non-existent extra (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored Sep 3, 2022
1 parent cef21cb commit a1f4ebc
Show file tree
Hide file tree
Showing 2 changed files with 57 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 @@ -160,7 +160,7 @@ def walk_dependencies(

for require in locked_package.requires:
if require.is_optional() and not any(
require in locked_package.extras[feature]
require in locked_package.extras.get(feature, ())
for feature in locked_package.features
):
continue
Expand Down
56 changes: 56 additions & 0 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2398,3 +2398,59 @@ def test_exporter_respects_package_sources(tmp_dir: str, poetry: Poetry) -> None
"""

assert io.fetch_output() == expected


def test_exporter_tolerates_non_existent_extra(tmp_dir: str, poetry: Poetry) -> None:
# foo actually has a 'bar' extra, but pyproject.toml mistakenly references a 'baz'
# extra.
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
"package": [
{
"name": "foo",
"version": "1.2.3",
"category": "main",
"optional": False,
"python-versions": "*",
"dependencies": {
"bar": {
"version": ">=0.1.0",
"optional": True,
"markers": "extra == 'bar'",
}
},
"extras": {"bar": ["bar (>=0.1.0)"]},
},
{
"name": "bar",
"version": "4.5.6",
"category": "main",
"optional": False,
"python-versions": "*",
},
],
"metadata": {
"python-versions": "*",
"content-hash": "123456789",
"hashes": {"foo": [], "bar": []},
},
}
)
root = poetry.package.with_dependency_groups([], only=True)
root.add_dependency(
Factory.create_dependency(
name="foo", constraint={"version": "^1.2", "extras": ["baz"]}
)
)
poetry._package = root

exporter = Exporter(poetry)
exporter.export("requirements.txt", Path(tmp_dir), "requirements.txt")

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

expected = f"""\
foo[baz]==1.2.3 ; {MARKER_PY27} or {MARKER_PY36}
"""
assert content == expected

0 comments on commit a1f4ebc

Please # to comment.