diff --git a/components/polylith/hatch/hooks/bricks.py b/components/polylith/hatch/hooks/bricks.py index ae8233d1..096be2b3 100644 --- a/components/polylith/hatch/hooks/bricks.py +++ b/components/polylith/hatch/hooks/bricks.py @@ -34,6 +34,15 @@ def filtered_bricks(data: dict, version: str) -> dict: return bricks +def collect_configured_exclude_patterns(data: dict, target_name: str) -> set: + entry = data.get("tool", {}).get("hatch", {}).get("build", {}) + target = entry.get("targets", {}).get(target_name, {}) + + exclude = target.get("exclude", []) + + return set(exclude) + + class PolylithBricksHook(BuildHookInterface): PLUGIN_NAME = "polylith-bricks" @@ -57,9 +66,10 @@ def initialize(self, version: str, build_data: Dict[str, Any]) -> None: return ns = parsing.parse_brick_namespace_from_path(bricks) + exclude_patterns = collect_configured_exclude_patterns(data, self.target_name) for source, brick in bricks.items(): - path = parsing.copy_brick(source, brick, work_dir) + path = parsing.copy_brick(source, brick, work_dir, exclude_patterns) rewritten_bricks = parsing.rewrite_modules(path, ns, top_ns) for item in rewritten_bricks: diff --git a/components/polylith/parsing/core.py b/components/polylith/parsing/core.py index 0565ac5b..4dcc9cb8 100644 --- a/components/polylith/parsing/core.py +++ b/components/polylith/parsing/core.py @@ -1,28 +1,39 @@ import shutil from pathlib import Path +from typing import Union +default_patterns = { + "*.pyc", + "__pycache__", + ".venv", + "__pypackages__", + ".mypy_cache", + ".ruff_cache", + ".pytest_cache", + "node_modules", + ".git", +} -def copy_tree(source: str, destination: str) -> Path: - ignore = shutil.ignore_patterns( - "*.pyc", - "__pycache__", - ".venv", - "__pypackages__", - ".mypy_cache", - ".pytest_cache", - "node_modules", - ".git", - ) + +def copy_tree(source: str, destination: str, patterns: set) -> Path: + ignore = shutil.ignore_patterns(*patterns) res = shutil.copytree(source, destination, ignore=ignore, dirs_exist_ok=True) return Path(res) -def copy_brick(source: str, brick: str, destination_dir: Path) -> Path: +def copy_brick( + source: str, + brick: str, + destination_dir: Path, + exclude_patterns: Union[set, None] = None, +) -> Path: destination = Path(destination_dir / brick).as_posix() - return copy_tree(source, destination) + patterns = set().union(default_patterns, exclude_patterns or set()) + + return copy_tree(source, destination, patterns) def parse_brick_namespace_from_path(bricks: dict) -> str: diff --git a/projects/hatch_polylith_bricks/pyproject.toml b/projects/hatch_polylith_bricks/pyproject.toml index 41eb00e9..af72d63e 100644 --- a/projects/hatch_polylith_bricks/pyproject.toml +++ b/projects/hatch_polylith_bricks/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "hatch-polylith-bricks" -version = "1.3.2" +version = "1.4.0" description = "Hatch build hook plugin for Polylith" authors = ['David Vujic'] homepage = "https://davidvujic.github.io/python-polylith-docs/" diff --git a/projects/pdm_polylith_bricks/pyproject.toml b/projects/pdm_polylith_bricks/pyproject.toml index eb726941..b68e16e3 100644 --- a/projects/pdm_polylith_bricks/pyproject.toml +++ b/projects/pdm_polylith_bricks/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pdm-polylith-bricks" -version = "1.1.2" +version = "1.2.0" description = "a PDM build hook for Polylith" authors = ["David Vujic"] homepage = "https://davidvujic.github.io/python-polylith-docs/" diff --git a/projects/pdm_polylith_workspace/pyproject.toml b/projects/pdm_polylith_workspace/pyproject.toml index 667e99ff..2cdaa181 100644 --- a/projects/pdm_polylith_workspace/pyproject.toml +++ b/projects/pdm_polylith_workspace/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pdm-polylith-workspace" -version = "1.1.2" +version = "1.2.0" description = "a PDM build hook for a Polylith workspace" homepage = "https://davidvujic.github.io/python-polylith-docs/" repository = "https://github.com/davidvujic/python-polylith" diff --git a/projects/polylith_cli/pyproject.toml b/projects/polylith_cli/pyproject.toml index 9a6f4e79..564784cb 100644 --- a/projects/polylith_cli/pyproject.toml +++ b/projects/polylith_cli/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "polylith-cli" -version = "1.28.0" +version = "1.29.0" description = "Python tooling support for the Polylith Architecture" authors = ['David Vujic'] homepage = "https://davidvujic.github.io/python-polylith-docs/"