Skip to content

Commit 3e1d256

Browse files
authored
feat(poly deps): view usage of brick interfaces (#436)
* wip(poly deps): check bricks interfaces * bump Poetry plugin to 1.51.0 * bump CLI to 1.45.0
1 parent f84fe46 commit 3e1d256

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

components/polylith/commands/deps.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ def used_by_as_bricks(bricks: dict, brick_deps: dict) -> dict:
4141
}
4242

4343

44+
def print_possible_invalid_bricks_interfaces_usage(
45+
root: Path, ns: str, bricks: dict, bricks_deps: dict
46+
) -> None:
47+
flattened_bricks = set().union(*bricks.values())
48+
bricks_with_deps = {b: bricks_deps[b] for b in flattened_bricks if b in bricks_deps}
49+
50+
for brick, brick_deps in bricks_with_deps.items():
51+
used_bricks = used_by_as_bricks(bricks, brick_deps)
52+
53+
interface.report.print_brick_interface_invalid_usage(
54+
root, ns, brick, used_bricks
55+
)
56+
57+
4458
def run(root: Path, ns: str, options: dict):
4559
directory = options.get("directory")
4660
brick = options.get("brick")
@@ -84,4 +98,8 @@ def run(root: Path, ns: str, options: dict):
8498
return
8599

86100
deps.print_deps(bricks, imports, options)
101+
102+
if show_interface:
103+
print_possible_invalid_bricks_interfaces_usage(root, ns, bricks, bricks_deps)
104+
87105
deps.print_bricks_with_circular_deps(circular_bricks, bricks)

components/polylith/deps/report.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ def print_brick_deps(brick: str, bricks: dict, brick_deps: dict, options: dict):
145145
output.save(table, options, f"deps_{brick}")
146146

147147

148-
def print_brick_with_circular_deps(brick: str, deps: Set[str], bricks: dict) -> None:
148+
def print_brick_with_circular_deps(
149+
brick: str, deps: Set[str], bricks: dict, padding: Union[tuple, None] = None
150+
) -> None:
149151
bases = bricks["bases"]
150152

151153
console = Console(theme=theme.poly_theme)
@@ -158,9 +160,13 @@ def print_brick_with_circular_deps(brick: str, deps: Set[str], bricks: dict) ->
158160
prefix = ":information:"
159161
message = f"[{tag}]{brick}[/] [data]is used by[/] {others} [data]and also uses[/] {others}[data].[/]"
160162

161-
console.print(Padding(f"{prefix} {message}", (0, 0, 0, 1)), overflow="ellipsis")
163+
pad = padding or (1, 0, 0, 1)
164+
console.print(Padding(f"{prefix} {message}", pad), overflow="ellipsis")
162165

163166

164167
def print_bricks_with_circular_deps(circular_bricks: dict, bricks: dict) -> None:
168+
console = Console(theme=theme.poly_theme)
169+
console.print()
170+
165171
for brick, deps in circular_bricks.items():
166-
print_brick_with_circular_deps(brick, deps, bricks)
172+
print_brick_with_circular_deps(brick, deps, bricks, (0, 0, 0, 1))

components/polylith/interface/report.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from polylith.interface.usage import check_brick_interface_usage, unified_usages
55
from polylith.reporting import theme
66
from rich.console import Console
7+
from rich.padding import Padding
78
from rich.table import Table
89

910

@@ -26,7 +27,7 @@ def print_brick_interface(root: Path, ns: str, brick: str, bricks: dict) -> None
2627
*_ns, exposes = str.split(endpoint, ".")
2728
table.add_row(f"[data]{exposes}[/]")
2829

29-
console.print(table, overflow="ellipsis")
30+
console.print(Padding(table, (0, 0, 1, 0)), overflow="ellipsis")
3031

3132

3233
def print_brick_interface_invalid_usage(
@@ -45,7 +46,6 @@ def print_brick_interface_invalid_usage(
4546

4647
console = Console(theme=theme.poly_theme)
4748

48-
table = Table(box=None)
4949
tag = "base" if brick in bricks["bases"] else "comp"
5050

5151
for using_brick, usages in invalid_usage.items():
@@ -58,6 +58,4 @@ def print_brick_interface_invalid_usage(
5858

5959
message = f":information: {prefix}: {middle}."
6060

61-
table.add_row(f"{message}")
62-
63-
console.print(table, overflow="ellipsis")
61+
console.print(Padding(f"{message}", (0, 0, 0, 1)), overflow="ellipsis")

projects/poetry_polylith_plugin/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 = "poetry-polylith-plugin"
3-
version = "1.50.0"
3+
version = "1.51.0"
44
description = "A Poetry plugin that adds tooling support for the Polylith Architecture"
55
authors = ["David Vujic"]
66
homepage = "https://davidvujic.github.io/python-polylith-docs/"

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.44.0"
3+
version = "1.45.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)