https://github.com/python/cpython/commit/5bbf4fad6d539f84659671ecc52ee13916d5a703 commit: 5bbf4fad6d539f84659671ecc52ee13916d5a703 branch: main author: Stan Ulbrych <[email protected]> committer: StanFromIreland <[email protected]> date: 2026-09-19T16:23:54+01:00 summary:
gh-95779: Refuse to run `make doctest` under a mismatched Python (#156203) Co-authored-by: Hugo van Kemenade <[email protected]> files: M Doc/conf.py diff --git a/Doc/conf.py b/Doc/conf.py index 084906ac17cf94..1666f7b3b435cd 100644 --- a/Doc/conf.py +++ b/Doc/conf.py @@ -636,3 +636,40 @@ "library/threadsafety.rst": "builtins/threadsafety.rst", "library/time-complexity.rst": "builtins/time-complexity.rst", } + +# Refuse to run the doctest builder under a mismatched Python +# ----------------------------------------------------------- + + +def _check_doctest_interpreter(app): + # The doctests are executed by the interpreter running Sphinx, + # so refuse to run them if its version doesn't match the source tree. + if app.builder.name != "doctest": + return + + running_version = f"{sys.version_info.major}.{sys.version_info.minor}" + if running_version != version: + from sphinx.util import logging as sphinx_logging + + logger = sphinx_logging.getLogger(__name__) + logger.error( + "The doctests are executed by the Python running Sphinx, " + "which is Python %s, however this source tree is Python %s, " + "so they would test Python %s rather than the code " + "documented here.\n" + "Recreate the venv with a matching interpreter, for example: " + "'make clean-venv && make venv PYTHON=../python'.", + running_version, + version, + running_version, + ) + raise SystemExit(1) + + +def setup(app): + app.connect("builder-inited", _check_doctest_interpreter) + return { + "version": "1.0", + "parallel_read_safe": True, + "parallel_write_safe": True, + } _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
