Skip to content

Commit

Permalink
libs: Add envoy.code.check[spelling]
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Northey <[email protected]>
  • Loading branch information
phlax committed Feb 7, 2022
1 parent 816be6a commit 6cab0cc
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions envoy.code.check/envoy/code/check/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pytooling_library(
"abstract/base.py",
"abstract/checker.py",
"abstract/flake8.py",
"abstract/spelling.py",
"abstract/yapf.py",
"checker.py",
"cmd.py",
Expand Down
3 changes: 3 additions & 0 deletions envoy.code.check/envoy/code/check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
ACodeCheck,
ACodeChecker,
AFlake8Check,
ASpellingCheck,
AYapfCheck)
from .checker import (
CodeChecker,
Flake8Check,
SpellingCheck,
YapfCheck)
from .cmd import run, main
from . import checker
Expand All @@ -26,4 +28,5 @@
"main",
"run",
"typing",
"SpellingCheck",
"YapfCheck")
4 changes: 4 additions & 0 deletions envoy.code.check/envoy/code/check/abstract/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
from .base import ACodeCheck
from .checker import ACodeChecker
from .flake8 import AFlake8Check
from .spelling import ASpellingCheck
from .yapf import AYapfCheck
from . import (
base,
checker,
flake8,
spelling,
yapf)


__all__ = (
"ACodeCheck",
"ACodeChecker",
"AFlake8Check",
"ASpellingCheck",
"AYapfCheck",
"base",
"checker",
"flake8",
"spelling",
"yapf")
21 changes: 20 additions & 1 deletion envoy.code.check/envoy/code/check/abstract/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ACodeChecker(
metaclass=abstracts.Abstraction):
"""Code checker."""

checks = ("python_yapf", "python_flake8")
checks = ("python_yapf", "python_flake8", "spelling")

@property
def all_files(self) -> bool:
Expand Down Expand Up @@ -104,6 +104,16 @@ def grep_matching_re(self) -> Optional[Pattern[str]]:
def path(self) -> pathlib.Path:
return super().path

@cached_property
def spelling(self) -> "abstract.ASpellingCheck":
"""SPELLING checker."""
return self.spelling_class(self.directory, fix=self.fix)

@property # type:ignore
@abstracts.interfacemethod
def spelling_class(self) -> Type["abstract.ASpellingCheck"]:
raise NotImplementedError

@cached_property
def yapf(self) -> "abstract.AYapfCheck":
"""YAPF checker."""
Expand All @@ -129,6 +139,10 @@ async def check_python_yapf(self) -> None:
"""Check for yapf issues."""
await self._code_check(self.yapf)

async def check_spelling(self) -> None:
"""Check for yapf issues."""
await self._code_check(self.spelling)

@checker.preload(
when=["python_flake8"])
async def preload_flake8(self) -> None:
Expand All @@ -139,6 +153,11 @@ async def preload_flake8(self) -> None:
async def preload_yapf(self) -> None:
await self.yapf.problem_files

@checker.preload(
when=["spelling"])
async def preload_spelling(self) -> None:
await self.spelling.problem_files

async def _code_check(self, check: "abstract.ACodeCheck") -> None:
problem_files = await check.problem_files
for path in sorted(await check.files):
Expand Down
29 changes: 29 additions & 0 deletions envoy.code.check/envoy/code/check/abstract/spelling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pathlib
import re
import sys
from functools import cached_property
from typing import Dict, Iterator, List, Pattern, Set, Tuple

import abstracts

from envoy.code.check import abstract

from aio.core.functional import async_property


class ASpellingCheck(abstract.ACodeCheck, metaclass=abstracts.Abstraction):

@async_property
async def checker_files(self) -> Set[str]:
return set()

@async_property(cache=True)
async def problem_files(self) -> Dict[str, List[str]]:
return (
dict(await self.errors)
if await self.files
else {})

@async_property
async def errors(self):
return {}
9 changes: 9 additions & 0 deletions envoy.code.check/envoy/code/check/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class YapfCheck:
pass


@abstracts.implementer(check.ASpellingCheck)
class SpellingCheck:
pass


@abstracts.implementer(check.ACodeChecker)
class CodeChecker:

Expand All @@ -38,6 +43,10 @@ def git_directory_class(self):
def path(self) -> pathlib.Path:
return super().path

@property
def spelling_class(self):
return SpellingCheck

@property
def yapf_class(self):
return YapfCheck

0 comments on commit 6cab0cc

Please sign in to comment.