From 16fe5da0bd9be4d0669f00a47d260894c988cf87 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 14 Jun 2023 16:18:09 +0100 Subject: [PATCH] Fix readthedocs build (#15437) I initially included an error (removed allowlisted error code that is not covered), to verify it will be caught. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/docs.yml | 1 + docs/source/html_builder.py | 11 ++++++++--- tox.ini | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8851f7fbb0f3..3e06b5e909f1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -20,6 +20,7 @@ jobs: env: TOXENV: docs TOX_SKIP_MISSING_INTERPRETERS: False + VERIFY_MYPY_ERROR_CODES: 1 steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 diff --git a/docs/source/html_builder.py b/docs/source/html_builder.py index efe1fcaa48fa..405b80ac53d2 100644 --- a/docs/source/html_builder.py +++ b/docs/source/html_builder.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +import os import textwrap from pathlib import Path from typing import Any @@ -9,8 +10,6 @@ from sphinx.application import Sphinx from sphinx.builders.html import StandaloneHTMLBuilder -from mypy.errorcodes import error_codes - class MypyHTMLBuilder(StandaloneHTMLBuilder): def __init__(self, app: Sphinx) -> None: @@ -21,7 +20,9 @@ def write_doc(self, docname: str, doctree: document) -> None: super().write_doc(docname, doctree) self._ref_to_doc.update({_id: docname for _id in doctree.ids}) - def _write_ref_redirector(self) -> None: + def _verify_error_codes(self) -> None: + from mypy.errorcodes import error_codes + known_missing = { # TODO: fix these before next release "annotation-unchecked", @@ -39,6 +40,10 @@ def _write_ref_redirector(self) -> None: raise ValueError( f"Some error codes are not documented: {', '.join(sorted(missing_error_codes))}" ) + + def _write_ref_redirector(self) -> None: + if os.getenv("VERIFY_MYPY_ERROR_CODES"): + self._verify_error_codes() p = Path(self.outdir) / "_refs.html" data = f""" diff --git a/tox.ini b/tox.ini index 6d64cebaec6d..2ddda8281beb 100644 --- a/tox.ini +++ b/tox.ini @@ -33,6 +33,8 @@ commands = [testenv:docs] description = invoke sphinx-build to build the HTML docs +passenv = + VERIFY_MYPY_ERROR_CODES deps = -rdocs/requirements-docs.txt commands = sphinx-build -d "{toxworkdir}/docs_doctree" docs/source "{toxworkdir}/docs_out" --color -W -bhtml {posargs}