|
21 | 21 | from docutils.parsers.rst import Directive |
22 | 22 | from .pg_logger import exec_script_str_local |
23 | 23 | import json |
| 24 | +import six |
24 | 25 |
|
25 | 26 | def setup(app): |
26 | 27 | app.add_directive('codelens',Codelens) |
@@ -71,15 +72,20 @@ def setup(app): |
71 | 72 | var %(divid)s_vis; |
72 | 73 |
|
73 | 74 | $(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 | + } |
83 | 89 |
|
84 | 90 | }); |
85 | 91 |
|
@@ -147,7 +153,8 @@ class Codelens(Directive): |
147 | 153 | 'question':directives.unchanged, |
148 | 154 | 'correct':directives.unchanged, |
149 | 155 | 'feedback':directives.unchanged, |
150 | | - 'breakline':directives.nonnegative_int |
| 156 | + 'breakline':directives.nonnegative_int, |
| 157 | + 'python':directives.unchanged |
151 | 158 | } |
152 | 159 |
|
153 | 160 | has_content = True |
@@ -181,7 +188,11 @@ def js_var_finalizer(input_code, output_trace): |
181 | 188 | else: |
182 | 189 | self.options['embedded'] = 'false' |
183 | 190 |
|
184 | | - |
| 191 | + if 'python' not in self.options: |
| 192 | + if six.PY2: |
| 193 | + self.options['python'] = 'py2' |
| 194 | + else: |
| 195 | + self.options['python'] = 'py3' |
185 | 196 |
|
186 | 197 | if 'question' in self.options: |
187 | 198 | curTrace = exec_script_str_local(source, None, CUMULATIVE_MODE, None, raw_dict) |
|
0 commit comments