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
2 changes: 2 additions & 0 deletions bases/polylith/poetry_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from poetry.console.application import Application
from poetry.plugins.application_plugin import ApplicationPlugin
from polylith.poetry.commands import (
CheckCommand,
CreateBaseCommand,
CreateComponentCommand,
CreateProjectCommand,
Expand All @@ -10,6 +11,7 @@
)

commands = [
CheckCommand,
CreateBaseCommand,
CreateComponentCommand,
CreateProjectCommand,
Expand Down
3 changes: 3 additions & 0 deletions components/polylith/check/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from polylith.check import report

__all__ = ["report"]
25 changes: 25 additions & 0 deletions components/polylith/check/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import subprocess
from pathlib import Path
from typing import List


def navigate_to(path: Path):
os.chdir(str(path))


def run_command(project_path: Path) -> List[str]:
current_dir = Path.cwd()

navigate_to(project_path)

try:
res = subprocess.run(
["poetry", "check-project"], capture_output=True, text=True
)
finally:
navigate_to(current_dir)

res.check_returncode()

return res.stdout.splitlines()
33 changes: 33 additions & 0 deletions components/polylith/check/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from polylith.check.core import run_command
from rich.console import Console
from rich.theme import Theme

info_theme = Theme(
{
"data": "#999966",
"proj": "#8A2BE2",
"comp": "#32CD32",
"base": "#6495ED",
}
)


def run(project_data: dict) -> bool:
console = Console(theme=info_theme)

project_name = project_data["name"]
project_path = project_data["path"]

with console.status(f"checking [proj]{project_name}[/]", spinner="monkey"):
result = run_command(project_path)

message = ["[proj]", project_name, "[/]", " "]
extra = [":warning:"] if result else [":heavy_check_mark:"]

output = "".join(message + extra)
console.print(output)

for row in result:
console.print(f"[data]{row}[/]")

return True if not result else False
2 changes: 2 additions & 0 deletions components/polylith/poetry/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from polylith.poetry.commands.check import CheckCommand
from polylith.poetry.commands.create_base import CreateBaseCommand
from polylith.poetry.commands.create_component import CreateComponentCommand
from polylith.poetry.commands.create_project import CreateProjectCommand
Expand All @@ -6,6 +7,7 @@
from polylith.poetry.commands.info import InfoCommand

__all__ = [
"CheckCommand",
"CreateBaseCommand",
"CreateComponentCommand",
"CreateProjectCommand",
Expand Down
22 changes: 22 additions & 0 deletions components/polylith/poetry/commands/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pathlib import Path

from poetry.console.commands.command import Command
from polylith import check, project, repo


class CheckCommand(Command):
name = "poly check"
description = "Validates the <comment>Polylith</> workspace."

def handle(self) -> int:
root = repo.find_workspace_root(Path.cwd())
if not root:
raise ValueError(
"Didn't find the workspace root. Expected to find a workspace.toml file."
)

projects = project.get_project_names_and_paths(root)

res = [check.report.run(proj) for proj in projects]

return 0 if all(res) else 1
7 changes: 6 additions & 1 deletion components/polylith/project/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from polylith.project.create import create_project
from polylith.project.get import get_packages_for_projects, get_project_names
from polylith.project.get import (
get_packages_for_projects,
get_project_names,
get_project_names_and_paths,
)
from polylith.project.parser import parse_package_paths

__all__ = [
"create_project",
"get_project_names",
"get_project_names_and_paths",
"get_packages_for_projects",
"parse_package_paths",
]
8 changes: 8 additions & 0 deletions components/polylith/project/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ def get_packages_for_projects(root: Path) -> List[dict]:
{"name": get_project_name(d), "packages": get_project_package_includes(d)}
for d in tomls
]


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

return [
{"name": get_project_name(get_toml(p)), "path": p.parent} for p in project_files
]
1,443 changes: 775 additions & 668 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions projects/poetry_polylith_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Show info about the workspace:
poetry poly info
```

#### Diff
Shows what has changed since the most recent stable point in time:

``` shell
Expand All @@ -91,6 +92,16 @@ Useful for CI:
poetry poly diff --short
```

#### Check
Validates the Polylith workspace:

``` shell
poetry poly check
```

**NOTE**: this feature is built on top of the `poetry check-project` command from the [Multiproject](https://github.com/DavidVujic/poetry-multiproject-plugin) plugin.
Make sure that you have the latest version of poetry-multiproject-plugin installed to be able to use the `poly check` command.

#### Testing
The `create` commands will also create corresponding unit tests. It is possible to disable thi behaviour
by setting `enabled = false` in the `workspace.toml` file.
Expand Down
2 changes: 2 additions & 0 deletions projects/poetry_polylith_plugin/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy-cleo.helpers.*]
ignore_missing_imports = True
Loading