|
2 | 2 | from dataclasses import dataclass
|
3 | 3 | from os.path import splitext
|
4 | 4 |
|
5 |
| -from sphinxlint.utils import hide_non_rst_blocks, po2rst |
| 5 | +from sphinxlint.utils import PER_FILE_CACHES, hide_non_rst_blocks, po2rst |
6 | 6 |
|
7 | 7 |
|
8 | 8 | @dataclass(frozen=True)
|
@@ -50,16 +50,20 @@ def check_text(filename, text, checkers, options=None):
|
50 | 50 |
|
51 | 51 |
|
52 | 52 | def check_file(filename, checkers, options: CheckersOptions = None):
|
53 |
| - ext = splitext(filename)[1] |
54 |
| - if not any(ext in checker.suffixes for checker in checkers): |
55 |
| - return Counter() |
56 | 53 | try:
|
57 |
| - with open(filename, encoding="utf-8") as f: |
58 |
| - text = f.read() |
59 |
| - if filename.endswith(".po"): |
60 |
| - text = po2rst(text) |
61 |
| - except OSError as err: |
62 |
| - return [f"{filename}: cannot open: {err}"] |
63 |
| - except UnicodeDecodeError as err: |
64 |
| - return [f"{filename}: cannot decode as UTF-8: {err}"] |
65 |
| - return check_text(filename, text, checkers, options) |
| 54 | + ext = splitext(filename)[1] |
| 55 | + if not any(ext in checker.suffixes for checker in checkers): |
| 56 | + return Counter() |
| 57 | + try: |
| 58 | + with open(filename, encoding="utf-8") as f: |
| 59 | + text = f.read() |
| 60 | + if filename.endswith(".po"): |
| 61 | + text = po2rst(text) |
| 62 | + except OSError as err: |
| 63 | + return [f"{filename}: cannot open: {err}"] |
| 64 | + except UnicodeDecodeError as err: |
| 65 | + return [f"{filename}: cannot decode as UTF-8: {err}"] |
| 66 | + return check_text(filename, text, checkers, options) |
| 67 | + finally: |
| 68 | + for memoized_function in PER_FILE_CACHES: |
| 69 | + memoized_function.cache_clear() |
0 commit comments