Skip to content

Commit

Permalink
fix(poly diff): adjust view for many projects (#104)
Browse files Browse the repository at this point in the history
* fix(poly diff): adjust for workspace with many projects

* fix(poly info and diff): separate components and bases by color in views

* refactor: share code between poly info and diff reporting

* bump version to 1.8.1
  • Loading branch information
DavidVujic authored Aug 1, 2023
1 parent 59a53b4 commit 44a7b28
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 41 deletions.
28 changes: 5 additions & 23 deletions components/polylith/diff/report.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,23 @@
from typing import List

from polylith import info
from polylith.reporting import theme
from rich import box
from rich.columns import Columns
from rich.console import Console
from rich.padding import Padding
from rich.table import Table


def brick_status(brick, bricks) -> str:
status = ":gear:" if brick in bricks else "-"

return f"[data]{status}[/]"


def print_diff_details(
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:

if not bases and not components:
return

console = Console(theme=theme.poly_theme)
table = Table(box=box.SIMPLE_HEAD)
table.add_column("[data]changed brick[/]")

proj_cols = [f"[proj]{project['name']}[/]" for project in projects_data]
table.add_column(Columns(proj_cols, align="center", expand=True))

for brick in sorted(components):
cols = [brick_status(brick, p.get("components")) for p in projects_data]
table.add_row(f"[comp]{brick}[/]", Columns(cols, align="center", expand=True))

for brick in sorted(bases):
cols = [brick_status(brick, p.get("bases")) for p in projects_data]
table.add_row(f"[base]{brick}[/]", Columns(cols, align="center", expand=True))
options = {"command": "diff"}
table = info.report.build_bricks_in_projects_table(
projects_data, bases, components, options
)

console.print(table, overflow="ellipsis")

Expand Down Expand Up @@ -82,7 +65,6 @@ def print_short_diff(
bases: List[str],
components: List[str],
) -> None:

a = _changed_projects(projects_data, "components", components)
b = _changed_projects(projects_data, "bases", bases)
c = set(projects)
Expand Down
2 changes: 2 additions & 0 deletions components/polylith/info/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from polylith.info.report import (
is_project,
print_bricks_in_projects,
print_compressed_view_for_bricks_in_projects,
print_workspace_summary,
)

Expand All @@ -17,5 +18,6 @@
"get_projects_data",
"is_project",
"print_bricks_in_projects",
"print_compressed_view_for_bricks_in_projects",
"print_workspace_summary",
]
60 changes: 44 additions & 16 deletions components/polylith/info/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from rich.table import Table


def brick_status(brick, bricks) -> str:
status = ":heavy_check_mark:" if brick in bricks else "-"
def brick_status(brick, bricks, command: str) -> str:
emoji = ":heavy_check_mark:" if command == "info" else ":gear:"

status = emoji if brick in bricks else "-"

return f"[data]{status}[/]"

Expand All @@ -31,19 +33,15 @@ def printable_name(project: dict, short: bool) -> str:
return template.format(name=name)


def construct_brick_columns(brick: str, brick_type: str, projects_data: List[dict]):
statuses = [brick_status(brick, p.get(brick_type)) for p in projects_data]

return [f"[comp]{brick}[/]"] + statuses


def print_bricks_in_projects(
projects_data: List[dict], bases: List[str], components: List[str], short: bool
) -> None:
if not components and not bases:
return
def build_bricks_in_projects_table(
projects_data: List[dict],
bases: List[str],
components: List[str],
options: dict,
) -> Table:
short = options.get("short", False)
command = options.get("command", "info")

console = Console(theme=theme.poly_theme)
table = Table(box=box.SIMPLE_HEAD)
table.add_column("[data]brick[/]")

Expand All @@ -53,16 +51,46 @@ def print_bricks_in_projects(
table.add_column(col, justify="center")

for brick in sorted(components):
cols = construct_brick_columns(brick, "components", projects_data)
statuses = [
brick_status(brick, p.get("components"), command) for p in projects_data
]
cols = [f"[comp]{brick}[/]"] + statuses

table.add_row(*cols)

for brick in sorted(bases):
cols = construct_brick_columns(brick, "bases", projects_data)
statuses = [brick_status(brick, p.get("bases"), command) for p in projects_data]
cols = [f"[base]{brick}[/]"] + statuses

table.add_row(*cols)

return table


def print_table(table: Table) -> None:
console = Console(theme=theme.poly_theme)

console.print(table, overflow="ellipsis")


def print_compressed_view_for_bricks_in_projects(
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:
options = {"short": True}
table = build_bricks_in_projects_table(projects_data, bases, components, options)

print_table(table)


def print_bricks_in_projects(
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:
options = {"short": False}
table = build_bricks_in_projects_table(projects_data, bases, components, options)

print_table(table)


def print_workspace_summary(
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:
Expand Down
11 changes: 10 additions & 1 deletion components/polylith/poetry/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def handle(self) -> int:
projects_data = info.get_bricks_in_projects(root, components, bases, ns)

info.print_workspace_summary(projects_data, bases, components)
info.print_bricks_in_projects(projects_data, bases, components, short)

if not components and not bases:
return 0

if short:
info.print_compressed_view_for_bricks_in_projects(
projects_data, bases, components
)
else:
info.print_bricks_in_projects(projects_data, bases, components)

return 0
2 changes: 1 addition & 1 deletion projects/poetry_polylith_plugin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "poetry-polylith-plugin"
version = "1.8.0"
version = "1.8.1"
description = "A Poetry plugin that adds tooling support for the Polylith Architecture"
authors = ["David Vujic"]
homepage = "https://davidvujic.github.io/python-polylith-docs/"
Expand Down

0 comments on commit 44a7b28

Please sign in to comment.