From 4e2ba920f748a7ba7dd25b146bc9880cbae71a4e Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 27 Feb 2022 06:38:50 +0100 Subject: improve checker caching: file hash instead of mtime --- check_checkers.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'check_checkers.py') 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('{0}'.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 -- cgit v1.2.3