Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion components/polylith/hatch/hooks/bricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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:
Expand Down
37 changes: 24 additions & 13 deletions components/polylith/parsing/core.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion projects/hatch_polylith_bricks/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion projects/pdm_polylith_bricks/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion projects/pdm_polylith_workspace/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion projects/polylith_cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down