Skip to content
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
21 changes: 6 additions & 15 deletions src/poetry_plugin_export/exporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import contextlib
import itertools
import urllib.parse

from datetime import datetime
Expand Down Expand Up @@ -395,24 +394,16 @@ def add_file_info(
package.source_reference or "PyPI",
).files
}
artifacts = {
k: list(v)
for k, v in itertools.groupby(
package.files,
key=(
lambda x: (
"wheel" if x["file"].endswith(".whl") else "sdist"
)
),
)
}

sdist_files = list(artifacts.get("sdist", []))
sdist_files = [
f for f in package.files if not f["file"].endswith(".whl")
]
for sdist in sdist_files:
sdist_table = inline_table()
data["sdist"] = sdist_table
add_file_info(sdist_table, sdist, pool_info[sdist["file"]])
if wheels := list(artifacts.get("wheel", [])):
if wheels := [
f for f in package.files if f["file"].endswith(".whl")
]:
wheel_array = array()
data["wheels"] = wheel_array
wheel_array.multiline(True)
Expand Down
82 changes: 82 additions & 0 deletions tests/test_exporter_pylock_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,88 @@ def test_export_pypi_dependencies_multiple_wheels(
assert content == expected


def test_export_pypi_dependencies_sdist_sorted_between_wheels(
tmp_path: Path, poetry: Poetry
) -> None:
# The lock file sorts files by name, so the sdist can end up between wheels,
# e.g. if the distribution name of some wheels is normalized differently.
lock_data = {
"package": [
{
"name": "foo.bar",
"version": "1.0",
"optional": False,
"python-versions": "*",
"groups": [MAIN_GROUP],
"files": [
{
"file": "foo.bar-1.0-py2-none-any.whl",
"hash": "sha256:abcdef1234567891",
},
{
"file": "foo.bar-1.0.tar.gz",
"hash": "sha256:0123456789abcdef",
},
{
"file": "foo_bar-1.0-py3-none-any.whl",
"hash": "sha256:abcdef1234567890",
},
],
},
],
"metadata": {"lock-version": "2.1"},
}
poetry.locker.mock_lock_data(lock_data) # type: ignore[attr-defined]

foo_bar = Package("foo.bar", "1.0")
foo_bar.files = [
{
"file": "foo.bar-1.0-py2-none-any.whl",
"hash": "sha256:abcdef1234567891",
"url": "https://example.org/foo.bar-1.0-py2-none-any.whl",
},
{
"file": "foo.bar-1.0.tar.gz",
"hash": "sha256:0123456789abcdef",
"url": "https://example.org/foo.bar-1.0.tar.gz",
},
{
"file": "foo_bar-1.0-py3-none-any.whl",
"hash": "sha256:abcdef1234567890",
"url": "https://example.org/foo_bar-1.0-py3-none-any.whl",
},
]
poetry.pool.repository("PyPI").add_package(foo_bar)

exporter = Exporter(poetry, NullIO())

exporter.export("pylock.toml", tmp_path, "pylock.toml")

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

expected = """\
lock-version = "1.0"
created-by = "poetry-plugin-export"

[[packages]]
name = "foo-bar"
version = "1.0"
index = "https://pypi.org/simple"
sdist = {name = "foo.bar-1.0.tar.gz", url = "https://example.org/foo.bar-1.0.tar.gz", hashes = {sha256 = "0123456789abcdef"}}
wheels = [
{name = "foo.bar-1.0-py2-none-any.whl", url = "https://example.org/foo.bar-1.0-py2-none-any.whl", hashes = {sha256 = "abcdef1234567891"}},
{name = "foo_bar-1.0-py3-none-any.whl", url = "https://example.org/foo_bar-1.0-py3-none-any.whl", hashes = {sha256 = "abcdef1234567890"}},
]

[tool.poetry-plugin-export]
groups = ["main"]
extras = []
"""

assert content == expected


def test_export_legacy_repo_dependencies(tmp_path: Path, poetry: Poetry) -> None:
lock_data = {
"package": [
Expand Down
Loading