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