feat: add presets

This commit is contained in:
2023-03-16 15:07:11 +03:00
parent 23ca8c0cac
commit 8b718fda79
15 changed files with 357 additions and 142 deletions
+8 -9
View File
@@ -4,10 +4,8 @@ from pathlib import Path
from typing import Dict, Iterable
from .command import CommandError
from .entries.nodejs import NodejsEntry
from .entries.python import PythonEntry
from .entry import Entry, EntryCommandNotImplementedError
from .resolver import EntryDetector, EntryResolver
from .entry import Entry, EntryResolver, EntryTaskNotImplementedError
from .preset.entry import PresetEntryDetector
__all__ = ("ProjectManager",)
@@ -20,20 +18,21 @@ class ProjectManager:
def __init__(self, basepath: Path):
self._basepaht = basepath
self._resolver = EntryResolver(
EntryDetector(PythonEntry, NodejsEntry), ["node_modules", ".venv", ".git"]
PresetEntryDetector(Path(__file__).parent / "default_preset.toml"),
["node_modules", ".venv", ".git"],
)
def _iter_entries(self) -> Iterable[Entry]:
return self._resolver.resolve(self._basepaht)
def run_command(self, command_name: str) -> Dict[str, int]:
def run_task(self, task_name: str) -> Dict[str, int]:
counter = Counter()
for entry in self._iter_entries():
try:
entry.run_command(command_name)
entry.run_task(task_name)
counter["success"] += 1
except EntryCommandNotImplementedError:
self._logger.warn(f"{command_name} {entry}")
except EntryTaskNotImplementedError:
self._logger.warn(f"{task_name} {entry}")
counter["skipped"] += 1
except CommandError as error:
self._logger.error(f"{entry}\n{error.output}")