diff options
author | Martin Fischer <martin@push-f.com> | 2022-03-02 07:13:19 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-03-02 07:13:19 +0100 |
commit | 060bf54f3cce2b72f7bc0a951a0dc6ab02b18f14 (patch) | |
tree | d341d06cd13d30308333d4c9c2f67678a742bfbe | |
parent | 80c24905262130fa95ff37a424998f40f094c739 (diff) |
-rwxr-xr-x | check_checkers.py | 37 | ||||
-rw-r--r-- | puzzles/mod_relative_import/__init__.py | 3 | ||||
-rw-r--r-- | puzzles/mod_relative_import/foo.py | 1 |
3 files changed, 33 insertions, 8 deletions
diff --git a/check_checkers.py b/check_checkers.py index 769adba..42415f0 100755 --- a/check_checkers.py +++ b/check_checkers.py @@ -227,10 +227,20 @@ def run( for puzzle in puzzles: print(puzzle) - with open(puzzle, 'rb') as f: - code = f.read() - puzzle_hash = hashlib.sha256(code).hexdigest() + codes: Dict[str, bytes] = {} + + if puzzle.is_dir(): + for file in sorted(puzzle.iterdir()): + with file.open('rb') as f: + codes[file.name] = f.read() + else: + with puzzle.open('rb') as f: + codes[puzzle.name] = f.read() + + puzzle_hash = '-'.join( + hashlib.sha256(code).hexdigest() for code in codes.values() + ) if str(puzzle) in cache and puzzle_hash == cache[str(puzzle)]['puzzle_hash']: checker_results = cache[str(puzzle)]['checker_results'] else: @@ -241,11 +251,22 @@ def run( } 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)) - error_ok = '# error' in code or '# maybe error' in code - no_error_ok = '# error' not in code + out.write('<tr><td id="{0}"><a href="#{0}">{0}</a><br>'.format(anchor)) + + error_ok = False + no_error_ok = True + + for fname, code in codes.items(): + code = code.decode('utf-8') + if len(codes) > 1: + out.write(html.escape(fname)) + out.write(highlight(code, python_lexer, html_formatter)) + + if '# error' in code: + error_ok = True + no_error_ok = False + elif '# maybe error' in code: + error_ok = True results = [ (checker, checker_results[checker.__class__.__name__]) diff --git a/puzzles/mod_relative_import/__init__.py b/puzzles/mod_relative_import/__init__.py new file mode 100644 index 0000000..ff97bdb --- /dev/null +++ b/puzzles/mod_relative_import/__init__.py @@ -0,0 +1,3 @@ +from .foo import x + +print(foo.x + x) diff --git a/puzzles/mod_relative_import/foo.py b/puzzles/mod_relative_import/foo.py new file mode 100644 index 0000000..b95c23a --- /dev/null +++ b/puzzles/mod_relative_import/foo.py @@ -0,0 +1 @@ +x = 3 |