Skip to content

Commit

Permalink
Fix: Include explicit sources in export command (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiumachi authored May 26, 2023
1 parent 208a5e3 commit 06c42b2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
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

0 comments on commit 06c42b2

Please sign in to comment.