with one click
find-cpython-usage
// Find all CPython internal headers and structs used in the codebase, particularly for profiling functionality. Use this when adding support for a new Python version to identify what CPython internals we depend on.
// Find all CPython internal headers and structs used in the codebase, particularly for profiling functionality. Use this when adding support for a new Python version to identify what CPython internals we depend on.
Run targeted linting, formatting, and code quality checks on modified files. Use this to validate code style, type safety, security, and other quality metrics before committing. Supports running all checks or targeting specific checks on specific files for efficient validation.
Validate code changes by intelligently selecting and running the appropriate test suites. Use this when editing code to verify changes work correctly, run tests, validate functionality, or check for regressions. Automatically discovers affected test suites, selects the minimal set of venvs needed for validation, and handles test execution with Docker services as needed.
Diagnose and fix slow base venv build times caused by unnecessary recompilation of native extensions (CMake, Cython, Rust) across riot generate runs. Use when CI base venv builds are slow, when ext_cache isn't saving time, or when investigating warm build regressions.
Run performance benchmarks to measure the impact of code changes. Discovers relevant benchmark scenarios based on changed files, executes them comparing a baseline version against local changes, and summarizes performance results. Use this when touching performance-sensitive code paths or when asked about performance impact.
Review CI results for the current branch, commit, or PR using the Datadog MCP. Use this when CI is failing, to understand what's blocking a PR, or to get actionable fix instructions for failed jobs and tests.
Run circular import detection against ddtrace and propose architectural fixes for any cycles found. Use this when adding or refactoring modules, or when the detect_circular_imports CI job reports new cycles on a PR.
| name | find-cpython-usage |
| description | Find all CPython internal headers and structs used in the codebase, particularly for profiling functionality. Use this when adding support for a new Python version to identify what CPython internals we depend on. |
| allowed-tools | ["Bash","Read","Grep","Glob","TodoWrite"] |
This skill helps identify all CPython internal headers and structures used in the codebase, which is essential when adding support for new Python versions.
Use this skill when:
Search for CPython header includes across all C/C++/Cython files:
# Find all CPython internal header includes
grep -r "include.*internal/pycore" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find all CPython cpython header includes
grep -r "include.*cpython" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find all Python.h includes (indicates CPython API usage)
grep -r "#include.*Python\.h" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find frameobject.h includes (common CPython API)
grep -r "#include.*frameobject\.h" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
# Find PyO3 FFI usage in Rust (Rust extensions may use CPython internals)
grep -r "pyo3_ffi::\|pyo3::ffi::" src/native/ --include="*.rs" || true
Note: These patterns search across all native extension files (.c, .cpp, .h, .hpp, .pyx, .rs)
regardless of their location in the codebase. Check setup.py to see which extensions are built.
Rust extensions use PyO3 which may access CPython internals through the pyo3_ffi module.
Search for direct struct field access and struct definitions across all native files:
# Find struct field accesses (arrow operator)
grep -r "->f_\|->[a-z_]*\." ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp"
# Find struct definitions
grep -r "struct.*Py" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp"
# Find common CPython struct usage
grep -r "PyFrameObject\|PyThreadState\|_PyInterpreterFrame" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
grep -r "PyFrameObject\|PyThreadState\|PyInterpreterState" src/native/ --include="*.rs" || true
# Find PyCodeObject usage
grep -r "PyCodeObject" ddtrace/ --include="*.c" --include="*.cpp" --include="*.h" --include="*.hpp" --include="*.pyx"
grep -r "PyCodeObject" src/native/ --include="*.rs" || true
Look for patterns like:
PyFrameObject, _PyInterpreterFrame)PyThreadState)PyCodeObject)Common CPython structures we typically access:
Frame structures:
PyFrameObject / struct _frame_PyInterpreterFrameState structures:
PyThreadStatePyInterpreterState_PyRuntimeStateCode structures:
PyCodeObjectGenerator structures:
PyGenObjectPyAsyncGenASendAsyncio structures:
FutureObjTaskObjCreate a list of:
This will be used in the next step to compare against the new Python version.
To find all native extensions that may use CPython APIs, check setup.py:
# View all native extensions defined in setup.py
grep -A 5 "Extension\|CMakeExtension\|Cython.Distutils.Extension\|RustExtension" setup.py
The setup.py file defines all native extensions (C, C++, CMake, Cython, and Rust) that
are built for the project. Not all extensions use CPython internals - focus on those
that access frame objects, thread state, or internal structures when searching for
CPython API usage.
Note: Rust extensions use PyO3 bindings which may access CPython internals through
pyo3_ffi module. Search Rust source files (.rs) for CPython API usage as well.
The grep commands above will identify which CPython headers are actually used in the codebase. Common patterns include:
Public Headers:
*.h in Include/ directory (e.g., frameobject.h, unicodeobject.h)Include/cpython/ directory (e.g., cpython/genobject.h)Internal Headers (require Py_BUILD_CORE):
internal/pycore*.h patternFocus on headers that are actually found by the grep commands rather than maintaining a hardcoded list, as the headers used may change over time.
After running this skill, you should have:
This information can then be used with the compare-cpython-versions skill to identify what changed.