Skip to content

iritkatriel/codoscope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codoscope

Visualize the python compile pipeline

Install

This requires:

  • CPython 3.13 (tested with 3.13.0b1)
  • dependencies in requirements.txt
    • You will have to manually install tree-sitter-languages to have syntax highlighting. See step-by-step instructions below

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.

Step by step

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.txt

Usage

env/bin/python codoscope/src/main.py

Will 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:

  1. Source
  2. Tokens
  3. AST
  4. Optimized AST
  5. Pseudo bytecode
  6. Optimized Pseudo bytecode
  7. Assembled bytecode

You can pre-load source from a file by running:

env/bin/python codoscope/src/main.py source-file-to-analyze.py

For 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.module

Once you run it, you can inspect parts of the source code and the corresponding code views by hovering over them.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages