From 7a8e6bf585c38828c69650fd81a47733c546aea0 Mon Sep 17 00:00:00 2001 From: David Vujic Date: Wed, 4 Jun 2025 18:58:42 +0200 Subject: [PATCH 1/6] feat(hatch): add support for configured exclude paths pattern when building wheels and sdists --- components/polylith/hatch/hooks/bricks.py | 12 +++++++- components/polylith/parsing/core.py | 37 +++++++++++++++-------- 2 files changed, 35 insertions(+), 14 deletions(-) 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: From 3a32811d1e289fc5be2886c32d80c0fb74b1396b Mon Sep 17 00:00:00 2001 From: David Vujic Date: Wed, 4 Jun 2025 19:02:28 +0200 Subject: [PATCH 2/6] bump hatch hook to 1.4.0 --- projects/hatch_polylith_bricks/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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/" From 38d70832e7a00e2f2434d605bfca328e980969d0 Mon Sep 17 00:00:00 2001 From: David Vujic Date: Wed, 4 Jun 2025 19:03:03 +0200 Subject: [PATCH 3/6] bump PDM hooks to 1.1.3 --- projects/pdm_polylith_bricks/pyproject.toml | 2 +- projects/pdm_polylith_workspace/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/pdm_polylith_bricks/pyproject.toml b/projects/pdm_polylith_bricks/pyproject.toml index eb726941..01b41564 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.1.3" 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..1b3e6534 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.1.3" description = "a PDM build hook for a Polylith workspace" homepage = "https://davidvujic.github.io/python-polylith-docs/" repository = "https://github.com/davidvujic/python-polylith" From c14267bf8e0dba42c4f30df9fb922f431779338b Mon Sep 17 00:00:00 2001 From: David Vujic Date: Wed, 4 Jun 2025 19:04:45 +0200 Subject: [PATCH 4/6] bump CLI to 1.28.1 --- projects/polylith_cli/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/polylith_cli/pyproject.toml b/projects/polylith_cli/pyproject.toml index 9a6f4e79..d1675dd8 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.28.1" description = "Python tooling support for the Polylith Architecture" authors = ['David Vujic'] homepage = "https://davidvujic.github.io/python-polylith-docs/" From 1d0bbdcd189736d677adeba065255a208b980208 Mon Sep 17 00:00:00 2001 From: David Vujic Date: Wed, 4 Jun 2025 20:57:59 +0200 Subject: [PATCH 5/6] bump PDM hooks to 1.2.0 --- projects/pdm_polylith_bricks/pyproject.toml | 2 +- projects/pdm_polylith_workspace/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/pdm_polylith_bricks/pyproject.toml b/projects/pdm_polylith_bricks/pyproject.toml index 01b41564..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.3" +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 1b3e6534..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.3" +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" From 606eab747c982abe48c7fd489d0a942d58c5c0c4 Mon Sep 17 00:00:00 2001 From: David Vujic Date: Wed, 4 Jun 2025 20:58:11 +0200 Subject: [PATCH 6/6] bump CLI to 1.29.0 --- projects/polylith_cli/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/polylith_cli/pyproject.toml b/projects/polylith_cli/pyproject.toml index d1675dd8..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.1" +version = "1.29.0" description = "Python tooling support for the Polylith Architecture" authors = ['David Vujic'] homepage = "https://davidvujic.github.io/python-polylith-docs/"