Skip to content

Commit

Permalink
refactor: set default formats for includes in Factory
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Jan 7, 2025
1 parent 3c8dbf2 commit 7bfad90
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
16 changes: 12 additions & 4 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,18 @@ def _configure_package_poetry_specifics(
package.build_config = build or {}

if includes := tool_poetry.get("include"):
package.include = [
include if isinstance(include, dict) else {"path": include}
for include in includes
]
includes_ = []
for include in includes:
if not isinstance(include, dict):
include = {"path": include}

formats = include.get("format", ["sdist"])
if not isinstance(formats, list):
formats = [formats]

includes_.append({**include, "format": formats})

package.include = includes_

if exclude := tool_poetry.get("exclude"):
package.exclude = exclude
Expand Down
16 changes: 5 additions & 11 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,15 @@ def _module(self) -> Module:

packages: list[dict[str, str | dict[str, str]]] = []
includes: list[dict[str, str | dict[str, str]]] = []
for source_list, target_list, default in [
(self._package.packages, packages, ["sdist", "wheel"]),
(self._package.include, includes, ["sdist"]),
for source_list, target_list in [
(self._package.packages, packages),
(self._package.include, includes),
]:
for item in source_list:
# Default to including in both sdist & wheel
# if the `format` key is not provided.
formats = item.get("format", default)
if not isinstance(formats, list):
formats = [formats]

if self.format and self.format not in formats:
if self.format and self.format not in item["format"]:
continue

target_list.append({**item, "format": formats})
target_list.append({**item})

return Module(
self._package.name,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_create_poetry_with_packages_and_includes() -> None:

assert package.include == [
{"path": "extra_dir/vcs_excluded.py", "format": ["sdist", "wheel"]},
{"path": "notes.txt"},
{"path": "notes.txt", "format": ["sdist"]},
]


Expand Down

0 comments on commit 7bfad90

Please sign in to comment.