Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit d19461d

Browse files
committed
detect python version, protect page against visualier init failure
1 parent 8e98957 commit d19461d

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

runestone/codelens/visualizer.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from docutils.parsers.rst import Directive
2222
from .pg_logger import exec_script_str_local
2323
import json
24+
import six
2425

2526
def setup(app):
2627
app.add_directive('codelens',Codelens)
@@ -71,15 +72,20 @@ def setup(app):
7172
var %(divid)s_vis;
7273
7374
$(document).ready(function() {
74-
%(divid)s_vis = new ExecutionVisualizer('%(divid)s',%(divid)s_trace,
75-
{embeddedMode: %(embedded)s,
76-
verticalStack: false,
77-
heightChangeCallback: redrawAllVisualizerArrows,
78-
codeDivWidth: 500,
79-
lang : 'py3'
80-
});
81-
attachLoggers(%(divid)s_vis,'%(divid)s');
82-
allVisualizers.push(%(divid)s_vis);
75+
try {
76+
%(divid)s_vis = new ExecutionVisualizer('%(divid)s',%(divid)s_trace,
77+
{embeddedMode: %(embedded)s,
78+
verticalStack: false,
79+
heightChangeCallback: redrawAllVisualizerArrows,
80+
codeDivWidth: 500,
81+
lang : '%(python)s'
82+
});
83+
attachLoggers(%(divid)s_vis,'%(divid)s');
84+
allVisualizers.push(%(divid)s_vis);
85+
} catch (e) {
86+
console.log("Failed to Initialize CodeLens component %(divid)s_vis" );
87+
console.log(e.toString());
88+
}
8389
8490
});
8591
@@ -147,7 +153,8 @@ class Codelens(Directive):
147153
'question':directives.unchanged,
148154
'correct':directives.unchanged,
149155
'feedback':directives.unchanged,
150-
'breakline':directives.nonnegative_int
156+
'breakline':directives.nonnegative_int,
157+
'python':directives.unchanged
151158
}
152159

153160
has_content = True
@@ -181,7 +188,11 @@ def js_var_finalizer(input_code, output_trace):
181188
else:
182189
self.options['embedded'] = 'false'
183190

184-
191+
if 'python' not in self.options:
192+
if six.PY2:
193+
self.options['python'] = 'py2'
194+
else:
195+
self.options['python'] = 'py3'
185196

186197
if 'question' in self.options:
187198
curTrace = exec_script_str_local(source, None, CUMULATIVE_MODE, None, raw_dict)

0 commit comments

Comments
 (0)