File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 638638 "library/threadsafety.rst" : "builtins/threadsafety.rst" ,
639639 "library/time-complexity.rst" : "builtins/time-complexity.rst" ,
640640}
641+
642+ # Refuse to run the doctest builder under a mismatched Python
643+ # -----------------------------------------------------------
644+
645+
646+ def _check_doctest_interpreter (app ):
647+ # The doctests are executed by the interpreter running Sphinx,
648+ # so refuse to run them if its version doesn't match the source tree.
649+ if app .builder .name != "doctest" :
650+ return
651+
652+ running_version = f"{ sys .version_info .major } .{ sys .version_info .minor } "
653+ if running_version != version :
654+ from sphinx .util import logging as sphinx_logging
655+
656+ logger = sphinx_logging .getLogger (__name__ )
657+ logger .error (
658+ "The doctests are executed by the Python running Sphinx, "
659+ "which is Python %s, however this source tree is Python %s, "
660+ "so they would test Python %s rather than the code "
661+ "documented here.\n "
662+ "Recreate the venv with a matching interpreter, for example: "
663+ "'make clean-venv && make venv PYTHON=../python'." ,
664+ running_version ,
665+ version ,
666+ running_version ,
667+ )
668+ raise SystemExit (1 )
669+
670+
671+ def setup (app ):
672+ app .connect ("builder-inited" , _check_doctest_interpreter )
673+ return {
674+ "version" : "1.0" ,
675+ "parallel_read_safe" : True ,
676+ "parallel_write_safe" : True ,
677+ }
You can’t perform that action at this time.
0 commit comments