Skip to content

Commit

Permalink
Fix readthedocs build (#15437)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and hauntsaninja committed Jun 24, 2023
1 parent 9b327d1 commit 16fe5da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions 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
Expand All @@ -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:
Expand All @@ -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",
Expand All @@ -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"""
<html>
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Expand Up @@ -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}
Expand Down

0 comments on commit 16fe5da

Please sign in to comment.