mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-16 23:44:53 +08:00
This pull request updates the PyTorch documentation build system to support newer versions of Sphinx and its related dependencies, improves coverage checking for undocumented objects, and adds configuration enhancements to the docs build. The most important changes are grouped below. **Dependency Upgrades and Compatibility:** * Upgraded `sphinx` to version 7.2.6 and updated related documentation dependencies (`breathe`, `exhale`, `docutils`, `myst-nb`, `sphinx-design`, `myst-parser`, and others) in `.ci/docker/requirements-docs.txt` to ensure compatibility with Python 3.13 and improve documentation generation. [[1]](diffhunk://#diff-b5577a8e38a2e4c5d91865096b259738cc1dbcb97921abb73045dae0255b1479L1-L12) [[2]](diffhunk://#diff-b5577a8e38a2e4c5d91865096b259738cc1dbcb97921abb73045dae0255b1479L39-R45) [[3]](diffhunk://#diff-b5577a8e38a2e4c5d91865096b259738cc1dbcb97921abb73045dae0255b1479L59-R64) * Replaced the editable install of `pytorch_sphinx_theme2` with a pinned version for stability in documentation builds. **Documentation Coverage and Build Improvements:** * Updated the coverage check logic in `.ci/pytorch/python_doc_push_script.sh` to parse the new Sphinx 7.2.6+ coverage report format, extracting the undocumented count from the statistics table for more reliable coverage validation. **Configuration and Formatting Enhancements:** * Introduced `autosummary_filename_map` in `docs/source/conf.py` to resolve duplicated autosummary output filenames for functions and classes with the same name, improving documentation clarity. **Minor Documentation Formatting:** * Removed an unused `:template:` directive from `docs/source/quantization-support.md` for cleaner autosummary output. Pull Request resolved: https://github.com/pytorch/pytorch/pull/164901 Approved by: https://github.com/albanD
157 lines
5.0 KiB
Bash
Executable File
157 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# This is where the local pytorch install in the docker image is located
|
|
pt_checkout="/var/lib/jenkins/workspace"
|
|
|
|
source "$pt_checkout/.ci/pytorch/common_utils.sh"
|
|
|
|
echo "python_doc_push_script.sh: Invoked with $*"
|
|
|
|
set -ex -o pipefail
|
|
|
|
# for statements like ${1:-${DOCS_INSTALL_PATH:-docs/}}
|
|
# the order of operations goes:
|
|
# 1. Check if there's an argument $1
|
|
# 2. If no argument check for environment var DOCS_INSTALL_PATH
|
|
# 3. If no environment var fall back to default 'docs/'
|
|
|
|
# NOTE: It might seem weird to gather the second argument before gathering the first argument
|
|
# but since DOCS_INSTALL_PATH can be derived from DOCS_VERSION it's probably better to
|
|
# try and gather it first, just so we don't potentially break people who rely on this script
|
|
# Argument 2: What version of the docs we are building.
|
|
version="${2:-${DOCS_VERSION:-main}}"
|
|
if [ -z "$version" ]; then
|
|
echo "error: python_doc_push_script.sh: version (arg2) not specified"
|
|
exit 1
|
|
fi
|
|
|
|
# Argument 1: Where to copy the built documentation to
|
|
# (pytorch_docs/$install_path)
|
|
install_path="${1:-${DOCS_INSTALL_PATH:-${DOCS_VERSION}}}"
|
|
if [ -z "$install_path" ]; then
|
|
echo "error: python_doc_push_script.sh: install_path (arg1) not specified"
|
|
exit 1
|
|
fi
|
|
|
|
is_main_doc=false
|
|
if [ "$version" == "main" ]; then
|
|
is_main_doc=true
|
|
fi
|
|
|
|
# Argument 3: The branch to push to. Usually is "site"
|
|
branch="${3:-${DOCS_BRANCH:-site}}"
|
|
if [ -z "$branch" ]; then
|
|
echo "error: python_doc_push_script.sh: branch (arg3) not specified"
|
|
exit 1
|
|
fi
|
|
|
|
echo "install_path: $install_path version: $version"
|
|
|
|
|
|
build_docs () {
|
|
set +e
|
|
set -o pipefail
|
|
make "$1" 2>&1 | tee /tmp/docs_build.txt
|
|
code=$?
|
|
if [ $code -ne 0 ]; then
|
|
set +x
|
|
echo =========================
|
|
grep "WARNING:" /tmp/docs_build.txt
|
|
echo =========================
|
|
echo Docs build failed. If the failure is not clear, scan back in the log
|
|
echo for any WARNINGS or for the line "build finished with problems"
|
|
echo "(tried to echo the WARNINGS above the ==== line)"
|
|
echo =========================
|
|
fi
|
|
set -ex -o pipefail
|
|
return $code
|
|
}
|
|
|
|
|
|
git clone https://github.com/pytorch/docs pytorch_docs -b "$branch" --depth 1
|
|
pushd pytorch_docs
|
|
|
|
export LC_ALL=C
|
|
export PATH=/opt/conda/bin:$PATH
|
|
if [ -n "$ANACONDA_PYTHON_VERSION" ]; then
|
|
export PATH=/opt/conda/envs/py_$ANACONDA_PYTHON_VERSION/bin:$PATH
|
|
fi
|
|
|
|
rm -rf pytorch || true
|
|
|
|
# Get all the documentation sources, put them in one place
|
|
pushd "$pt_checkout"
|
|
pushd docs
|
|
|
|
# Build the docs
|
|
if [ "$is_main_doc" = true ]; then
|
|
build_docs html || exit $?
|
|
|
|
make coverage
|
|
# Now we have the coverage report, we need to make sure it is empty.
|
|
# Sphinx 7.2.6+ format: python.txt contains a statistics table with a TOTAL row
|
|
# showing the undocumented count in the third column.
|
|
# Example: | TOTAL | 99.83% | 2 |
|
|
#
|
|
# Also: see docs/source/conf.py for "coverage_ignore*" items, which should
|
|
# be documented then removed from there.
|
|
|
|
# Extract undocumented count from TOTAL row in Sphinx 7.2.6 statistics table
|
|
# The table format is: | Module | Coverage | Undocumented |
|
|
# Extract the third column (undocumented count) from the TOTAL row
|
|
undocumented=$(grep "| TOTAL" build/coverage/python.txt | awk -F'|' '{print $4}' | tr -d ' ')
|
|
|
|
if [ -z "$undocumented" ] || ! [[ "$undocumented" =~ ^[0-9]+$ ]]; then
|
|
echo coverage output not found
|
|
exit 1
|
|
elif [ "$undocumented" -gt 0 ]; then
|
|
set +x # Disable command echoing for cleaner output
|
|
echo ""
|
|
echo "====================="
|
|
echo "UNDOCUMENTED OBJECTS:"
|
|
echo "====================="
|
|
echo ""
|
|
# Find the line number of the TOTAL row and print only what comes after it
|
|
total_line=$(grep -n "| TOTAL" build/coverage/python.txt | cut -d: -f1)
|
|
if [ -n "$total_line" ]; then
|
|
# Print only the detailed list (skip the statistics table)
|
|
tail -n +$((total_line + 2)) build/coverage/python.txt
|
|
else
|
|
# Fallback to showing entire file if TOTAL line not found
|
|
cat build/coverage/python.txt
|
|
fi
|
|
echo ""
|
|
echo "Make sure you've updated relevant .rsts in docs/source!"
|
|
echo "You can reproduce locally by running 'cd docs && make coverage && tail -n +\$((grep -n \"| TOTAL\" build/coverage/python.txt | cut -d: -f1) + 2)) build/coverage/python.txt'"
|
|
set -x # Re-enable command echoing
|
|
exit 1
|
|
fi
|
|
else
|
|
# skip coverage, format for stable or tags
|
|
build_docs html-stable || exit $?
|
|
fi
|
|
|
|
# Move them into the docs repo
|
|
popd
|
|
popd
|
|
git rm -rf "$install_path" || true
|
|
mv "$pt_checkout/docs/build/html" "$install_path"
|
|
|
|
git add "$install_path" || true
|
|
git status
|
|
git config user.email "soumith+bot@pytorch.org"
|
|
git config user.name "pytorchbot"
|
|
# If there aren't changes, don't make a commit; push is no-op
|
|
git commit -m "Generate Python docs from pytorch/pytorch@${GITHUB_SHA}" || true
|
|
git status
|
|
|
|
if [[ "${WITH_PUSH:-}" == true ]]; then
|
|
# push to a temp branch first to trigger CLA check and satisfy branch protections
|
|
git push -u origin HEAD:pytorchbot/temp-branch-py -f
|
|
git push -u origin HEAD^:pytorchbot/base -f
|
|
sleep 30
|
|
git push -u origin "${branch}"
|
|
fi
|
|
|
|
popd
|