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
23 changes: 16 additions & 7 deletions components/polylith/diff/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@
from polylith import repo, workspace


def _parse_brick_name(folder: str, changed_file: Path) -> str:
file_path = Path(changed_file.as_posix().replace(folder, ""))

return next(p for p in file_path.parts if p != file_path.root)


def _get_changed(folder: str, changed_files: List[Path]) -> set:
return {p.parent.name for p in changed_files if folder in p.as_posix()}
return {_parse_brick_name(folder, f) for f in changed_files if folder in f.as_posix()}


def _get_changed_bricks(root: Path, top_dir: str, changed_files: List[Path]) -> list:
namespace = workspace.parser.get_namespace_from_config(root)
def _get_changed_bricks(
root: Path, top_dir: str, changed_files: List[Path], namespace: str
) -> list:
d = f"{top_dir}/{namespace}"

return sorted(_get_changed(d, changed_files))


def get_changed_components(root: Path, changed_files: List[Path]) -> list:
return _get_changed_bricks(root, repo.components_dir, changed_files)
def get_changed_components(
root: Path, changed_files: List[Path], namespace: str
) -> list:
return _get_changed_bricks(root, repo.components_dir, changed_files, namespace)


def get_changed_bases(root: Path, changed_files: List[Path]) -> list:
return _get_changed_bricks(root, repo.bases_dir, changed_files)
def get_changed_bases(root: Path, changed_files: List[Path], namespace: str) -> list:
return _get_changed_bricks(root, repo.bases_dir, changed_files, namespace)


def get_changed_projects(changed_files: List[Path]) -> list:
Expand Down
4 changes: 4 additions & 0 deletions components/polylith/diff/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def brick_status(brick, bricks) -> str:
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=info_theme)
table = Table(box=box.SIMPLE_HEAD)
table.add_column("[data]changed brick[/]")
Expand Down
4 changes: 3 additions & 1 deletion components/polylith/info/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from polylith.info.collect import get_bricks_in_projects
from polylith.info.collect import get_bases, get_bricks_in_projects, get_components
from polylith.info.report import print_bricks_in_projects, print_workspace_summary

__all__ = [
"get_bases",
"get_bricks_in_projects",
"get_components",
"print_bricks_in_projects",
"print_workspace_summary",
]
16 changes: 10 additions & 6 deletions components/polylith/info/collect.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path
from typing import List

from polylith import workspace
from polylith.bricks import base, component
from polylith.project import get_packages_for_projects, parse_package_paths

Expand All @@ -25,13 +24,18 @@ def get_project_bricks(project_packages: List[dict], components, bases, namespac
return {"components": components_in_project, "bases": bases_in_project}


def get_bricks_in_projects(root: Path) -> List[dict]:
namespace = workspace.parser.get_namespace_from_config(root)
def get_components(root: Path, namespace: str) -> List[str]:
return [c["name"] for c in component.get_components_data(root, namespace)]

packages_for_projects = get_packages_for_projects(root)

components = [c["name"] for c in component.get_components_data(root, namespace)]
bases = [b["name"] for b in base.get_bases_data(root, namespace)]
def get_bases(root: Path, namespace: str) -> List[str]:
return [b["name"] for b in base.get_bases_data(root, namespace)]


def get_bricks_in_projects(
root: Path, components: List[str], bases: List[str], namespace: str
) -> List[dict]:
packages_for_projects = get_packages_for_projects(root)

res = [
{
Expand Down
19 changes: 8 additions & 11 deletions components/polylith/info/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def brick_status(brick, bricks) -> str:


def print_bricks_in_projects(
projects_data: List[dict], bases_data: List[dict], components_data: List[dict]
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:
if not components_data and not bases_data:
if not components and not bases:
return

console = Console(theme=info_theme)
Expand All @@ -36,30 +36,27 @@ def print_bricks_in_projects(
proj_cols = [f"[proj]{project['name']}[/]" for project in projects_data]
table.add_column(Columns(proj_cols, align="center", expand=True))

components = sorted((c["name"] for c in components_data))
bases = sorted((b["name"] for b in bases_data))

for brick in components:
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 bases:
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))

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


def print_workspace_summary(
projects_data: List[dict], bases_data: List[dict], components_data: List[dict]
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:
console = Console(theme=info_theme)

console.print(Padding("[data]Workspace summary[/]", (1, 0, 1, 0)))

number_of_projects = len(projects_data) if projects_data else 0
number_of_components = len(components_data) if components_data else 0
number_of_bases = len(bases_data) if bases_data else 0
number_of_projects = len(projects_data)
number_of_components = len(components)
number_of_bases = len(bases)

console.print(f"[proj]projects[/]: [data]{number_of_projects}[/]")
console.print(f"[comp]components[/]: [data]{number_of_components}[/]")
Expand Down
9 changes: 5 additions & 4 deletions components/polylith/poetry/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from cleo.helpers import option
from poetry.console.commands.command import Command
from polylith import diff, info, repo
from polylith import diff, info, repo, workspace


class DiffCommand(Command):
Expand Down Expand Up @@ -30,11 +30,12 @@ def handle(self) -> int:
if not tag:
self.line("No tags found in repository.")
else:
ns = workspace.parser.get_namespace_from_config(root)
files = diff.collect.get_files(tag)
bases = diff.collect.get_changed_bases(root, files)
components = diff.collect.get_changed_components(root, files)
bases = diff.collect.get_changed_bases(root, files, ns)
components = diff.collect.get_changed_components(root, files, ns)
projects = diff.collect.get_changed_projects(files)
projects_data = info.get_bricks_in_projects(root)
projects_data = info.get_bricks_in_projects(root, components, bases, ns)

short = self.option("short")

Expand Down
11 changes: 5 additions & 6 deletions components/polylith/poetry/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from poetry.console.commands.command import Command
from polylith import info, repo, workspace
from polylith.bricks import base, component


class InfoCommand(Command):
Expand All @@ -17,11 +16,11 @@ def handle(self) -> int:
)

ns = workspace.parser.get_namespace_from_config(root)
bases_data = base.get_bases_data(root, ns)
components_data = component.get_components_data(root, ns)
projects_data = info.get_bricks_in_projects(root)
bases = info.get_bases(root, ns)
components = info.get_components(root, ns)
projects_data = info.get_bricks_in_projects(root, components, bases, ns)

info.print_workspace_summary(projects_data, bases_data, components_data)
info.print_bricks_in_projects(projects_data, bases_data, components_data)
info.print_workspace_summary(projects_data, bases, components)
info.print_bricks_in_projects(projects_data, bases, components)

return 0