diff --git a/components/polylith/info/__init__.py b/components/polylith/info/__init__.py index 799c4fcd..df16b158 100644 --- a/components/polylith/info/__init__.py +++ b/components/polylith/info/__init__.py @@ -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", ] diff --git a/components/polylith/info/collect.py b/components/polylith/info/collect.py index c3514863..2967261e 100644 --- a/components/polylith/info/collect.py +++ b/components/polylith/info/collect.py @@ -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) diff --git a/components/polylith/info/report.py b/components/polylith/info/report.py index 3a17a37c..f508b07e 100644 --- a/components/polylith/info/report.py +++ b/components/polylith/info/report.py @@ -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: @@ -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): @@ -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}[/]") diff --git a/components/polylith/libs/report.py b/components/polylith/libs/report.py index e312a47d..03d59d55 100644 --- a/components/polylith/libs/report.py +++ b/components/polylith/libs/report.py @@ -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 @@ -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") diff --git a/components/polylith/poetry/commands/check.py b/components/polylith/poetry/commands/check.py index 991d64bd..89d9e93b 100644 --- a/components/polylith/poetry/commands/check.py +++ b/components/polylith/poetry/commands/check.py @@ -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 Polylith workspace." @@ -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) diff --git a/components/polylith/poetry/commands/diff.py b/components/polylith/poetry/commands/diff.py index bfc4b851..0d8aeefe 100644 --- a/components/polylith/poetry/commands/diff.py +++ b/components/polylith/poetry/commands/diff.py @@ -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") diff --git a/components/polylith/poetry/commands/libs.py b/components/polylith/poetry/commands/libs.py index 6a676264..d263a402 100644 --- a/components/polylith/poetry/commands/libs.py +++ b/components/polylith/poetry/commands/libs.py @@ -1,5 +1,5 @@ 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 @@ -7,13 +7,6 @@ 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." @@ -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: @@ -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) diff --git a/components/polylith/project/get.py b/components/polylith/project/get.py index fd42b6ae..769c54f7 100644 --- a/components/polylith/project/get.py +++ b/components/polylith/project/get.py @@ -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]: @@ -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 ] diff --git a/components/polylith/project/parser.py b/components/polylith/project/parser.py index 820b36fa..eb986586 100644 --- a/components/polylith/project/parser.py +++ b/components/polylith/project/parser.py @@ -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]