Use this skill when you need to compile CPython, run tests, verify your changes work, check if a fix is correct, or debug test failures. Covers building from source with ./configure and make, ccache for faster rebuilds, Argument Clinic regeneration, and the unittest-based test system (NOT pytest). Essential for any task that requires running code or tests.
View on GitHubSelect agents to install to:
npx add-skill https://github.com/gpshead/cpython-skills/blob/main/plugins/cpython-skills/skills/build/SKILL.md -a claude-code --skill buildInstallation paths:
.claude/skills/build/# Building and Testing CPython ## Building CPython **ONLY build in a `build/` subdirectory** at repo root. Never build in the source tree. ### Setup and Configuration ```bash # Build directory setup REPO_ROOT=<path-to-cpython-git-repo> BUILD_DIR=$REPO_ROOT/build ``` #### ccache Setup (Recommended) ccache dramatically speeds up rebuilds by caching compilation results. Check if available: ```bash which ccache ``` **If ccache is not installed**: - macOS (Homebrew): Install directly with `brew install ccache` (no sudo required) - Containerized/root environments: Install directly with `apt-get install -y ccache` or `dnf install -y ccache` - Otherwise, ask the user for permission to install: - Debian/Ubuntu: `sudo apt-get install ccache` - Fedora/RHEL: `sudo dnf install ccache` **Configure with ccache** (if available): ```bash cd $BUILD_DIR && CC="ccache gcc" ../configure --with-pydebug ``` **Configure without ccache** (fallback): ```bash cd $BUILD_DIR && ../configure --with-pydebug ``` #### Performance/Benchmarking Builds When doing benchmarking or performance measurement of C code changes, **omit `--with-pydebug`** from configure: ```bash cd $BUILD_DIR && CC="ccache gcc" ../configure # No --with-pydebug ``` Debug builds have significant overhead that distorts performance measurements. However, **do not use `--enable-optimizations`** unless explicitly asked—it enables PGO (Profile-Guided Optimization) which is slow to compile. Non-PGO release builds are sufficient for the majority of performance comparison work. ```bash # Build using all CPU cores (initial or incremental) make -C $BUILD_DIR -j $(nproc) ``` **Platform notes**: - Linux: `BUILT_PY=$BUILD_DIR/python` - macOS: `BUILT_PY=$BUILD_DIR/python.exe` (note .exe extension) - Windows: Ask user how to build (uses Visual Studio, different process) ### Argument Clinic After editing `.c` files that change function signatures, docstrings, or argument specs: ```bash make -C $BUILD_DIR clinic ``` **NEV