1@echo off 2setlocal 3 4pushd %~dp0 5 6set this=%~n0 7 8call ..\PCbuild\find_python.bat %PYTHON% 9 10if not defined PYTHON set PYTHON=py 11 12if not defined SPHINXBUILD ( 13 %PYTHON% -c "import sphinx" > nul 2> nul 14 if errorlevel 1 ( 15 echo Installing sphinx with %PYTHON% 16 %PYTHON% -m pip install -r requirements.txt 17 if errorlevel 1 exit /B 18 ) 19 set SPHINXBUILD=%PYTHON% -c "import sphinx.cmd.build, sys; sys.exit(sphinx.cmd.build.main())" 20) 21 22%PYTHON% -c "import python_docs_theme" > nul 2> nul 23if errorlevel 1 ( 24 echo Installing python-docs-theme with %PYTHON% 25 %PYTHON% -m pip install python-docs-theme 26 if errorlevel 1 exit /B 27) 28 29if not defined BLURB ( 30 %PYTHON% -c "import blurb" > nul 2> nul 31 if errorlevel 1 ( 32 echo Installing blurb with %PYTHON% 33 rem Should have been installed with Sphinx earlier 34 %PYTHON% -m pip install blurb 35 if errorlevel 1 exit /B 36 ) 37 set BLURB=%PYTHON% -m blurb 38) 39 40if not defined SPHINXLINT ( 41 %PYTHON% -c "import sphinxlint" > nul 2> nul 42 if errorlevel 1 ( 43 echo Installing sphinx-lint with %PYTHON% 44 rem Should have been installed with Sphinx earlier 45 %PYTHON% -m pip install sphinx-lint 46 if errorlevel 1 exit /B 47 ) 48 set SPHINXLINT=%PYTHON% -m sphinxlint 49) 50 51if "%1" NEQ "htmlhelp" goto :skiphhcsearch 52if exist "%HTMLHELP%" goto :skiphhcsearch 53 54rem Search for HHC in likely places 55set HTMLHELP= 56where hhc /q && set "HTMLHELP=hhc" && goto :skiphhcsearch 57where /R ..\externals hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" 58if not exist "%HTMLHELP%" where /R "%ProgramFiles(x86)%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" 59if not exist "%HTMLHELP%" where /R "%ProgramFiles%" hhc > "%TEMP%\hhc.loc" 2> nul && set /P HTMLHELP= < "%TEMP%\hhc.loc" & del "%TEMP%\hhc.loc" 60if not exist "%HTMLHELP%" ( 61 echo. 62 echo.The HTML Help Workshop was not found. Set the HTMLHELP variable 63 echo.to the path to hhc.exe or download and install it from 64 echo.http://msdn.microsoft.com/en-us/library/ms669985 65 exit /B 1 66) 67:skiphhcsearch 68 69if not defined DISTVERSION for /f "usebackq" %%v in (`%PYTHON% tools/extensions/patchlevel.py`) do set DISTVERSION=%%v 70 71if not defined BUILDDIR set BUILDDIR=build 72 73rem Targets that don't require sphinx-build 74if "%1" EQU "" goto help 75if "%1" EQU "help" goto help 76if "%1" EQU "check" goto check 77if "%1" EQU "serve" goto serve 78if "%1" == "clean" ( 79 rmdir /q /s "%BUILDDIR%" 80 goto end 81) 82 83%SPHINXBUILD% >nul 2> nul 84if errorlevel 9009 ( 85 echo. 86 echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 87 echo.installed, then set the SPHINXBUILD environment variable to point 88 echo.to the full path of the 'sphinx-build' executable. Alternatively you 89 echo.may add the Sphinx directory to PATH. 90 echo. 91 echo.If you don't have Sphinx installed, grab it from 92 echo.http://sphinx-doc.org/ 93 popd 94 exit /B 1 95) 96 97rem Targets that do require sphinx-build and have their own label 98if "%1" EQU "htmlview" goto htmlview 99 100rem Everything else 101goto build 102 103:help 104echo.usage: %this% BUILDER [filename ...] 105echo. 106echo.Call %this% with the desired Sphinx builder as the first argument, e.g. 107echo.``%this% html`` or ``%this% doctest``. Interesting targets that are 108echo.always available include: 109echo. 110echo. Provided by Sphinx: 111echo. html, htmlhelp, latex, text 112echo. suspicious, linkcheck, changes, doctest 113echo. Provided by this script: 114echo. clean, check, htmlview 115echo. 116echo.All arguments past the first one are passed through to sphinx-build as 117echo.filenames to build or are ignored. See README.rst in this directory or 118echo.the documentation for your version of Sphinx for more exhaustive lists 119echo.of available targets and descriptions of each. 120echo. 121echo.This script assumes that the SPHINXBUILD environment variable contains 122echo.a legitimate command for calling sphinx-build, or that sphinx-build is 123echo.on your PATH if SPHINXBUILD is not set. Options for sphinx-build can 124echo.be passed by setting the SPHINXOPTS environment variable. 125goto end 126 127:build 128if not exist "%BUILDDIR%" mkdir "%BUILDDIR%" 129 130rem PY_MISC_NEWS_DIR is also used by our Sphinx extension in tools/extensions/pyspecific.py 131if not defined PY_MISC_NEWS_DIR set PY_MISC_NEWS_DIR=%BUILDDIR%\%1 132if not exist "%PY_MISC_NEWS_DIR%" mkdir "%PY_MISC_NEWS_DIR%" 133if exist ..\Misc\NEWS ( 134 echo.Copying Misc\NEWS to %PY_MISC_NEWS_DIR%\NEWS 135 copy ..\Misc\NEWS "%PY_MISC_NEWS_DIR%\NEWS" > nul 136) else if exist ..\Misc\NEWS.D ( 137 if defined BLURB ( 138 echo.Merging Misc/NEWS with %BLURB% 139 %BLURB% merge -f "%PY_MISC_NEWS_DIR%\NEWS" 140 ) else ( 141 echo.No Misc/NEWS file and Blurb is not available. 142 exit /B 1 143 ) 144) 145 146if defined PAPER ( 147 set SPHINXOPTS=-D latex_elements.papersize=%PAPER% %SPHINXOPTS% 148) 149if "%1" EQU "htmlhelp" ( 150 set SPHINXOPTS=-D html_theme_options.body_max_width=none %SPHINXOPTS% 151) 152cmd /S /C "%SPHINXBUILD% %SPHINXOPTS% -b%1 -dbuild\doctrees . "%BUILDDIR%\%1" %2 %3 %4 %5 %6 %7 %8 %9" 153 154if "%1" EQU "htmlhelp" ( 155 "%HTMLHELP%" "%BUILDDIR%\htmlhelp\python%DISTVERSION:.=%.hhp" 156 rem hhc.exe seems to always exit with code 1, reset to 0 for less than 2 157 if not errorlevel 2 cmd /C exit /b 0 158) 159 160echo. 161if errorlevel 1 ( 162 echo.Build failed (exit code %ERRORLEVEL%^), check for error messages 163 echo.above. Any output will be found in %BUILDDIR%\%1 164) else ( 165 echo.Build succeeded. All output should be in %BUILDDIR%\%1 166) 167goto end 168 169:htmlview 170if NOT "%2" EQU "" ( 171 echo.Can't specify filenames to build with htmlview target, ignoring. 172) 173cmd /C %this% html 174 175if EXIST "%BUILDDIR%\html\index.html" ( 176 echo.Opening "%BUILDDIR%\html\index.html" in the default web browser... 177 start "" "%BUILDDIR%\html\index.html" 178) 179 180goto end 181 182:check 183rem Check the docs and NEWS files with sphinx-lint. 184rem Ignore the tools dir and check that the default role is not used. 185cmd /S /C "%SPHINXLINT% -i tools --enable default-role" 186cmd /S /C "%SPHINXLINT% --enable default-role ..\Misc\NEWS.d\next\ " 187goto end 188 189:serve 190echo.The serve target was removed, use htmlview instead (see bpo-36329) 191goto end 192 193:end 194popd 195