From c9d3c54778743df477f845987568f715b7bfc1b8 Mon Sep 17 00:00:00 2001 From: lucasiscovici-loreal Date: Sat, 12 Feb 2022 02:33:09 +0100 Subject: [PATCH 1/2] Move up source condition and use source_root for files inside dir --- src/poetry/core/masonry/builders/builder.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/poetry/core/masonry/builders/builder.py b/src/poetry/core/masonry/builders/builder.py index a4056a787..e0b33eead 100644 --- a/src/poetry/core/masonry/builders/builder.py +++ b/src/poetry/core/masonry/builders/builder.py @@ -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( @@ -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 ) From c59c8ecfe853617c08ef48ec50844bf02c0dc8af Mon Sep 17 00:00:00 2001 From: lucasiscovici-loreal Date: Wed, 9 Mar 2022 00:48:33 +0100 Subject: [PATCH 2/2] add test for multiple package with from keyword --- tests/masonry/builders/test_complete.py | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/masonry/builders/test_complete.py b/tests/masonry/builders/test_complete.py index 672242111..6be09a470 100644 --- a/tests/masonry/builders/test_complete.py +++ b/tests/masonry/builders/test_complete.py @@ -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"