luciole 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- luciole-0.1.0/.gitignore +228 -0
- luciole-0.1.0/CHANGELOG.md +13 -0
- luciole-0.1.0/LICENSE +21 -0
- luciole-0.1.0/PKG-INFO +72 -0
- luciole-0.1.0/README.md +48 -0
- luciole-0.1.0/docs/graph-format.md +251 -0
- luciole-0.1.0/docs/roadmap.md +148 -0
- luciole-0.1.0/examples/shop.graph.json +119 -0
- luciole-0.1.0/examples/shop.py +31 -0
- luciole-0.1.0/examples/workers.py +48 -0
- luciole-0.1.0/pyproject.toml +50 -0
- luciole-0.1.0/schema/graph.schema.json +142 -0
- luciole-0.1.0/src/luciole/__init__.py +1 -0
- luciole-0.1.0/src/luciole/__main__.py +5 -0
- luciole-0.1.0/src/luciole/analyzer.py +686 -0
- luciole-0.1.0/src/luciole/cli.py +62 -0
- luciole-0.1.0/src/luciole/recorder.py +561 -0
- luciole-0.1.0/src/luciole/values.py +84 -0
- luciole-0.1.0/tests/graphcheck.py +76 -0
- luciole-0.1.0/tests/test_analyzer.py +229 -0
- luciole-0.1.0/tests/test_graph_format.py +27 -0
- luciole-0.1.0/tests/test_recorder.py +468 -0
luciole-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs/Zensical documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
221
|
+
|
|
222
|
+
# Extension
|
|
223
|
+
extension/node_modules/
|
|
224
|
+
extension/out/
|
|
225
|
+
*.vsix
|
|
226
|
+
extension/python/
|
|
227
|
+
extension/LICENSE
|
|
228
|
+
extension/CHANGELOG.md
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- `luciole graph`: functions, classes, variables, calls and variable flow of a Python project,
|
|
8
|
+
from its source.
|
|
9
|
+
- `luciole run`: runs a script or module under a recorder (`sys.monitoring`, Python 3.12+) that
|
|
10
|
+
reports calls, call paths, threads and asyncio tasks, and can pause, step and show variables.
|
|
11
|
+
- VS Code extension: a 3D graph of the project, lit up as the program runs. Run Live on the
|
|
12
|
+
current file, Run Live… for arguments, modules (pytest) and run configurations, and Stop,
|
|
13
|
+
Pause/Resume, Step over/into/out with a Variables view.
|
luciole-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pinepomme
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
luciole-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: luciole
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Explore Python codebases as an interactive graph that lights up as your code runs
|
|
5
|
+
Project-URL: Homepage, https://github.com/Pinepomme/luciole
|
|
6
|
+
Project-URL: Repository, https://github.com/Pinepomme/luciole
|
|
7
|
+
Project-URL: Issues, https://github.com/Pinepomme/luciole/issues
|
|
8
|
+
Author: Alexandre Suescun
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: call-graph,code-exploration,data-flow,visualization,vscode
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# Luciole
|
|
26
|
+
|
|
27
|
+
Luciole turns a Python project into a graph you can explore, and lights it up as the code runs.
|
|
28
|
+
*Luciole* is French for "firefly".
|
|
29
|
+
|
|
30
|
+
- **One neuron per function.** The lines between them are the variables that flow from one
|
|
31
|
+
function to another: arguments in, return values out, and globals or attributes one function
|
|
32
|
+
writes and another reads.
|
|
33
|
+
- **Live mode.** Run a program, a module or your tests under the recorder: running functions glow,
|
|
34
|
+
pulses travel along calls, and every thread and asyncio task shows its call path.
|
|
35
|
+
- **Debugger controls.** Pause, step over/into/out, and look at every function's variables.
|
|
36
|
+
|
|
37
|
+
Luciole has two parts: this Python package (the analyzer and the live recorder), and a VS Code
|
|
38
|
+
extension that shows the graph in 3D. The extension bundles the package, so in VS Code there is
|
|
39
|
+
nothing to install in your project.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
pip install luciole # or: uv tool install luciole
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The package has no dependencies. The graph needs Python 3.10 or newer, live mode 3.12 or newer.
|
|
48
|
+
|
|
49
|
+
## Use
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
luciole graph src/ # summary of the graph
|
|
53
|
+
luciole graph src/ --json -o graph.json
|
|
54
|
+
luciole run train.py --epochs 1 # run a script under the recorder
|
|
55
|
+
luciole run --events run.jsonl -m pytest -q
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`luciole run` reports which project functions run, and who calls whom, as JSON lines: to the VS
|
|
59
|
+
Code extension, or to a file with `--events`. Only code under `--root` (default: the current
|
|
60
|
+
directory) is reported.
|
|
61
|
+
|
|
62
|
+
The graph format and the live events are documented in
|
|
63
|
+
[docs/graph-format.md](docs/graph-format.md), and the plan in [docs/roadmap.md](docs/roadmap.md).
|
|
64
|
+
|
|
65
|
+
## Status
|
|
66
|
+
|
|
67
|
+
Early: version 0.1. It works on real projects of tens of thousands of lines, but large graphs are
|
|
68
|
+
still dense, and calls through objects whose type the analyzer can't infer show up only at runtime.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|
luciole-0.1.0/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Luciole
|
|
2
|
+
|
|
3
|
+
Luciole turns a Python project into a graph you can explore, and lights it up as the code runs.
|
|
4
|
+
*Luciole* is French for "firefly".
|
|
5
|
+
|
|
6
|
+
- **One neuron per function.** The lines between them are the variables that flow from one
|
|
7
|
+
function to another: arguments in, return values out, and globals or attributes one function
|
|
8
|
+
writes and another reads.
|
|
9
|
+
- **Live mode.** Run a program, a module or your tests under the recorder: running functions glow,
|
|
10
|
+
pulses travel along calls, and every thread and asyncio task shows its call path.
|
|
11
|
+
- **Debugger controls.** Pause, step over/into/out, and look at every function's variables.
|
|
12
|
+
|
|
13
|
+
Luciole has two parts: this Python package (the analyzer and the live recorder), and a VS Code
|
|
14
|
+
extension that shows the graph in 3D. The extension bundles the package, so in VS Code there is
|
|
15
|
+
nothing to install in your project.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
pip install luciole # or: uv tool install luciole
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The package has no dependencies. The graph needs Python 3.10 or newer, live mode 3.12 or newer.
|
|
24
|
+
|
|
25
|
+
## Use
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
luciole graph src/ # summary of the graph
|
|
29
|
+
luciole graph src/ --json -o graph.json
|
|
30
|
+
luciole run train.py --epochs 1 # run a script under the recorder
|
|
31
|
+
luciole run --events run.jsonl -m pytest -q
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`luciole run` reports which project functions run, and who calls whom, as JSON lines: to the VS
|
|
35
|
+
Code extension, or to a file with `--events`. Only code under `--root` (default: the current
|
|
36
|
+
directory) is reported.
|
|
37
|
+
|
|
38
|
+
The graph format and the live events are documented in
|
|
39
|
+
[docs/graph-format.md](docs/graph-format.md), and the plan in [docs/roadmap.md](docs/roadmap.md).
|
|
40
|
+
|
|
41
|
+
## Status
|
|
42
|
+
|
|
43
|
+
Early: version 0.1. It works on real projects of tens of thousands of lines, but large graphs are
|
|
44
|
+
still dense, and calls through objects whose type the analyzer can't infer show up only at runtime.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# Luciole graph format (version 1)
|
|
2
|
+
|
|
3
|
+
The Python analyzer and the VS Code extension share only this format. The machine-checkable
|
|
4
|
+
definition is [`schema/graph.schema.json`](../schema/graph.schema.json). A complete hand-made
|
|
5
|
+
example is [`examples/shop.graph.json`](../examples/shop.graph.json), built from
|
|
6
|
+
[`examples/shop.py`](../examples/shop.py).
|
|
7
|
+
|
|
8
|
+
## Top level
|
|
9
|
+
|
|
10
|
+
```json
|
|
11
|
+
{
|
|
12
|
+
"format": "luciole-graph",
|
|
13
|
+
"format_version": 1,
|
|
14
|
+
"root": "examples",
|
|
15
|
+
"generator": { "name": "luciole", "version": "0.0.1" },
|
|
16
|
+
"nodes": [],
|
|
17
|
+
"edges": []
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`format_version` is an integer. It changes only on breaking changes. Adding optional fields does
|
|
22
|
+
not change it, so readers must ignore fields they don't know.
|
|
23
|
+
|
|
24
|
+
## Principles
|
|
25
|
+
|
|
26
|
+
1. **Containment is a field, not an edge.** Every node has a `parent` (`null` for modules). This
|
|
27
|
+
maps directly onto Cytoscape compound nodes and gives one source of truth.
|
|
28
|
+
2. **Edges point where things move.** `calls` goes from caller to callee. Data edges go from where a
|
|
29
|
+
value comes from to where it ends up (`reads` goes from variable to function, `writes` from
|
|
30
|
+
function to variable).
|
|
31
|
+
3. **One edge per (kind, source, target).** Repeated occurrences go into the edge's `sites` list.
|
|
32
|
+
This keeps large graphs small and still allows jumping to every occurrence.
|
|
33
|
+
4. **Variables are graph nodes, including the return value.** Each function with a `return <expr>`
|
|
34
|
+
gets a pseudo-variable named `return`. A program slice of a variable is then a plain graph
|
|
35
|
+
traversal over `flows_to`, `passes_arg` and `returns` edges, across function boundaries.
|
|
36
|
+
5. **Ids are stable qualified names.** Runtime events and saved UI state (what is expanded or
|
|
37
|
+
selected) refer to nodes by id, so ids must not change between runs while the code stays the same.
|
|
38
|
+
|
|
39
|
+
## Node ids
|
|
40
|
+
|
|
41
|
+
| Kind | Pattern | Example |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| module | dotted module name | `pkg.shop` |
|
|
44
|
+
| class / function in a module | `<module>:<name>` | `pkg.shop:Cart`, `pkg.shop:main` |
|
|
45
|
+
| class / function nested in a class or function | `<parent>.<name>` | `pkg.shop:Cart.add` |
|
|
46
|
+
| variable | `<scope>#<name>` | `pkg.shop:Cart.add#price`, `pkg.shop#TAX_RATE` |
|
|
47
|
+
| return value | `<function>#return` | `pkg.shop:with_tax#return` |
|
|
48
|
+
|
|
49
|
+
`return` is a Python keyword, so it can never collide with a real variable. When a name is defined
|
|
50
|
+
twice in the same scope (conditional definitions, `@property` plus a setter), the second definition
|
|
51
|
+
gets the suffix `~2`, the third `~3`, and so on (`pkg.shop:Cart.value~2`).
|
|
52
|
+
|
|
53
|
+
## Nodes
|
|
54
|
+
|
|
55
|
+
Every node has these fields: `id`, `kind`, `name`, `parent`, `file` (relative to `root`, with `/`
|
|
56
|
+
separators), and `loc`.
|
|
57
|
+
|
|
58
|
+
`loc` is `{line, col, end_line, end_col}` with 1-based lines and 0-based columns, exactly as
|
|
59
|
+
`ast` reports them. VS Code positions are 0-based for lines, so the extension subtracts 1.
|
|
60
|
+
|
|
61
|
+
| Kind | Parent | Extra fields | `loc` covers |
|
|
62
|
+
|---|---|---|---|
|
|
63
|
+
| `module` | `null` | — | whole file |
|
|
64
|
+
| `class` | module, class or function | `bases`, `decorators` (source text) | `class` statement, without decorators |
|
|
65
|
+
| `function` | module, class or function | `is_async`, `decorators` (source text) | `def` statement, without decorators |
|
|
66
|
+
| `variable` | module, class or function | `role`, and `param_index` when `role` is `param` | first binding |
|
|
67
|
+
|
|
68
|
+
Variable roles:
|
|
69
|
+
|
|
70
|
+
| `role` | Meaning | Parent |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| `param` | function parameter, including `self`, `*args` and `**kwargs` | function |
|
|
73
|
+
| `local` | name bound inside a function | function |
|
|
74
|
+
| `global` | module-level name | module |
|
|
75
|
+
| `class_attr` | name bound in a class body | class |
|
|
76
|
+
| `instance_attr` | `self.<name>` assigned in any method | class |
|
|
77
|
+
| `return` | the function's return value | function |
|
|
78
|
+
|
|
79
|
+
## Edges
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{ "kind": "calls", "source": "shop:main", "target": "shop:Cart.add",
|
|
83
|
+
"sites": [{ "line": 24, "col": 4 }, { "line": 25, "col": 4 }] }
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
| Kind | Source → target | Meaning | Site points at |
|
|
87
|
+
|---|---|---|---|
|
|
88
|
+
| `calls` | module/function → function/class | source calls target | the call expression |
|
|
89
|
+
| `reads` | variable → module/function | code reads the variable | the name |
|
|
90
|
+
| `writes` | module/function → variable | code assigns the variable | the assignment target |
|
|
91
|
+
| `flows_to` | variable → variable | source's value is used to compute target | the assignment target |
|
|
92
|
+
| `passes_arg` | caller variable → callee `param` | value passed as an argument | the argument expression |
|
|
93
|
+
| `returns` | callee `return` → caller variable | call result lands in target | the call expression |
|
|
94
|
+
|
|
95
|
+
`provenance` is `"static"` (the default, usually omitted) or `"runtime"`. Runtime edges come from
|
|
96
|
+
dynamic calls such as `getattr`, callbacks or monkey-patching that the static analysis couldn't see.
|
|
97
|
+
They may have no `sites`.
|
|
98
|
+
|
|
99
|
+
`reads` and `writes` are emitted for every access, including a function touching its own locals.
|
|
100
|
+
Renderers can hide edges whose variable is a child of the function, since nesting already shows
|
|
101
|
+
that relationship. The edges are still useful for `sites` (jumping to each use) and for runtime
|
|
102
|
+
lighting.
|
|
103
|
+
|
|
104
|
+
## Analysis rules
|
|
105
|
+
|
|
106
|
+
The analyzer ([`src/luciole/analyzer.py`](../src/luciole/analyzer.py)) implements these rules.
|
|
107
|
+
They decide what ends up in the graph.
|
|
108
|
+
|
|
109
|
+
**Calls**
|
|
110
|
+
|
|
111
|
+
- **Calls to classes** target the class's `__init__` when it is defined in the project (including on
|
|
112
|
+
a base class), or the class node otherwise. This way static edges line up with what the runtime
|
|
113
|
+
recorder sees.
|
|
114
|
+
- **Method calls** `obj.m(a)` also produce `passes_arg` from `obj` to `m`'s first parameter
|
|
115
|
+
(`self`), so an object can be traced across its methods. Static methods take no receiver. Class
|
|
116
|
+
methods skip `cls`. `Class.m(obj, a)` passes `obj` to `self` like any other argument.
|
|
117
|
+
- **Arguments** map to parameters by position, then by keyword. Extra ones go to `*args` or
|
|
118
|
+
`**kwargs`. Positions after a `*iterable` argument are unknown, so those arguments go to `*args`.
|
|
119
|
+
- **`obj.m()` resolves** only when the analyzer knows `obj`'s class. That's the case for `self`,
|
|
120
|
+
for a variable assigned from a constructor (`c = Cart()`), and for a parameter annotated with a
|
|
121
|
+
project class. Methods are looked up through base classes too. Anything else is unresolved, until
|
|
122
|
+
roadmap step 4 adds a real type checker.
|
|
123
|
+
- **Unresolved calls** (builtins, third-party code, unknown receivers), like `y = round(x, 2)` or
|
|
124
|
+
`t = s.upper()`, produce no `calls` edge. Their arguments and receiver `flows_to` the assignment
|
|
125
|
+
target directly, which is a conservative approximation.
|
|
126
|
+
- **Resolved calls** `y = f(x)` produce no direct `x → y` flow. The value goes
|
|
127
|
+
`passes_arg` x → `f#param`, then `returns` `f#return` → y.
|
|
128
|
+
- **Decorators** that are project functions get a `calls` edge from the code that defines the
|
|
129
|
+
decorated function.
|
|
130
|
+
|
|
131
|
+
**Variables**
|
|
132
|
+
|
|
133
|
+
- **`return f(x)`** treats `#return` as the assignment target.
|
|
134
|
+
- **`obj.x`**, when `x` is a known attribute (like `self.x` in a method, or a module's global),
|
|
135
|
+
reads `x` only, not `obj`. `self` is never counted as read. That also holds when `self` is passed
|
|
136
|
+
as a receiver.
|
|
137
|
+
- **`a.x = v` and `a[i] = v`**, when `x` isn't a tracked attribute, count as a write to `a`, with
|
|
138
|
+
`v flows_to a`.
|
|
139
|
+
- **Augmented assignment** `x += y` is a read and a write of `x`, and `y flows_to x`. It doesn't
|
|
140
|
+
produce a `flows_to` from `x` to itself, because self-loops are never emitted.
|
|
141
|
+
- **Tuple unpacking** `a, b = value` sends every source to every target.
|
|
142
|
+
- **Default values** `def f(x=LIMIT)` produce `LIMIT flows_to f#x`.
|
|
143
|
+
- **Literals** create no edges (`add(10)` has no `passes_arg`).
|
|
144
|
+
- **`global` / `nonlocal`** declarations create no new node. Accesses point at the outer variable.
|
|
145
|
+
- **Comprehension and lambda variables** are not tracked. In `ys = [f(x) for x in xs]`, `xs` flows
|
|
146
|
+
to `ys`, and `x` has no node.
|
|
147
|
+
- **Class bodies** run as the enclosing module or function: that's the source of their `calls`,
|
|
148
|
+
`reads` and `writes`.
|
|
149
|
+
|
|
150
|
+
**Structure**
|
|
151
|
+
|
|
152
|
+
- **Imported names** resolve to the node they import, when that node is in the project. Relative
|
|
153
|
+
imports are supported.
|
|
154
|
+
- **Module names** come from the package structure: walk up while the directory has an
|
|
155
|
+
`__init__.py`. So `src/luciole/cli.py` is `luciole.cli`. Directories starting with `.`, and
|
|
156
|
+
`__pycache__`, `venv`, `site-packages` and `node_modules` are skipped.
|
|
157
|
+
- **`@overload` stubs** are left out: they never run, and the implementation keeps the plain id.
|
|
158
|
+
- **Files that don't parse** are skipped with a warning.
|
|
159
|
+
|
|
160
|
+
## Worked example: where does `due` come from?
|
|
161
|
+
|
|
162
|
+
In `examples/shop.py`, following edges backwards from `shop:main#due` gives this chain:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
shop:main#due
|
|
166
|
+
← returns shop:Cart.total#return
|
|
167
|
+
← returns shop:with_tax#return
|
|
168
|
+
← flows_to shop:with_tax#total
|
|
169
|
+
← flows_to shop:with_tax#amount, shop#TAX_RATE
|
|
170
|
+
amount ← passes_arg shop:Cart#subtotal
|
|
171
|
+
subtotal ← flows_to shop:Cart.add#price
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
This is the "trace" view: one variable's path across four functions and a class, with nothing else
|
|
175
|
+
drawn.
|
|
176
|
+
|
|
177
|
+
## Live events
|
|
178
|
+
|
|
179
|
+
`luciole run [--root DIR] [--port N] [--events FILE] script.py [args...]` (or `-m module`) runs a
|
|
180
|
+
program under the recorder ([`src/luciole/recorder.py`](../src/luciole/recorder.py), Python
|
|
181
|
+
3.12+, `sys.monitoring`). Only code under `--root` is reported, by the same node ids as the graph.
|
|
182
|
+
Every 50 ms the recorder sends one JSON line, to the port and/or the file:
|
|
183
|
+
|
|
184
|
+
```json
|
|
185
|
+
{"t": 1.25,
|
|
186
|
+
"stacks": [{"thread": "MainThread", "stack": ["app", "app:main"]},
|
|
187
|
+
{"thread": "worker-1", "stack": ["app:crunch"]}],
|
|
188
|
+
"calls": {"app:checksum": 12}, "links": {"app:crunch>app:checksum": 12},
|
|
189
|
+
"spawns": {"app:start_workers>app:crunch": 2}, "waiting": {"app:download": 3}}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
- `t`: seconds since the program started.
|
|
193
|
+
- `stacks`: each thread's project frames, outermost first, main thread first, with the thread's name.
|
|
194
|
+
- `calls`: calls per function (or module code, or class body) since the previous line.
|
|
195
|
+
- `links`: calls per `caller>callee`, the caller being the nearest project frame, even across
|
|
196
|
+
library code (a function passed to `map` is called by whoever called `map`).
|
|
197
|
+
- `spawns`: work started elsewhere, per `origin>function`, since the previous line:
|
|
198
|
+
- a thread: `origin` is the project function that called `Thread.start` (also for
|
|
199
|
+
`threading.Thread` subclasses and thread pools, whose workers are started on first use);
|
|
200
|
+
- an asyncio task: `origin` is the project function that created the task's coroutine, as
|
|
201
|
+
recorded by `sys.set_coroutine_origin_tracking_depth`. A task's coroutine is run by the event
|
|
202
|
+
loop, so it gets a spawn instead of a link from whoever started the loop.
|
|
203
|
+
- `waiting`: project coroutines suspended on an `await` right now, per function. A coroutine
|
|
204
|
+
awaiting another one counts too (`main` waiting on `crawl` waiting on `download`).
|
|
205
|
+
|
|
206
|
+
A line is only sent when something changed. The last line is `{"done": true}`.
|
|
207
|
+
|
|
208
|
+
The recorder sends aggregates rather than one event per call. That keeps the stream small however
|
|
209
|
+
fast the program runs (pytest makes about 30,000 calls per second through it), which is all the
|
|
210
|
+
lighting needs. Variable reads and writes, and per-call replay, are not recorded yet.
|
|
211
|
+
|
|
212
|
+
All the state is kept by the monitoring callbacks, in the thread where each event happens: each
|
|
213
|
+
thread has its own project stack, pushed on `PY_START`/`PY_RESUME`, popped on
|
|
214
|
+
`PY_RETURN`/`PY_YIELD`/`PY_UNWIND`. The background thread that sends the lines never reads other
|
|
215
|
+
threads' frames: `sys._current_frames()` breaks `torch.export` tracing.
|
|
216
|
+
|
|
217
|
+
### Pausing and variables
|
|
218
|
+
|
|
219
|
+
The socket also carries commands from the view to the recorder, one JSON object per line:
|
|
220
|
+
`{"cmd": "pause"}`, `{"cmd": "resume"}`, `{"cmd": "expand", "ref": 7}` and
|
|
221
|
+
`{"cmd": "step", "thread": 1401, "mode": "over"}` (`mode`: `over`, `into` or `out`). On pause, the
|
|
222
|
+
recorder turns on `LINE` events and each thread stops at its next line of project code. It sends
|
|
223
|
+
its own project frames, innermost first, with their variables, to the view only (not to
|
|
224
|
+
`--events`):
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{"paused": {"thread": "MainThread", "id": 1401, "frames": [
|
|
228
|
+
{"node": "app:tick", "name": "tick", "file": "/abs/app.py", "line": 14,
|
|
229
|
+
"vars": [{"name": "step", "type": "int", "value": "7"},
|
|
230
|
+
{"name": "cart", "type": "Cart", "value": "<app.Cart object at 0x7f…>", "ref": 3},
|
|
231
|
+
{"name": "(globals)", "value": "2 names", "ref": 4}]}]}}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
A variable with a `ref` has children. `expand` asks for them, and the thread that owns the value
|
|
235
|
+
answers (its `repr` may run the program's code) with `{"children": {"ref": 3, "vars": [...]}}`:
|
|
236
|
+
dict items, sequence items or object attributes, 300 at most. Refs are valid until `resume`.
|
|
237
|
+
A thread reads only its own frames, as for the stacks above. Closing the socket resumes the
|
|
238
|
+
program.
|
|
239
|
+
|
|
240
|
+
A step resumes every thread. The stepping thread stops at:
|
|
241
|
+
|
|
242
|
+
- `into`: its next line of project code, wherever it is;
|
|
243
|
+
- `over`: the next line of the frame it was paused in, or the next project line once that frame
|
|
244
|
+
returns, raises, or (a generator) yields; a coroutine suspended on an `await` stops when it
|
|
245
|
+
continues;
|
|
246
|
+
- `out`: the next project line once that frame returns, raises or yields.
|
|
247
|
+
|
|
248
|
+
Then every thread stops again, and new `paused` messages come.
|
|
249
|
+
|
|
250
|
+
Not covered yet: other processes (`multiprocessing`, Python subprocesses), and event loops in
|
|
251
|
+
threads other than the main one (their tasks still show as calls, without their spawn origin).
|