-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: a new command - poly check (#43)
* dev: project-specific mypy config * feat: a poly check command * update lock-files * feat(poly-check): bump version to 1.1.0 * docs(poly-check): add docs about the check command
- Loading branch information
1 parent
ffcd2ec
commit fec66cb
Showing
14 changed files
with
1,787 additions
and
1,336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from polylith.check import report | ||
|
||
__all__ = ["report"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[mypy-cleo.helpers.*] | ||
ignore_missing_imports = True |
Oops, something went wrong.