You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8d4cb58
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: v3/docs/developer-overview.md
+64-49Lines changed: 64 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,10 @@ elapsed since that date, the more likely things are out-of-date.
10
10
11
11
I'm assuming that you're competent in Python, JavaScript, command-line-fu, and Google-fu,
12
12
so I won't do much hand-holding in these directions.
13
-
But feel free to email philip@pgbovine.net if you have questions.
13
+
14
+
This guy isn't meant to be comprehensive; rather, it's just a starting point for learning about the code
15
+
and development workflow. You will undoubtedly still be confused about details after reading it, so
16
+
feel free to email philip@pgbovine.net if you have questions.
14
17
15
18
And please excuse the sloppy writing; I'm not trying to win any style awards here :)
16
19
@@ -36,7 +39,7 @@ btw, using the default configuration, http://localhost:8080/ is actually loading
36
39
(See `v3/pythontutor.py` for details.)
37
40
38
41
The benefit of running OPT locally is that you can test all changes without going online. So even
39
-
if you're eventually going to deploy NOT on Google App Engine, it makes good sense to install locally
42
+
if you're eventually going to deploy on something other than Google App Engine, it still makes sense to install locally
40
43
for development and testing. The main caveat here is that Google App Engine currently runs Python 2.7,
41
44
so you won't be able to test Python 3 locally this way.
42
45
@@ -46,45 +49,49 @@ so you won't be able to test Python 3 locally this way.
46
49
OPT consists of a pure-Python backend and an HTML/CSS/JavaScript frontend.
47
50
Here is a typical user interaction sequence:
48
51
49
-
1. The user types in Python code in the web-based text editor (powered by [CodeMirror](http://www.codemirror.net/)).
52
+
1. The user visits [visualize.html](http://pythontutor.com/visualize.html) and types in Python code in the web-based text editor.
50
53
2. The user hits the "Visualize execution" button.
51
54
3. The OPT frontend sends the user's Python code as a string to the backend by making an AJAX GET request.
52
-
4. The backend executes the Python code under the supervision of the Python [bdb](http://docs.python.org/library/bdb.html) debugger module, produces an execution trace, and send that trace back to the frontend in JSON format.
53
-
5. The frontend switches to a visualization pane, parses the execution trace, and renders the appropriate stack frames and heap objects.
54
-
6. When the user interacts with the frontend by stepping through execution points (forwards and backwards), the frontend renders the proper data structures WITHOUT making another call to the backend.
55
+
4. The backend executes the Python code under the supervision of the Python [bdb](http://docs.python.org/library/bdb.html) debugger, produces an execution trace, and send that trace back to the frontend in JSON format.
56
+
5. The frontend switches to a visualization display, parses the execution trace, and renders the appropriate stack frames, heap objects, and pointers.
57
+
6. When the user interacts with the frontend by stepping through execution points (forwards and backwards), the frontend renders the proper data structures **without** making another subsequent call to the backend.
55
58
56
59
All relevant files are located in `OnlinePythonTutor/v3/`, since v3 is the currently-active version.
57
60
58
61
The frontend consists of:
59
-
visualize.html
60
-
css/opt-frontend.css
61
-
js/opt-frontend.js
62
-
css/pytutor.css
63
-
js/pytutor.js
64
-
<abunchofauxiliarycssandjsfilessuchaslibraries>
62
+
```
63
+
visualize.html
64
+
css/opt-frontend.css
65
+
js/opt-frontend.js
66
+
css/pytutor.css
67
+
js/pytutor.js
68
+
<a bunch of auxiliary css and js files such as libraries>
69
+
```
65
70
66
-
`pytutor.[js|css]` contain the bulk of the OPT frontend code. In theory, if you set things up correctly,
67
-
you should be able to **embed** an OPT visualization into any webpage with one line of JavaScript that looks like:
71
+
`pytutor.[js|css]` contain the bulk of the OPT frontend code. In theory, you should be able to **embed** an
72
+
OPT visualization into any webpage with one line of JavaScript that looks like:
68
73
69
74
```javascript
70
75
var v =newExecutionVisualizer(domRoot, traceFromBackend, optionalParams);
71
76
```
72
77
73
78
Thus, the design of `pytutor.[js|css]` is meant to be as modular as possible, which means abstracting
74
-
everything in an `ExecutionVisualizer`object. This way, you can create multiple visualizer objects
75
-
to embed on the same webpage and not have them interfere with one another.
79
+
everything in an `ExecutionVisualizer`class. This way, you can create multiple visualizer objects
80
+
to embed on the same webpage without them interfering with one another.
76
81
77
82
`opt-frontend.[js|css]` contain code that is specific to the `visualize.html` page and doesn't make sense for, say,
78
-
embedding OPT visualizations into other types of webpages.
83
+
embedding OPT visualizations into other webpages.
79
84
80
85
The backend consists of:
86
+
```
87
+
pg_logger.py - the main entry point to the OPT backend
88
+
pg_encoder.py - encodes the trace format into JSON to send to frontend
89
+
generate_json_trace.py - script to test the backend independent of the frontend
90
+
app.yaml, pythontutor.py - files for deploying on Google App Engine
91
+
web_exec.py - example CGI script for deploying backend on CGI-enabled webservers
92
+
```
81
93
82
-
pg_logger.py : the main entry point for the OPT backend
83
-
pg_encoder.py : encodes the trace format into JSON to send to frontend
84
-
generate_json_trace.py : script to test the backend independent of the frontend
85
-
app.yaml and pythontutor.py : config files for Google App Engine
86
-
web_exec.py : example CGI script for deploying backend on CGI-enabled webservers
87
-
94
+
The backend works with both Python 2 and 3.
88
95
89
96
## Hacking on the backend
90
97
@@ -93,15 +100,21 @@ To modify the backend, you will mainly need to understand `pg_logger.py` and `pg
93
100
94
101
### Two quick tips for starters
95
102
103
+
Since the backend's details might change, rather than documenting every last detail, I'd rather equip you with
104
+
the knowledge needed to experiment with the code yourself, since that knowledge is less likely to get outdated.
105
+
96
106
First, run `generate_json_trace.py` to see the trace that the backend generates for a given input Python program.
97
-
This is the main way to do an "end-to-end" test on your backend modifications. For example, if you wrote a Python
98
-
program stored in `example.py`, then running:
107
+
This is the main way to do an "end-to-end" test on your backend modifications. For example, if you want the backend
108
+
to process a Python program stored in `example.py`, then run:
99
109
100
-
python generate_json_trace.py example.py
101
-
102
-
will print a JSON-formatted execution trace to stdout. This is exactly what the backend sends to the frontend.
110
+
```
111
+
python generate_json_trace.py example.py
112
+
```
113
+
114
+
Doing so will print a JSON-formatted execution trace to stdout.
115
+
This data is exactly what the backend sends to the frontend.
103
116
(Actually not quite: the sent trace is actually compressed to eliminate all extraneous spaces and newlines.
104
-
But for testing, I've made the trace more human-readable.)
117
+
But for testing purposes, I've made the trace more human-readable.)
105
118
106
119
Second, when you're "print debugging" in the backend, you can't simply print to stdout, since `pg_logger.py`
107
120
*redirects* stdout to a buffer. Instead, you need to write all of your print statements as:
0 commit comments