Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sdist build for multiple readme files #486

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from posixpath import join as pjoin
from pprint import pformat
from typing import TYPE_CHECKING
from typing import Iterable
from typing import Iterator

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

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

# add script files
additional_files.update(self.convert_script_files())

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

# add readme if it is specified
# add readme files if specified
if "readme" in self._poetry.local_config:
additional_files.add(self._poetry.local_config["readme"])
readme: str | Iterable[str] = self._poetry.local_config["readme"]
if isinstance(readme, str):
additional_files.add(Path(readme))
else:
additional_files.update(Path(r) for r in readme)

for additional_file in additional_files:
file = BuildIncludeFile(
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/with_readme_files/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "single-python"
name = "my-package"
version = "0.1"
description = "Some description."
authors = [
Expand All @@ -16,4 +16,4 @@ homepage = "https://python-poetry.org/"


[tool.poetry.dependencies]
python = "2.7.15"
python = "^2.7"
42 changes: 28 additions & 14 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,37 @@ def test_find_files_to_add() -> None:
poetry = Factory().create_poetry(project("complete"))

builder = SdistBuilder(poetry)
result = [f.relative_to_source_root() for f in builder.find_files_to_add()]
result = {f.relative_to_source_root() for f in builder.find_files_to_add()}

assert result == {
Path("LICENSE"),
Path("README.rst"),
Path("bin/script.sh"),
Path("my_package/__init__.py"),
Path("my_package/data1/test.json"),
Path("my_package/sub_pkg1/__init__.py"),
Path("my_package/sub_pkg2/__init__.py"),
Path("my_package/sub_pkg2/data2/data.json"),
Path("my_package/sub_pkg3/foo.py"),
Path("pyproject.toml"),
}

assert sorted(result) == sorted(
[
Path("LICENSE"),
Path("README.rst"),
Path("bin/script.sh"),
Path("my_package/__init__.py"),
Path("my_package/data1/test.json"),
Path("my_package/sub_pkg1/__init__.py"),
Path("my_package/sub_pkg2/__init__.py"),
Path("my_package/sub_pkg2/data2/data.json"),
Path("my_package/sub_pkg3/foo.py"),
Path("pyproject.toml"),
]

def test_find_files_to_add_with_multiple_readme_files() -> None:
poetry = Factory().create_poetry(
Path(__file__).parent.parent.parent / "fixtures" / "with_readme_files"
)

builder = SdistBuilder(poetry)
result = {f.relative_to_source_root() for f in builder.find_files_to_add()}

assert result == {
Path("README-1.rst"),
Path("README-2.rst"),
Path("my_package/__init__.py"),
Path("pyproject.toml"),
}


def test_make_pkg_info_multi_constraints_dependency() -> None:
poetry = Factory().create_poetry(
Expand Down