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