from abc import abstractmethod
from pathlib import Path
from typing import Any, Iterable, Optional
from hammurabi.mixins import GitMixin
from hammurabi.rules.base import Rule
[docs]class SinglePathRule(Rule, GitMixin):
"""
Abstract class which extends :class:`hammurabi.rules.base.Rule` to handle operations on a
single directory.
"""
def __init__(self, name: str, path: Optional[Path] = None, **kwargs) -> None:
super().__init__(name, path, **kwargs)
[docs] def post_task_hook(self):
self.git_add(self.param)
[docs] @abstractmethod
def task(self) -> Any:
"""
Abstract method representing how a :func:`hammurabi.rules.base.Rule.task`
must be parameterized. Any difference in the parameters will result in
pylint/mypy errors.
For more details please check :func:`hammurabi.rules.base.Rule.task`.
"""
[docs]class MultiplePathRule(Rule, GitMixin):
"""
Abstract class which extends :class:`hammurabi.rules.base.Rule` to handle operations on
multiple files.
"""
def __init__(
self, name: str, paths: Optional[Iterable[Path]] = (), **kwargs
) -> None:
super().__init__(name, paths, **kwargs)
[docs] def post_task_hook(self):
for path in self.param:
self.git_add(path)
[docs] @abstractmethod
def task(self) -> Any:
"""
Abstract method representing how a :func:`hammurabi.rules.base.Rule.task`
must be parameterized. Any difference in the parameters will result in
pylint/mypy errors.
For more details please check :func:`hammurabi.rules.base.Rule.task`.
"""