Proper Doc
Browse files
README.md
CHANGED
@@ -1,62 +1,12 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
*Expected Input*:
|
6 |
-
- `code`
|
7 |
-
- `language`
|
8 |
-
|
9 |
-
*Expected Output*:
|
10 |
-
- `interpreter_output`: output of the code interpreter
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
# Table of Contents
|
15 |
|
16 |
-
* [run](#run)
|
17 |
* [InterpreterAtomicFlow](#InterpreterAtomicFlow)
|
18 |
* [InterpreterAtomicFlow](#InterpreterAtomicFlow.InterpreterAtomicFlow)
|
19 |
* [set\_up\_flow\_state](#InterpreterAtomicFlow.InterpreterAtomicFlow.set_up_flow_state)
|
20 |
-
* [
|
21 |
-
* [code\_interpreters](#code_interpreters)
|
22 |
-
* [code\_interpreters.language\_map](#code_interpreters.language_map)
|
23 |
-
* [code\_interpreters.create\_code\_interpreter](#code_interpreters.create_code_interpreter)
|
24 |
-
* [code\_interpreters.languages.javascript](#code_interpreters.languages.javascript)
|
25 |
-
* [preprocess\_javascript](#code_interpreters.languages.javascript.preprocess_javascript)
|
26 |
-
* [code\_interpreters.languages.shell](#code_interpreters.languages.shell)
|
27 |
-
* [preprocess\_shell](#code_interpreters.languages.shell.preprocess_shell)
|
28 |
-
* [add\_active\_line\_prints](#code_interpreters.languages.shell.add_active_line_prints)
|
29 |
-
* [code\_interpreters.languages.python](#code_interpreters.languages.python)
|
30 |
-
* [preprocess\_python](#code_interpreters.languages.python.preprocess_python)
|
31 |
-
* [add\_active\_line\_prints](#code_interpreters.languages.python.add_active_line_prints)
|
32 |
-
* [AddLinePrints](#code_interpreters.languages.python.AddLinePrints)
|
33 |
-
* [insert\_print\_statement](#code_interpreters.languages.python.AddLinePrints.insert_print_statement)
|
34 |
-
* [process\_body](#code_interpreters.languages.python.AddLinePrints.process_body)
|
35 |
-
* [visit](#code_interpreters.languages.python.AddLinePrints.visit)
|
36 |
-
* [code\_interpreters.languages.html](#code_interpreters.languages.html)
|
37 |
-
* [code\_interpreters.languages.r](#code_interpreters.languages.r)
|
38 |
-
* [R](#code_interpreters.languages.r.R)
|
39 |
-
* [preprocess\_code](#code_interpreters.languages.r.R.preprocess_code)
|
40 |
-
* [code\_interpreters.languages.powershell](#code_interpreters.languages.powershell)
|
41 |
-
* [preprocess\_powershell](#code_interpreters.languages.powershell.preprocess_powershell)
|
42 |
-
* [add\_active\_line\_prints](#code_interpreters.languages.powershell.add_active_line_prints)
|
43 |
-
* [wrap\_in\_try\_catch](#code_interpreters.languages.powershell.wrap_in_try_catch)
|
44 |
-
* [code\_interpreters.languages](#code_interpreters.languages)
|
45 |
-
* [code\_interpreters.languages.applescript](#code_interpreters.languages.applescript)
|
46 |
-
* [AppleScript](#code_interpreters.languages.applescript.AppleScript)
|
47 |
-
* [preprocess\_code](#code_interpreters.languages.applescript.AppleScript.preprocess_code)
|
48 |
-
* [add\_active\_line\_indicators](#code_interpreters.languages.applescript.AppleScript.add_active_line_indicators)
|
49 |
-
* [detect\_active\_line](#code_interpreters.languages.applescript.AppleScript.detect_active_line)
|
50 |
-
* [detect\_end\_of\_execution](#code_interpreters.languages.applescript.AppleScript.detect_end_of_execution)
|
51 |
-
* [code\_interpreters.subprocess\_code\_interpreter](#code_interpreters.subprocess_code_interpreter)
|
52 |
-
* [SubprocessCodeInterpreter](#code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter)
|
53 |
-
* [preprocess\_code](#code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter.preprocess_code)
|
54 |
-
* [code\_interpreters.base\_code\_interpreter](#code_interpreters.base_code_interpreter)
|
55 |
-
* [BaseCodeInterpreter](#code_interpreters.base_code_interpreter.BaseCodeInterpreter)
|
56 |
-
|
57 |
-
<a id="run"></a>
|
58 |
-
|
59 |
-
# run
|
60 |
|
61 |
<a id="InterpreterAtomicFlow"></a>
|
62 |
|
@@ -71,13 +21,13 @@ class InterpreterAtomicFlow(AtomicFlow)
|
|
71 |
```
|
72 |
|
73 |
This flow is used to run the code passed from the caller.
|
74 |
-
|
75 |
*Input Interface*:
|
76 |
- `code`
|
77 |
- `language`
|
78 |
|
79 |
*Output Interface*:
|
80 |
- `interpreter_output`: output of the code interpreter
|
|
|
81 |
|
82 |
*Configuration Parameters*:
|
83 |
- None
|
@@ -96,290 +46,19 @@ is not compatible with that of the current version of aiflows(v.0.1.7).
|
|
96 |
def set_up_flow_state()
|
97 |
```
|
98 |
|
99 |
-
class-specific flow state: language and code,
|
100 |
-
which describes the programming language and the code to run.
|
101 |
-
|
102 |
-
<a id="__init__"></a>
|
103 |
-
|
104 |
-
# \_\_init\_\_
|
105 |
-
|
106 |
-
<a id="code_interpreters"></a>
|
107 |
-
|
108 |
-
# code\_interpreters
|
109 |
-
|
110 |
-
<a id="code_interpreters.language_map"></a>
|
111 |
-
|
112 |
-
# code\_interpreters.language\_map
|
113 |
-
|
114 |
-
<a id="code_interpreters.create_code_interpreter"></a>
|
115 |
-
|
116 |
-
# code\_interpreters.create\_code\_interpreter
|
117 |
-
|
118 |
-
<a id="code_interpreters.languages.javascript"></a>
|
119 |
-
|
120 |
-
# code\_interpreters.languages.javascript
|
121 |
-
|
122 |
-
<a id="code_interpreters.languages.javascript.preprocess_javascript"></a>
|
123 |
-
|
124 |
-
#### preprocess\_javascript
|
125 |
-
|
126 |
-
```python
|
127 |
-
def preprocess_javascript(code)
|
128 |
-
```
|
129 |
-
|
130 |
-
Add active line markers
|
131 |
-
Wrap in a try catch
|
132 |
-
Add end of execution marker
|
133 |
-
|
134 |
-
<a id="code_interpreters.languages.shell"></a>
|
135 |
-
|
136 |
-
# code\_interpreters.languages.shell
|
137 |
-
|
138 |
-
<a id="code_interpreters.languages.shell.preprocess_shell"></a>
|
139 |
-
|
140 |
-
#### preprocess\_shell
|
141 |
-
|
142 |
-
```python
|
143 |
-
def preprocess_shell(code)
|
144 |
-
```
|
145 |
-
|
146 |
-
Add active line markers
|
147 |
-
Wrap in a try except (trap in shell)
|
148 |
-
Add end of execution marker
|
149 |
-
|
150 |
-
<a id="code_interpreters.languages.shell.add_active_line_prints"></a>
|
151 |
-
|
152 |
-
#### add\_active\_line\_prints
|
153 |
-
|
154 |
-
```python
|
155 |
-
def add_active_line_prints(code)
|
156 |
-
```
|
157 |
-
|
158 |
-
Add echo statements indicating line numbers to a shell string.
|
159 |
-
|
160 |
-
<a id="code_interpreters.languages.python"></a>
|
161 |
-
|
162 |
-
# code\_interpreters.languages.python
|
163 |
-
|
164 |
-
<a id="code_interpreters.languages.python.preprocess_python"></a>
|
165 |
-
|
166 |
-
#### preprocess\_python
|
167 |
-
|
168 |
-
```python
|
169 |
-
def preprocess_python(code)
|
170 |
-
```
|
171 |
-
|
172 |
-
Add active line markers
|
173 |
-
Wrap in a try except
|
174 |
-
Add end of execution marker
|
175 |
-
|
176 |
-
<a id="code_interpreters.languages.python.add_active_line_prints"></a>
|
177 |
-
|
178 |
-
#### add\_active\_line\_prints
|
179 |
-
|
180 |
-
```python
|
181 |
-
def add_active_line_prints(code)
|
182 |
-
```
|
183 |
-
|
184 |
-
Add print statements indicating line numbers to a python string.
|
185 |
-
|
186 |
-
<a id="code_interpreters.languages.python.AddLinePrints"></a>
|
187 |
-
|
188 |
-
## AddLinePrints Objects
|
189 |
-
|
190 |
-
```python
|
191 |
-
class AddLinePrints(ast.NodeTransformer)
|
192 |
-
```
|
193 |
-
|
194 |
-
Transformer to insert print statements indicating the line number
|
195 |
-
before every executable line in the AST.
|
196 |
-
|
197 |
-
<a id="code_interpreters.languages.python.AddLinePrints.insert_print_statement"></a>
|
198 |
-
|
199 |
-
#### insert\_print\_statement
|
200 |
-
|
201 |
-
```python
|
202 |
-
def insert_print_statement(line_number)
|
203 |
-
```
|
204 |
-
|
205 |
-
Inserts a print statement for a given line number.
|
206 |
-
|
207 |
-
<a id="code_interpreters.languages.python.AddLinePrints.process_body"></a>
|
208 |
-
|
209 |
-
#### process\_body
|
210 |
-
|
211 |
-
```python
|
212 |
-
def process_body(body)
|
213 |
-
```
|
214 |
-
|
215 |
-
Processes a block of statements, adding print calls.
|
216 |
-
|
217 |
-
<a id="code_interpreters.languages.python.AddLinePrints.visit"></a>
|
218 |
-
|
219 |
-
#### visit
|
220 |
-
|
221 |
-
```python
|
222 |
-
def visit(node)
|
223 |
-
```
|
224 |
-
|
225 |
-
Overridden visit to transform nodes.
|
226 |
-
|
227 |
-
<a id="code_interpreters.languages.html"></a>
|
228 |
-
|
229 |
-
# code\_interpreters.languages.html
|
230 |
-
|
231 |
-
<a id="code_interpreters.languages.r"></a>
|
232 |
-
|
233 |
-
# code\_interpreters.languages.r
|
234 |
-
|
235 |
-
<a id="code_interpreters.languages.r.R"></a>
|
236 |
-
|
237 |
-
## R Objects
|
238 |
-
|
239 |
-
```python
|
240 |
-
class R(SubprocessCodeInterpreter)
|
241 |
-
```
|
242 |
-
|
243 |
-
<a id="code_interpreters.languages.r.R.preprocess_code"></a>
|
244 |
|
245 |
-
|
246 |
|
247 |
-
|
248 |
-
def preprocess_code(code)
|
249 |
-
```
|
250 |
-
|
251 |
-
Add active line markers
|
252 |
-
Wrap in a tryCatch for better error handling in R
|
253 |
-
Add end of execution marker
|
254 |
-
|
255 |
-
<a id="code_interpreters.languages.powershell"></a>
|
256 |
-
|
257 |
-
# code\_interpreters.languages.powershell
|
258 |
-
|
259 |
-
<a id="code_interpreters.languages.powershell.preprocess_powershell"></a>
|
260 |
-
|
261 |
-
#### preprocess\_powershell
|
262 |
|
263 |
```python
|
264 |
-
def
|
265 |
```
|
266 |
|
267 |
-
|
268 |
-
Wrap in try-catch block
|
269 |
-
Add end of execution marker
|
270 |
-
|
271 |
-
<a id="code_interpreters.languages.powershell.add_active_line_prints"></a>
|
272 |
-
|
273 |
-
#### add\_active\_line\_prints
|
274 |
-
|
275 |
-
```python
|
276 |
-
def add_active_line_prints(code)
|
277 |
-
```
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
<a id="code_interpreters.languages.powershell.wrap_in_try_catch"></a>
|
282 |
-
|
283 |
-
#### wrap\_in\_try\_catch
|
284 |
-
|
285 |
-
```python
|
286 |
-
def wrap_in_try_catch(code)
|
287 |
-
```
|
288 |
-
|
289 |
-
Wrap PowerShell code in a try-catch block to catch errors and display them.
|
290 |
-
|
291 |
-
<a id="code_interpreters.languages"></a>
|
292 |
-
|
293 |
-
# code\_interpreters.languages
|
294 |
-
|
295 |
-
<a id="code_interpreters.languages.applescript"></a>
|
296 |
-
|
297 |
-
# code\_interpreters.languages.applescript
|
298 |
-
|
299 |
-
<a id="code_interpreters.languages.applescript.AppleScript"></a>
|
300 |
-
|
301 |
-
## AppleScript Objects
|
302 |
-
|
303 |
-
```python
|
304 |
-
class AppleScript(SubprocessCodeInterpreter)
|
305 |
-
```
|
306 |
-
|
307 |
-
<a id="code_interpreters.languages.applescript.AppleScript.preprocess_code"></a>
|
308 |
-
|
309 |
-
#### preprocess\_code
|
310 |
-
|
311 |
-
```python
|
312 |
-
def preprocess_code(code)
|
313 |
-
```
|
314 |
-
|
315 |
-
Inserts an end_of_execution marker and adds active line indicators.
|
316 |
-
|
317 |
-
<a id="code_interpreters.languages.applescript.AppleScript.add_active_line_indicators"></a>
|
318 |
-
|
319 |
-
#### add\_active\_line\_indicators
|
320 |
-
|
321 |
-
```python
|
322 |
-
def add_active_line_indicators(code)
|
323 |
-
```
|
324 |
-
|
325 |
-
Adds log commands to indicate the active line of execution in the AppleScript.
|
326 |
-
|
327 |
-
<a id="code_interpreters.languages.applescript.AppleScript.detect_active_line"></a>
|
328 |
-
|
329 |
-
#### detect\_active\_line
|
330 |
-
|
331 |
-
```python
|
332 |
-
def detect_active_line(line)
|
333 |
-
```
|
334 |
-
|
335 |
-
Detects active line indicator in the output.
|
336 |
-
|
337 |
-
<a id="code_interpreters.languages.applescript.AppleScript.detect_end_of_execution"></a>
|
338 |
-
|
339 |
-
#### detect\_end\_of\_execution
|
340 |
-
|
341 |
-
```python
|
342 |
-
def detect_end_of_execution(line)
|
343 |
-
```
|
344 |
-
|
345 |
-
Detects end of execution marker in the output.
|
346 |
-
|
347 |
-
<a id="code_interpreters.subprocess_code_interpreter"></a>
|
348 |
-
|
349 |
-
# code\_interpreters.subprocess\_code\_interpreter
|
350 |
-
|
351 |
-
<a id="code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter"></a>
|
352 |
-
|
353 |
-
## SubprocessCodeInterpreter Objects
|
354 |
-
|
355 |
-
```python
|
356 |
-
class SubprocessCodeInterpreter(BaseCodeInterpreter)
|
357 |
-
```
|
358 |
-
|
359 |
-
<a id="code_interpreters.subprocess_code_interpreter.SubprocessCodeInterpreter.preprocess_code"></a>
|
360 |
-
|
361 |
-
#### preprocess\_code
|
362 |
-
|
363 |
-
```python
|
364 |
-
def preprocess_code(code)
|
365 |
-
```
|
366 |
-
|
367 |
-
This needs to insert an end_of_execution marker of some kind,
|
368 |
-
which can be detected by detect_end_of_execution.
|
369 |
-
|
370 |
-
Optionally, add active line markers for detect_active_line.
|
371 |
-
|
372 |
-
<a id="code_interpreters.base_code_interpreter"></a>
|
373 |
-
|
374 |
-
# code\_interpreters.base\_code\_interpreter
|
375 |
-
|
376 |
-
<a id="code_interpreters.base_code_interpreter.BaseCodeInterpreter"></a>
|
377 |
-
|
378 |
-
## BaseCodeInterpreter Objects
|
379 |
-
|
380 |
-
```python
|
381 |
-
class BaseCodeInterpreter()
|
382 |
-
```
|
383 |
|
384 |
-
|
385 |
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Table of Contents
|
5 |
|
|
|
6 |
* [InterpreterAtomicFlow](#InterpreterAtomicFlow)
|
7 |
* [InterpreterAtomicFlow](#InterpreterAtomicFlow.InterpreterAtomicFlow)
|
8 |
* [set\_up\_flow\_state](#InterpreterAtomicFlow.InterpreterAtomicFlow.set_up_flow_state)
|
9 |
+
* [run](#InterpreterAtomicFlow.InterpreterAtomicFlow.run)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
<a id="InterpreterAtomicFlow"></a>
|
12 |
|
|
|
21 |
```
|
22 |
|
23 |
This flow is used to run the code passed from the caller.
|
|
|
24 |
*Input Interface*:
|
25 |
- `code`
|
26 |
- `language`
|
27 |
|
28 |
*Output Interface*:
|
29 |
- `interpreter_output`: output of the code interpreter
|
30 |
+
- `code_runs`: whether the code runs successfully or not
|
31 |
|
32 |
*Configuration Parameters*:
|
33 |
- None
|
|
|
46 |
def set_up_flow_state()
|
47 |
```
|
48 |
|
49 |
+
class-specific flow state: language and code, which describes the programming language and the code to run.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
<a id="InterpreterAtomicFlow.InterpreterAtomicFlow.run"></a>
|
52 |
|
53 |
+
#### run
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
```python
|
56 |
+
def run(input_message: FlowMessage)
|
57 |
```
|
58 |
|
59 |
+
Run the code interpreter and return the output.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
**Arguments**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
- `input_message` (`FlowMessage`): The input message of the flow.
|
64 |
|