From 6974e7a468d0141dafb4e6898fda9342c0de2140 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Mon, 6 Jan 2025 21:25:05 +0100 Subject: [PATCH] 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. --- src/poetry/core/factory.py | 7 +++++++ tests/test_factory.py | 28 ++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/poetry/core/factory.py b/src/poetry/core/factory.py index 8c369f4a8..b4b689601 100644 --- a/src/poetry/core/factory.py +++ b/src/poetry/core/factory.py @@ -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 diff --git a/tests/test_factory.py b/tests/test_factory.py index 5da4a1aaf..6ebc38694 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -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 == [