Skip to content

Commit

Permalink
Add codespell checker
Browse files Browse the repository at this point in the history
Check both files and commits.
  • Loading branch information
igo95862 committed Jun 9, 2024
1 parent e602875 commit 42e3c4a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
python-pyflakes reuse
mypy python-pyqt6 python-tomli-w
python-black python-isort
codespell
- name: Checkout
uses: actions/checkout@v4
- name: Add safe git directory
Expand Down
2 changes: 1 addition & 1 deletion src/bubblejail/bubblejail_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ async def client_handler(self, reader: StreamReader, writer: StreamWriter) -> No
line = await reader.readline()
if not line:
if __debug__:
print("Reached end of reader. Returnning", flush=True)
print("Reached end of reader. Returning", flush=True)
writer.close()
await writer.wait_closed()
return
Expand Down
2 changes: 1 addition & 1 deletion src/bubblejail/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ class Settings:
outbound_addr: str = field(
default="",
metadata=SettingFieldMetadata(
pretty_name="Outbound address or deivce",
pretty_name="Outbound address or device",
description=(
"Address or device to bind to. "
"If not set the default address would be used."
Expand Down
59 changes: 58 additions & 1 deletion tools/run_linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from pathlib import Path
from subprocess import CalledProcessError, run
from subprocess import PIPE, CalledProcessError, Popen, run
from sys import stderr

from .base import BUILD_DIR, PROJECT_ROOT_PATH, PYTHON_SOURCES
Expand Down Expand Up @@ -71,6 +71,61 @@ def run_isort() -> bool:
return False


def run_codespell() -> bool:
print("Running: codespell", file=stderr)
try:
list_of_files = run(
args=("git", "ls-files", "-z"),
cwd=PROJECT_ROOT_PATH,
stdout=PIPE,
text=True,
check=True,
).stdout.split("\0")
run(
args=[
"codespell",
"--check-filenames",
"--enable-colors",
"--context",
"3",
*list_of_files,
],
check=True,
)
except CalledProcessError:
return True

return False


def run_codespell_on_commits() -> bool:
print("Running: git log to codespell", file=stderr)
try:
git_log = Popen(
args=(
"git",
"log",
"--max-count=50",
"--no-merges",
r"--format='%H%n%n%s%n%n%b'",
),
cwd=PROJECT_ROOT_PATH,
stdout=PIPE,
)

run(
args=("codespell", "--enable-colors", "--context", "3", "-"),
cwd=PROJECT_ROOT_PATH,
check=True,
stdin=git_log.stdout,
timeout=5,
)
except CalledProcessError:
return True

return bool(git_log.wait(3))


def main() -> None:
BUILD_DIR.mkdir(exist_ok=True)

Expand All @@ -81,6 +136,8 @@ def main() -> None:
has_failed |= run_reuse()
has_failed |= run_black()
has_failed |= run_isort()
has_failed |= run_codespell()
has_failed |= run_codespell_on_commits()

if has_failed:
raise SystemExit(1)
Expand Down

0 comments on commit 42e3c4a

Please sign in to comment.