|
11 | 11 | from sphinx.builders.html import StandaloneHTMLBuilder |
12 | 12 | from sphinx.environment import BuildEnvironment |
13 | 13 |
|
| 14 | +from mypy.main import define_options |
| 15 | + |
14 | 16 |
|
15 | 17 | class MypyHTMLBuilder(StandaloneHTMLBuilder): |
| 18 | + strict_file: Path |
| 19 | + |
16 | 20 | def __init__(self, app: Sphinx, env: BuildEnvironment) -> None: |
17 | 21 | super().__init__(app, env) |
18 | 22 | self._ref_to_doc = {} |
| 23 | + self.strict_file = Path(self.srcdir) / "strict_list.rst" |
| 24 | + self._add_strict_list() |
19 | 25 |
|
20 | 26 | def write_doc(self, docname: str, doctree: document) -> None: |
21 | 27 | super().write_doc(docname, doctree) |
22 | 28 | self._ref_to_doc.update({_id: docname for _id in doctree.ids}) |
23 | 29 |
|
| 30 | + def _add_strict_list(self) -> None: |
| 31 | + strict_flags: list[str] |
| 32 | + _, strict_flags, _ = define_options() |
| 33 | + strict_part = ", ".join(f":option:`{s} <mypy {s}>`" for s in strict_flags) |
| 34 | + if ( |
| 35 | + not strict_part |
| 36 | + or strict_part.isspace() |
| 37 | + or len(strict_part) < 20 |
| 38 | + or len(strict_part) > 2000 |
| 39 | + ): |
| 40 | + raise ValueError(f"{strict_part=}, which doesn't look right (by a simple heuristic).") |
| 41 | + self.strict_file.write_text( |
| 42 | + "For this version of mypy, the list of flags enabled by strict is: " + strict_part |
| 43 | + ) |
| 44 | + |
24 | 45 | def _verify_error_codes(self) -> None: |
25 | 46 | from mypy.errorcodes import error_codes |
26 | 47 |
|
@@ -55,6 +76,7 @@ def _write_ref_redirector(self) -> None: |
55 | 76 | def finish(self) -> None: |
56 | 77 | super().finish() |
57 | 78 | self._write_ref_redirector() |
| 79 | + self.strict_file.unlink() |
58 | 80 |
|
59 | 81 |
|
60 | 82 | def setup(app: Sphinx) -> dict[str, Any]: |
|
0 commit comments