11@ ECHO OFF
22
3- REM Command file for Sphinx documentation
4-
3+ REM ============================================================================
4+ REM Sphinx Documentation Build Script for Requests
5+ REM ============================================================================
6+ REM Purpose: Build Sphinx documentation in various formats (HTML, PDF, etc.)
7+ REM Author: Requests Documentation Team
8+ REM Date: 2025
9+ REM
10+ REM This script provides a Windows interface to Sphinx documentation builds.
11+ REM It supports multiple output formats and handles Sphinx installation checks.
12+ REM ============================================================================
13+
14+ REM Define error code constants
15+ set " ERROR_COMMAND_NOT_FOUND = 9009"
16+
17+ REM Configure Sphinx build settings
518if " %SPHINXBUILD% " == " " (
6- set SPHINXBUILD = sphinx-build
19+ set " SPHINXBUILD = sphinx-build"
720)
8- set BUILDDIR = _build
9- set ALLSPHINXOPTS = -d %BUILDDIR% /doctrees %SPHINXOPTS% .
10- set I18NSPHINXOPTS = %SPHINXOPTS% .
21+ set " BUILDDIR = _build"
22+ set " ALLSPHINXOPTS = -d %BUILDDIR% /doctrees %SPHINXOPTS% ."
23+ set " I18NSPHINXOPTS = %SPHINXOPTS% ."
1124if NOT " %PAPER% " == " " (
12- set ALLSPHINXOPTS = -D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
13- set I18NSPHINXOPTS = -D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
25+ set " ALLSPHINXOPTS = -D latex_paper_size=%PAPER% %ALLSPHINXOPTS% "
26+ set " I18NSPHINXOPTS = -D latex_paper_size=%PAPER% %I18NSPHINXOPTS% "
1427)
1528
1629if " %1 " == " " goto help
1730
1831if " %1 " == " help" (
32+ REM ========================================================================
33+ REM Subroutine: help
34+ REM Purpose: Display usage information and available build targets
35+ REM Parameters: None
36+ REM Returns: Displays help text and exits
37+ REM ========================================================================
1938 :help
2039 echo .Please use `make ^ < target^ > ` where ^ < target^ > is one of
2140 echo . html to make standalone HTML files
@@ -43,21 +62,30 @@ if "%1" == "help" (
4362
4463if " %1 " == " clean" (
4564 for /d %%i in (%BUILDDIR% \*) do rmdir /q /s %%i
46- del /q /s %BUILDDIR% \*
65+ del /q /s %BUILDDIR% \* 2 > nul
66+ if errorlevel 1 (
67+ echo .Warning: Some files could not be deleted
68+ )
4769 goto end
4870)
4971
5072
5173REM Check if sphinx-build is available and fallback to Python version if any
5274%SPHINXBUILD% 1 > NUL 2 > NUL
53- if errorlevel 9009 goto sphinx_python
75+ if errorlevel %ERROR_COMMAND_NOT_FOUND% goto sphinx_python
5476goto sphinx_ok
5577
78+ REM ============================================================================
79+ REM Subroutine: sphinx_python
80+ REM Purpose: Fallback to Python module invocation if sphinx-build not found
81+ REM Parameters: None
82+ REM Returns: Sets SPHINXBUILD to Python module path or exits with error
83+ REM ============================================================================
5684:sphinx_python
5785
58- set SPHINXBUILD = python -m sphinx.__init__
86+ set " SPHINXBUILD = python -m sphinx.__init__"
5987%SPHINXBUILD% 2 > nul
60- if errorlevel 9009 (
88+ if errorlevel %ERROR_COMMAND_NOT_FOUND% (
6189 echo .
6290 echo .The 'sphinx-build' command was not found. Make sure you have Sphinx
6391 echo .installed, then set the SPHINXBUILD environment variable to point
@@ -69,6 +97,12 @@ if errorlevel 9009 (
6997 exit /b 1
7098)
7199
100+ REM ============================================================================
101+ REM Subroutine: sphinx_ok
102+ REM Purpose: Confirms Sphinx is available and proceeds with build operations
103+ REM Parameters: None
104+ REM Returns: Continues to build target handling
105+ REM ============================================================================
72106:sphinx_ok
73107
74108
@@ -260,4 +294,11 @@ if "%1" == "pseudoxml" (
260294 goto end
261295)
262296
297+ REM ============================================================================
298+ REM Subroutine: end
299+ REM Purpose: Exit point for all build operations
300+ REM Parameters: None
301+ REM Returns: Terminates script execution with success code
302+ REM ============================================================================
263303:end
304+ exit /b 0
0 commit comments