Skip to content

Commit 1787a35

Browse files
authored
feat(hatch): add support for configured exclude paths pattern (#339)
* feat(hatch): add support for configured exclude paths pattern when building wheels and sdists * feat(build): add .ruff_cache to default exclude pattern * bump hatch hook to 1.4.0 * bump PDM hooks to 1.2.0 * bump CLI to 1.29.0
1 parent fcea9a8 commit 1787a35

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

components/polylith/hatch/hooks/bricks.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def filtered_bricks(data: dict, version: str) -> dict:
3434
return bricks
3535

3636

37+
def collect_configured_exclude_patterns(data: dict, target_name: str) -> set:
38+
entry = data.get("tool", {}).get("hatch", {}).get("build", {})
39+
target = entry.get("targets", {}).get(target_name, {})
40+
41+
exclude = target.get("exclude", [])
42+
43+
return set(exclude)
44+
45+
3746
class PolylithBricksHook(BuildHookInterface):
3847
PLUGIN_NAME = "polylith-bricks"
3948

@@ -57,9 +66,10 @@ def initialize(self, version: str, build_data: Dict[str, Any]) -> None:
5766
return
5867

5968
ns = parsing.parse_brick_namespace_from_path(bricks)
69+
exclude_patterns = collect_configured_exclude_patterns(data, self.target_name)
6070

6171
for source, brick in bricks.items():
62-
path = parsing.copy_brick(source, brick, work_dir)
72+
path = parsing.copy_brick(source, brick, work_dir, exclude_patterns)
6373
rewritten_bricks = parsing.rewrite_modules(path, ns, top_ns)
6474

6575
for item in rewritten_bricks:

components/polylith/parsing/core.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
import shutil
22
from pathlib import Path
3+
from typing import Union
34

5+
default_patterns = {
6+
"*.pyc",
7+
"__pycache__",
8+
".venv",
9+
"__pypackages__",
10+
".mypy_cache",
11+
".ruff_cache",
12+
".pytest_cache",
13+
"node_modules",
14+
".git",
15+
}
416

5-
def copy_tree(source: str, destination: str) -> Path:
6-
ignore = shutil.ignore_patterns(
7-
"*.pyc",
8-
"__pycache__",
9-
".venv",
10-
"__pypackages__",
11-
".mypy_cache",
12-
".pytest_cache",
13-
"node_modules",
14-
".git",
15-
)
17+
18+
def copy_tree(source: str, destination: str, patterns: set) -> Path:
19+
ignore = shutil.ignore_patterns(*patterns)
1620

1721
res = shutil.copytree(source, destination, ignore=ignore, dirs_exist_ok=True)
1822

1923
return Path(res)
2024

2125

22-
def copy_brick(source: str, brick: str, destination_dir: Path) -> Path:
26+
def copy_brick(
27+
source: str,
28+
brick: str,
29+
destination_dir: Path,
30+
exclude_patterns: Union[set, None] = None,
31+
) -> Path:
2332
destination = Path(destination_dir / brick).as_posix()
2433

25-
return copy_tree(source, destination)
34+
patterns = set().union(default_patterns, exclude_patterns or set())
35+
36+
return copy_tree(source, destination, patterns)
2637

2738

2839
def parse_brick_namespace_from_path(bricks: dict) -> str:

projects/hatch_polylith_bricks/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "hatch-polylith-bricks"
3-
version = "1.3.2"
3+
version = "1.4.0"
44
description = "Hatch build hook plugin for Polylith"
55
authors = ['David Vujic']
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

projects/pdm_polylith_bricks/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pdm-polylith-bricks"
3-
version = "1.1.2"
3+
version = "1.2.0"
44
description = "a PDM build hook for Polylith"
55
authors = ["David Vujic"]
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

projects/pdm_polylith_workspace/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pdm-polylith-workspace"
3-
version = "1.1.2"
3+
version = "1.2.0"
44
description = "a PDM build hook for a Polylith workspace"
55
homepage = "https://davidvujic.github.io/python-polylith-docs/"
66
repository = "https://github.com/davidvujic/python-polylith"

projects/polylith_cli/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "polylith-cli"
3-
version = "1.28.0"
3+
version = "1.29.0"
44
description = "Python tooling support for the Polylith Architecture"
55
authors = ['David Vujic']
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

0 commit comments

Comments
 (0)