Skip to content

Commit

Permalink
respect format for explicit included files when finding excluded files (
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer authored Nov 9, 2021
1 parent 1ad005f commit 237a4c8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
7 changes: 5 additions & 2 deletions poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
Original file line number Diff line number Diff line change
@@ -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"
45 changes: 45 additions & 0 deletions tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 237a4c8

Please sign in to comment.