diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index 9797b1e10..2893af7c5 100644 --- a/poetry/core/masonry/builders/builder.py +++ b/poetry/core/masonry/builders/builder.py @@ -104,7 +104,7 @@ def executable(self) -> Path: def build(self) -> None: raise NotImplementedError() - def find_excluded_files(self) -> Set[str]: + def find_excluded_files(self, fmt: Optional[str] = None) -> Set[str]: if self._excluded_files is None: from poetry.core.vcs import get_vcs @@ -124,6 +124,9 @@ def find_excluded_files(self) -> Set[str]: explicitely_included = set() for inc in self._package.include: + if fmt and inc["format"] and fmt not in inc["format"]: + continue + included_glob = inc["path"] for included in self._path.glob(str(included_glob)): explicitely_included.add( @@ -146,7 +149,7 @@ def is_excluded(self, filepath: Union[str, Path]) -> bool: exclude_path = Path(filepath) while True: - if exclude_path.as_posix() in self.find_excluded_files(): + if exclude_path.as_posix() in self.find_excluded_files(fmt=self.format): return True if len(exclude_path.parts) > 1: diff --git a/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/__init__.py b/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/__init__.py new file mode 100644 index 000000000..3dc1f76bc --- /dev/null +++ b/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.0" diff --git a/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/compiled/source.c b/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/compiled/source.c new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/compiled/source.h b/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/compiled/source.h new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/cython_code.pyx b/tests/masonry/builders/fixtures/exclude-whl-include-sdist/exclude_whl_include_sdist/cython_code.pyx new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/exclude-whl-include-sdist/pyproject.toml b/tests/masonry/builders/fixtures/exclude-whl-include-sdist/pyproject.toml new file mode 100644 index 000000000..a684e61a4 --- /dev/null +++ b/tests/masonry/builders/fixtures/exclude-whl-include-sdist/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "exclude-whl-include-sdist" +description = "" +authors = [] +version = "0.1.0" +exclude = ["exclude_whl_include_sdist/compiled", "exclude_whl_include_sdist/*.pyx"] +include = [ + { path = "exclude_whl_include_sdist/compiled/**/*", format = "sdist" }, + { path = "exclude_whl_include_sdist/*.pyx", format = "sdist" } +] + +[tool.poetry.dependencies] +python = "^3.9" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/tests/masonry/builders/test_complete.py b/tests/masonry/builders/test_complete.py index 50e919552..d110443f8 100644 --- a/tests/masonry/builders/test_complete.py +++ b/tests/masonry/builders/test_complete.py @@ -556,3 +556,48 @@ def test_package_with_include(mocker): assert "package_with_include/__init__.py" in names assert "tests/__init__.py" not in names assert "src_package/__init__.py" in names + + +def test_respect_format_for_explicit_included_files(): + module_path = fixtures_dir / "exclude-whl-include-sdist" + builder = Builder(Factory().create_poetry(module_path)) + builder.build(fmt="all") + + sdist = module_path / "dist" / "exclude-whl-include-sdist-0.1.0.tar.gz" + + assert sdist.exists() + + with tarfile.open(str(sdist), "r") as tar: + names = tar.getnames() + assert ( + "exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/__init__.py" + in names + ) + assert ( + "exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/compiled/source.c" + in names + ) + assert ( + "exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/compiled/source.h" + in names + ) + assert ( + "exclude-whl-include-sdist-0.1.0/exclude_whl_include_sdist/cython_code.pyx" + in names + ) + assert "exclude-whl-include-sdist-0.1.0/pyproject.toml" in names + assert "exclude-whl-include-sdist-0.1.0/setup.py" in names + assert "exclude-whl-include-sdist-0.1.0/PKG-INFO" in names + + whl = module_path / "dist" / "exclude_whl_include_sdist-0.1.0-py3-none-any.whl" + + assert whl.exists() + + with zipfile.ZipFile(str(whl)) as z: + names = z.namelist() + assert "exclude_whl_include_sdist/__init__.py" in names + assert "exclude_whl_include_sdist/compiled/source.c" not in names + assert "exclude_whl_include_sdist/compiled/source.h" not in names + assert "exclude_whl_include_sdist/cython_code.pyx" not in names + + pass