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 6, 2025
1 parent 61081dd commit 6974e7a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ def _configure_package_poetry_specifics(
package.exclude = exclude

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

package.packages = packages

@classmethod
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 6974e7a

Please sign in to comment.