Skip to content

Commit cd5b624

Browse files
Fix sdist build for multiple readme files (#486)
1 parent af98abc commit cd5b624

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

src/poetry/core/masonry/builders/sdist.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from posixpath import join as pjoin
1515
from pprint import pformat
1616
from typing import TYPE_CHECKING
17+
from typing import Iterable
1718
from typing import Iterator
1819

1920
from poetry.core.masonry.builders.builder import Builder
@@ -322,17 +323,21 @@ def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile
322323
to_add = super().find_files_to_add(exclude_build)
323324

324325
# add any additional files, starting with all LICENSE files
325-
additional_files = set(self._path.glob("LICENSE*"))
326+
additional_files: set[Path] = set(self._path.glob("LICENSE*"))
326327

327328
# add script files
328329
additional_files.update(self.convert_script_files())
329330

330331
# Include project files
331332
additional_files.add(Path("pyproject.toml"))
332333

333-
# add readme if it is specified
334+
# add readme files if specified
334335
if "readme" in self._poetry.local_config:
335-
additional_files.add(self._poetry.local_config["readme"])
336+
readme: str | Iterable[str] = self._poetry.local_config["readme"]
337+
if isinstance(readme, str):
338+
additional_files.add(Path(readme))
339+
else:
340+
additional_files.update(Path(r) for r in readme)
336341

337342
for additional_file in additional_files:
338343
file = BuildIncludeFile(

tests/fixtures/with_readme_files/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.poetry]
2-
name = "single-python"
2+
name = "my-package"
33
version = "0.1"
44
description = "Some description."
55
authors = [
@@ -16,4 +16,4 @@ homepage = "https://python-poetry.org/"
1616

1717

1818
[tool.poetry.dependencies]
19-
python = "2.7.15"
19+
python = "^2.7"

tests/masonry/builders/test_sdist.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,37 @@ def test_find_files_to_add() -> None:
175175
poetry = Factory().create_poetry(project("complete"))
176176

177177
builder = SdistBuilder(poetry)
178-
result = [f.relative_to_source_root() for f in builder.find_files_to_add()]
178+
result = {f.relative_to_source_root() for f in builder.find_files_to_add()}
179+
180+
assert result == {
181+
Path("LICENSE"),
182+
Path("README.rst"),
183+
Path("bin/script.sh"),
184+
Path("my_package/__init__.py"),
185+
Path("my_package/data1/test.json"),
186+
Path("my_package/sub_pkg1/__init__.py"),
187+
Path("my_package/sub_pkg2/__init__.py"),
188+
Path("my_package/sub_pkg2/data2/data.json"),
189+
Path("my_package/sub_pkg3/foo.py"),
190+
Path("pyproject.toml"),
191+
}
179192

180-
assert sorted(result) == sorted(
181-
[
182-
Path("LICENSE"),
183-
Path("README.rst"),
184-
Path("bin/script.sh"),
185-
Path("my_package/__init__.py"),
186-
Path("my_package/data1/test.json"),
187-
Path("my_package/sub_pkg1/__init__.py"),
188-
Path("my_package/sub_pkg2/__init__.py"),
189-
Path("my_package/sub_pkg2/data2/data.json"),
190-
Path("my_package/sub_pkg3/foo.py"),
191-
Path("pyproject.toml"),
192-
]
193+
194+
def test_find_files_to_add_with_multiple_readme_files() -> None:
195+
poetry = Factory().create_poetry(
196+
Path(__file__).parent.parent.parent / "fixtures" / "with_readme_files"
193197
)
194198

199+
builder = SdistBuilder(poetry)
200+
result = {f.relative_to_source_root() for f in builder.find_files_to_add()}
201+
202+
assert result == {
203+
Path("README-1.rst"),
204+
Path("README-2.rst"),
205+
Path("my_package/__init__.py"),
206+
Path("pyproject.toml"),
207+
}
208+
195209

196210
def test_make_pkg_info_multi_constraints_dependency() -> None:
197211
poetry = Factory().create_poetry(

0 commit comments

Comments
 (0)