Skip to content

Commit

Permalink
masonry: fix handling of multiple package sources
Browse files Browse the repository at this point in the history
This change ensures that when multiple packages are included with a 
from directive, they are correctly included in both sdist and bdists.
  • Loading branch information
lucasiscovici2 authored Mar 9, 2022
1 parent 1314ad4 commit 0c5cfa4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,22 @@ def find_files_to_add(self, exclude_build: bool = True) -> Set["BuildIncludeFile
if "__pycache__" in str(file):
continue

if (
isinstance(include, PackageInclude)
and include.source
and self.format == "wheel"
):
source_root = include.base
else:
source_root = self._path

if file.is_dir():
if self.format in formats:
for current_file in file.glob("**/*"):
include_file = BuildIncludeFile(
path=current_file,
project_root=self._path,
source_root=self._path,
source_root=source_root,
)

if not current_file.is_dir() and not self.is_excluded(
Expand All @@ -185,15 +194,6 @@ def find_files_to_add(self, exclude_build: bool = True) -> Set["BuildIncludeFile
to_add.add(include_file)
continue

if (
isinstance(include, PackageInclude)
and include.source
and self.format == "wheel"
):
source_root = include.base
else:
source_root = self._path

include_file = BuildIncludeFile(
path=file, project_root=self._path, source_root=source_root
)
Expand Down
26 changes: 26 additions & 0 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,32 @@ def test_package_src():
zip.close()


def test_split_source():
module_path = fixtures_dir / "split_source"
builder = Builder(Factory().create_poetry(module_path))
builder.build(fmt="all")

sdist = module_path / "dist" / "split-source-0.1.tar.gz"

assert sdist.exists()

with tarfile.open(str(sdist), "r") as tar:
assert "split-source-0.1/lib_a/module_a/__init__.py" in tar.getnames()
assert "split-source-0.1/lib_b/module_b/__init__.py" in tar.getnames()

whl = module_path / "dist" / "split_source-0.1-py3-none-any.whl"

assert whl.exists()

zip = zipfile.ZipFile(str(whl))

try:
assert "module_a/__init__.py" in zip.namelist()
assert "module_b/__init__.py" in zip.namelist()
finally:
zip.close()


def test_package_with_include(mocker: "MockerFixture"):
module_path = fixtures_dir / "with-include"

Expand Down

0 comments on commit 0c5cfa4

Please sign in to comment.