Skip to content

Commit

Permalink
fix: Fix handling of "format" in package includes initialization
Browse files Browse the repository at this point in the history
Ensure that "format" is always processed as a list when initializing package includes. If not explicit set default to sdist and wheel.
  • Loading branch information
finswimmer committed Jan 7, 2025
1 parent 61081dd commit 5d007ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
10 changes: 9 additions & 1 deletion src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,15 @@ def _configure_package_poetry_specifics(
package.exclude = exclude

if packages := tool_poetry.get("packages"):
package.packages = packages
packages_ = []
for p in packages:
formats = p.get("format", ["sdist", "wheel"])
if not isinstance(formats, list):
formats = [formats]

packages_.append({**p, "format": formats})

package.packages = packages_

@classmethod
def create_dependency(
Expand Down
28 changes: 20 additions & 8 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,27 @@ def test_create_poetry_with_packages_and_includes() -> None:
package = poetry.package

assert package.packages == [
{"include": "extra_dir/**/*.py"},
{"include": "extra_dir/**/*.py"},
{"include": "my_module.py"},
{"include": "package_with_include"},
{"include": "tests", "format": "sdist"},
{"include": "extra_dir/**/*.py", "format": ["sdist", "wheel"]},
{"include": "extra_dir/**/*.py", "format": ["sdist", "wheel"]},
{"include": "my_module.py", "format": ["sdist", "wheel"]},
{"include": "package_with_include", "format": ["sdist", "wheel"]},
{
"include": "tests",
"format": ["sdist"],
},
{"include": "for_wheel_only", "format": ["wheel"]},
{"include": "src_package", "from": "src"},
{"include": "from_to", "from": "etc", "to": "target_from_to"},
{"include": "my_module_to.py", "to": "target_module"},
{"include": "src_package", "from": "src", "format": ["sdist", "wheel"]},
{
"include": "from_to",
"from": "etc",
"to": "target_from_to",
"format": ["sdist", "wheel"],
},
{
"include": "my_module_to.py",
"to": "target_module",
"format": ["sdist", "wheel"],
},
]

assert package.include == [
Expand Down

0 comments on commit 5d007ed

Please sign in to comment.