Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tolerate a non-existent extra #109

Merged
merged 1 commit into from
Sep 3, 2022
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 @@ -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