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: Include explicit sources in export command #205

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/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _export_generic_txt(
for index in sorted(indexes):
repositories = [
r
for r in self._poetry.pool.repositories
for r in self._poetry.pool.all_repositories
if isinstance(r, HTTPRepository) and r.url == index.rstrip("/")
]
if not repositories:
Expand Down
57 changes: 57 additions & 0 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2663,3 +2663,60 @@ def test_exporter_tolerates_non_existent_extra(tmp_path: Path, poetry: Poetry) -
foo[baz]==1.2.3 ; {MARKER_PY27} or {MARKER_PY36}
"""
assert content == expected


def test_exporter_exports_extra_index_url_and_trusted_host(
tmp_path: Path, poetry: Poetry
) -> None:
poetry.pool.add_repository(
LegacyRepository(
"custom",
"http://example.com/simple",
),
priority=Priority.EXPLICIT,
)
poetry.locker.mock_lock_data( # type: ignore[attr-defined]
{
"package": [
{
"name": "foo",
"version": "1.2.3",
"optional": False,
"python-versions": "*",
"dependencies": {"bar": "*"},
},
{
"name": "bar",
"version": "4.5.6",
"optional": False,
"python-versions": "*",
"source": {
"type": "legacy",
"url": "http://example.com/simple",
"reference": "",
},
},
],
"metadata": {
"python-versions": "*",
"content-hash": "123456789",
"files": {"foo": [], "bar": []},
},
}
)
set_package_requires(poetry)

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

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

expected = f"""\
--trusted-host example.com
--extra-index-url http://example.com/simple

bar==4.5.6 ; {MARKER_PY}
foo==1.2.3 ; {MARKER_PY}
"""
assert content == expected