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
15 changes: 13 additions & 2 deletions components/polylith/info/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
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
from polylith.info.collect import (
get_bases,
get_bricks_in_projects,
get_components,
get_projects_data,
)
from polylith.info.report import (
is_project,
print_bricks_in_projects,
print_workspace_summary,
)

__all__ = [
"get_bases",
"get_bricks_in_projects",
"get_components",
"get_projects_data",
"is_project",
"print_bricks_in_projects",
"print_workspace_summary",
]
9 changes: 8 additions & 1 deletion components/polylith/info/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ def get_bricks_in_projects(

res = [
{
**{"name": p["name"], "path": p["path"]},
**{"name": p["name"], "path": p["path"], "type": p["type"]},
**get_project_bricks(p["packages"], components, bases, namespace),
}
for p in packages_for_projects
]

return res


def get_projects_data(root: Path, ns: str) -> List[dict]:
bases = get_bases(root, ns)
components = get_components(root, ns)

return get_bricks_in_projects(root, components, bases, ns)
19 changes: 17 additions & 2 deletions components/polylith/info/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ def brick_status(brick, bricks) -> str:
return f"[data]{status}[/]"


def is_project(project: dict) -> bool:
return project["type"] == "project"


def printable_name(project: dict) -> str:
name = project["name"]

if is_project(project):
return f"[proj]{name}[/]"

return "[data]development[/]"


def print_bricks_in_projects(
projects_data: List[dict], bases: List[str], components: List[str]
) -> None:
Expand All @@ -33,7 +46,7 @@ def print_bricks_in_projects(
table = Table(box=box.SIMPLE_HEAD)
table.add_column("[data]brick[/]")

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

for brick in sorted(components):
Expand All @@ -54,10 +67,12 @@ def print_workspace_summary(

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

number_of_projects = len(projects_data)
number_of_projects = len([p for p in projects_data if is_project(p)])
number_of_components = len(components)
number_of_bases = len(bases)
number_of_dev = len([p for p in projects_data if not is_project(p)])

console.print(f"[proj]projects[/]: [data]{number_of_projects}[/]")
console.print(f"[comp]components[/]: [data]{number_of_components}[/]")
console.print(f"[base]bases[/]: [data]{number_of_bases}[/]")
console.print(f"[data]development[/]: [data]{number_of_dev}[/]")
10 changes: 7 additions & 3 deletions components/polylith/libs/report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from typing import Set

from polylith import workspace
from polylith import info, workspace
from polylith.libs import grouping
from rich import box
from rich.console import Console
Expand Down Expand Up @@ -45,11 +45,15 @@ def calculate_diff(brick_imports: dict, deps: Set[str]) -> Set[str]:
return set().union(bases_imports, components_imports).difference(normalized_deps)


def print_libs_summary(brick_imports: dict, project_name: str) -> None:
def print_libs_summary(brick_imports: dict, project_data: dict) -> None:
console = Console(theme=info_theme)

name = project_data["name"]
is_project = info.is_project(project_data)

printable_name = f"[proj]{name}[/]" if is_project else "[data]development[/]"
console.print(
Padding(f"[data]Libraries summary for [/][proj]{project_name}[/]", (1, 0, 1, 0))
Padding(f"[data]Libraries summary for [/]{printable_name}", (1, 0, 1, 0))
)

bases_imports = flatten_imports(brick_imports, "bases")
Expand Down
12 changes: 3 additions & 9 deletions components/polylith/poetry/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
from pathlib import Path
from typing import List, Set, Union
from typing import Set, Union

from poetry.console.commands.command import Command
from poetry.factory import Factory
from polylith import check, info, project, repo, workspace


def get_projects_data(root: Path, ns: str) -> List[dict]:
bases = info.get_bases(root, ns)
components = info.get_components(root, ns)

return info.get_bricks_in_projects(root, components, bases, ns)


class CheckCommand(Command):
name = "poly check"
description = "Validates the <comment>Polylith</> workspace."
Expand Down Expand Up @@ -48,7 +41,8 @@ def handle(self) -> int:

ns = workspace.parser.get_namespace_from_config(root)

projects_data = get_projects_data(root, ns)
all_projects_data = info.get_projects_data(root, ns)
projects_data = [p for p in all_projects_data if info.is_project(p)]

if self.option("directory"):
project_name = project.get_project_name(self.poetry.pyproject.data)
Expand Down
3 changes: 2 additions & 1 deletion components/polylith/poetry/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def handle(self) -> int:
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, components, bases, ns)
all_projects_data = info.get_bricks_in_projects(root, components, bases, ns)
projects_data = [p for p in all_projects_data if info.is_project(p)]

short = self.option("short")

Expand Down
13 changes: 3 additions & 10 deletions components/polylith/poetry/commands/libs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
from pathlib import Path
from typing import List, Set, Union
from typing import Set, Union

from poetry.console.commands.command import Command
from poetry.factory import Factory
from polylith import info, project, repo, workspace
from polylith.libs import report


def get_projects_data(root: Path, ns: str) -> List[dict]:
bases = info.get_bases(root, ns)
components = info.get_components(root, ns)

return info.get_bricks_in_projects(root, components, bases, ns)


class LibsCommand(Command):
name = "poly libs"
description = "Show third-party libraries used in the workspace."
Expand All @@ -34,7 +27,7 @@ def print_report(self, root: Path, ns: str, data: dict) -> bool:

brick_imports = report.get_third_party_imports(root, ns, data)

report.print_libs_summary(brick_imports, name)
report.print_libs_summary(brick_imports, data)
report.print_libs_in_bricks(brick_imports)

try:
Expand All @@ -57,7 +50,7 @@ def handle(self) -> int:

ns = workspace.parser.get_namespace_from_config(root)

projects_data = get_projects_data(root, ns)
projects_data = info.get_projects_data(root, ns)

if self.option("directory"):
project_name = project.get_project_name(self.poetry.pyproject.data)
Expand Down
20 changes: 17 additions & 3 deletions components/polylith/project/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,27 @@ def get_toml(root: Path) -> tomlkit.TOMLDocument:
return tomlkit.loads(f.read())


def get_project_files(root: Path) -> List[Path]:
return sorted(root.glob(f"projects/**/{default_toml}"))
def get_project_files(root: Path) -> dict:
projects = sorted(root.glob(f"projects/**/{default_toml}"))
development = Path(root / default_toml)

proj = {"projects": projects}
dev = {"development": [development]}

return {**proj, **dev}


def toml_data(path: Path, project_type: str) -> dict:
return {"toml": get_toml(path), "path": path.parent, "type": project_type}


def get_toml_files(root: Path) -> List[dict]:
project_files = get_project_files(root)

return [{"toml": get_toml(p), "path": p.parent} for p in project_files]
proj = [toml_data(p, "project") for p in project_files["projects"]]
dev = [toml_data(d, "development") for d in project_files["development"]]

return proj + dev


def get_packages_for_projects(root: Path) -> List[dict]:
Expand All @@ -36,6 +49,7 @@ def get_packages_for_projects(root: Path) -> List[dict]:
"name": get_project_name(d["toml"]),
"packages": get_project_package_includes(d["toml"]),
"path": d["path"],
"type": d["type"],
}
for d in tomls
]
2 changes: 1 addition & 1 deletion components/polylith/project/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def to_path(package: dict) -> Path:


def parse_package_paths(packages: List[dict]) -> List[Path]:
sorted_packages = sorted(packages, key=lambda p: (p["from"], p["include"]))
sorted_packages = sorted(packages, key=lambda p: (p.get("from", "."), p["include"]))

return [to_path(p) for p in sorted_packages]