summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-03-02 07:03:06 +0100
committerMartin Fischer <martin@push-f.com>2022-03-02 07:03:06 +0100
commit80c24905262130fa95ff37a424998f40f094c739 (patch)
treee6bc984ab0c05a51d81750cbe09ff0cc89ab2cb7
parent7622571695e7c07064ca950bff6845f2b2ecc372 (diff)
refactor check_checkers: use pathlib.Path
-rwxr-xr-xcheck_checkers.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/check_checkers.py b/check_checkers.py
index 4b78509..769adba 100755
--- a/check_checkers.py
+++ b/check_checkers.py
@@ -9,6 +9,7 @@ from subprocess import PIPE, Popen, check_output
import tempfile
import time
from typing import Dict, List, NamedTuple, TextIO, Tuple, TypedDict
+from pathlib import Path
import mypy.api
from pygments import highlight
@@ -169,7 +170,7 @@ def run_checkers(checkers: List[Checker], puzzle: str, typeshed_path: str):
def run(
checkers: List[Checker],
- puzzles: List[str],
+ puzzles: List[Path],
default_typeshed: str,
out: TextIO,
cache: Dict[str, Puzzle],
@@ -230,20 +231,16 @@ def run(
code = f.read()
puzzle_hash = hashlib.sha256(code).hexdigest()
- if puzzle in cache and puzzle_hash == cache[puzzle]['puzzle_hash']:
- checker_results = cache[puzzle]['checker_results']
+ if str(puzzle) in cache and puzzle_hash == cache[str(puzzle)]['puzzle_hash']:
+ checker_results = cache[str(puzzle)]['checker_results']
else:
- checker_results = run_checkers(checkers, puzzle, default_typeshed)
- cache[puzzle] = {
+ checker_results = run_checkers(checkers, str(puzzle), default_typeshed)
+ cache[str(puzzle)] = {
'puzzle_hash': puzzle_hash,
'checker_results': checker_results,
}
- anchor = (
- html.escape(puzzle.rsplit('/', maxsplit=1)[1])
- .replace('.py', '')
- .replace('_', '-')
- )
+ anchor = html.escape(puzzle.name).replace('.py', '').replace('_', '-')
out.write('<tr><td id="{0}"><a href="#{0}">{0}</a>'.format(anchor))
code = code.decode('utf-8')
out.write(highlight(code, python_lexer, html_formatter))
@@ -312,7 +309,7 @@ if __name__ == '__main__':
with open('dist/checkers.html', 'w') as f:
run(
[Mypy(), MypyStrict(), Pytype(), Pyright(), PyrightStrict()],
- ['puzzles/' + f for f in sorted(os.listdir('puzzles'))],
+ list(sorted(Path('puzzles/').iterdir())),
typeshed,
f,
cache,