2022-08-30 04:59:48 +00:00
|
|
|
"""Simple script for rebuilding .codespell-ignore-lines
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
cat < /dev/null > .codespell-ignore-lines
|
|
|
|
pre-commit run --all-files codespell >& /tmp/codespell_errors.txt
|
|
|
|
python3 tools/codespell_ignore_lines_from_errors.py /tmp/codespell_errors.txt > .codespell-ignore-lines
|
|
|
|
|
|
|
|
git diff to review changes, then commit, push.
|
|
|
|
"""
|
|
|
|
|
2024-06-22 04:55:00 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-08-30 04:59:48 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
2024-06-22 04:55:00 +00:00
|
|
|
def run(args: list[str]) -> None:
|
2022-08-30 04:59:48 +00:00
|
|
|
assert len(args) == 1, "codespell_errors.txt"
|
|
|
|
cache = {}
|
|
|
|
done = set()
|
2023-02-22 14:18:55 +00:00
|
|
|
with open(args[0]) as f:
|
|
|
|
lines = f.read().splitlines()
|
|
|
|
|
|
|
|
for line in sorted(lines):
|
2022-08-30 04:59:48 +00:00
|
|
|
i = line.find(" ==> ")
|
|
|
|
if i > 0:
|
|
|
|
flds = line[:i].split(":")
|
|
|
|
if len(flds) >= 2:
|
|
|
|
filename, line_num = flds[:2]
|
|
|
|
if filename not in cache:
|
2023-02-22 14:18:55 +00:00
|
|
|
with open(filename) as f:
|
|
|
|
cache[filename] = f.read().splitlines()
|
2022-08-30 04:59:48 +00:00
|
|
|
supp = cache[filename][int(line_num) - 1]
|
|
|
|
if supp not in done:
|
|
|
|
print(supp)
|
|
|
|
done.add(supp)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
run(args=sys.argv[1:])
|