diff options
author | Martin Fischer <martin@push-f.com> | 2022-02-27 06:38:50 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-02-27 06:39:14 +0100 |
commit | 4e2ba920f748a7ba7dd25b146bc9880cbae71a4e (patch) | |
tree | 75d8c7d6fdbbf9566c2a446e5ccfc3ba9d5bec01 /check_checkers.py | |
parent | e2a8648fa82d1f3199e257eb7b241267d10c1c80 (diff) |
improve checker caching: file hash instead of mtime
Diffstat (limited to 'check_checkers.py')
-rwxr-xr-x | check_checkers.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/check_checkers.py b/check_checkers.py index e46bb12..4b78509 100755 --- a/check_checkers.py +++ b/check_checkers.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import hashlib import html import json import os @@ -153,7 +154,7 @@ class PyrightStrict(Pyright): class Puzzle(TypedDict): checker_results: Dict[str, List[Error]] - last_modified: int + puzzle_hash: str def run_checkers(checkers: List[Checker], puzzle: str, typeshed_path: str): @@ -225,13 +226,16 @@ def run( for puzzle in puzzles: print(puzzle) - last_modified = int(os.stat(puzzle).st_mtime) - if puzzle in cache and last_modified == cache[puzzle]['last_modified']: + with open(puzzle, 'rb') as f: + 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'] else: checker_results = run_checkers(checkers, puzzle, default_typeshed) cache[puzzle] = { - 'last_modified': last_modified, + 'puzzle_hash': puzzle_hash, 'checker_results': checker_results, } @@ -241,8 +245,7 @@ def run( .replace('_', '-') ) out.write('<tr><td id="{0}"><a href="#{0}">{0}</a>'.format(anchor)) - with open(puzzle) as f: - code = f.read() + code = code.decode('utf-8') out.write(highlight(code, python_lexer, html_formatter)) error_ok = '# error' in code or '# maybe error' in code no_error_ok = '# error' not in code |