Skip to content

Commit d158c7b

Browse files
committed
fix: Fix handling of "format" in package includes initialization
Ensure that "format" is always processed as a list when initializing package includes. If not explicit set default to sdist and wheel.
1 parent 61081dd commit d158c7b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/poetry/core/masonry/utils/module.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ def __init__(
7272
packages = [default_package]
7373

7474
for package in packages:
75+
formats = package.get("format", ["sdist", "wheel"])
76+
if formats and not isinstance(formats, list):
77+
formats = [formats]
78+
7579
self._package_includes.append(
7680
PackageInclude(
7781
self._path,
7882
package["include"],
79-
formats=package["format"],
83+
formats=formats,
8084
source=package.get("from"),
8185
target=package.get("to"),
8286
)

tests/masonry/utils/test_module.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from poetry.core.factory import Factory
6+
from poetry.core.masonry.utils.module import Module
7+
from tests.test_factory import fixtures_dir
8+
9+
10+
@pytest.mark.parametrize(
11+
["given_format", "expected_formats"],
12+
[
13+
(None, ["sdist", "wheel"]),
14+
("sdist", ["sdist"]),
15+
("wheel", ["wheel"]),
16+
(["sdist", "wheel"], ["sdist", "wheel"]),
17+
],
18+
)
19+
def test_create_module_select_correct_formats(
20+
given_format: str | list[str] | None, expected_formats: list[str]
21+
) -> None:
22+
directory = fixtures_dir / "project_with_markers_and_extras"
23+
poetry = Factory().create_poetry(directory)
24+
25+
package = poetry.package
26+
assert "format" not in package.packages[0]
27+
28+
if given_format:
29+
package.packages[0]["format"] = given_format # type: ignore[index]
30+
31+
module = Module(
32+
name=package.name, directory=str(directory), packages=package.packages
33+
)
34+
assert len(module.includes) == 1
35+
assert module.includes[0].formats == expected_formats

0 commit comments

Comments
 (0)