You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.5 KiB

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