Skip to content

Commit 4ad84cb

Browse files
Refuse to run make doctest under a mismatched Python
1 parent 999a046 commit 4ad84cb

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Doc/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ coverage: build
132132
.PHONY: doctest
133133
doctest: BUILDER = doctest
134134
doctest:
135+
@venv_version=$$($(VENVDIR)/bin/python3 -c 'import sys; print("%d.%d" % sys.version_info[:2])'); \
136+
tree_version=$$($(PYTHON) tools/extensions/patchlevel.py --short); \
137+
if [ "$$venv_version" != "$$tree_version" ]; then \
138+
echo "The venv runs Python $$venv_version, but this source tree is Python $$tree_version."; \
139+
echo "The doctests are executed by the venv interpreter, so they would test"; \
140+
echo "Python $$venv_version rather than the code documented here."; \
141+
exit 1; \
142+
fi
135143
@$(MAKE) build BUILDER=$(BUILDER) || { \
136144
echo "Testing of doctests in the sources finished, look at the" \
137145
"results in build/doctest/output.txt"; \

Doc/make.bat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ call ..\PCbuild\find_python.bat %PYTHON%
99

1010
if not defined PYTHON set PYTHON=py
1111

12+
if "%1" NEQ "doctest" goto :skipversioncheck
13+
for /f "usebackq" %%v in (`%PYTHON% -c "import sys; print(sys.version_info[0], sys.version_info[1], sep='.')"`) do set PYVERSION=%%v
14+
for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py --short`) do set TREEVERSION=%%v
15+
if "%PYVERSION%" NEQ "%TREEVERSION%" (
16+
echo.
17+
echo.%PYTHON% is Python %PYVERSION%, but this source tree is Python %TREEVERSION%.
18+
echo.The doctests are executed by that interpreter, so they would test
19+
echo.Python %PYVERSION% rather than the code documented here.
20+
popd
21+
exit /B 1
22+
)
23+
:skipversioncheck
24+
1225
if not defined SPHINXBUILD (
1326
%PYTHON% -c "import sphinx" > nul 2> nul
1427
if errorlevel 1 (

0 commit comments

Comments
 (0)