Visualize the python compile pipeline
This requires:
- CPython 3.13 (tested with 3.13.0b1)
- dependencies in requirements.txt
- You will have to manually install
tree-sitter-languagesto have syntax highlighting. See step-by-step instructions below
- You will have to manually install
The code uses internal, undocumented CPython APIs. It is very likely to break in future CPython versions. When it does you get to keep both pieces.
You can run this code under python 3.12 or lower, but many features will be disabled.
The code is not packaged, due to some dependencies not being available yet in Python 3.13 (See this issue). I was able to get everything up by running the following commands:
python3.13 -m venv env
# or with uv
uv venv env --python 3.13 --seed
git clone https://github.com/grantjenks/py-tree-sitter-languages.git
git clone https://github.com/iritkatriel/codoscope.git
cd py-tree-sitter-languages/
../env/bin/pip install Cython tree_sitter==0.20.4 setuptools
../env/bin/python build.py
../env/bin/python setup.py install
cd ../codoscope
../env/bin/pip install -r requirements.txtenv/bin/python codoscope/src/main.pyWill start the application. You can press e to edit the code, and CTRL+S to go back
to the inspector. You can enable different code views in the inspectors with the numbers
from 1 to 7. You can quit with q.
The supported code views are:
- Source
- Tokens
- AST
- Optimized AST
- Pseudo bytecode
- Optimized Pseudo bytecode
- Assembled bytecode
You can pre-load source from a file by running:
env/bin/python codoscope/src/main.py source-file-to-analyze.pyFor testing compilation of a single line you can use:
env/bin/python codoscope/src/main.py -c 'x = [y*y for y in range(10)]'For showing the code of a python module you can run:
env/bin/python codoscope/src/main.py -m package.moduleOnce you run it, you can inspect parts of the source code and the corresponding code views by hovering over them.