code_execution#

Attributes#

Functions#

execute_plt_test()

execute_code(final_code[, open_code, log])

Executes the code provided in the final_code string, returning True if the execution was successful,

run_subprocess(→ tuple[str | None, str])

Module Contents#

code_execution.plt_code = Multiline-String[source]#
Show Value
"""import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('Agg')
fig, ax = plt.subplots()

fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

ax.bar(fruits, counts, label=bar_labels, color=bar_colors)

ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')

plt.show()"""
code_execution.execute_plt_test()[source]#
code_execution.execute_code(final_code: str, open_code=False, log=print)[source]#

Executes the code provided in the final_code string, returning True if the execution was successful, of False if an unhandled exception was raised or the execution resulted in an error code being returned.

Current implementation writes the code to a temporary file and runs it using subprocess. This detail could change; this function is a wrapper around the current implementation. We may for example sandbox the code in a separate container, or use a different method of execution.

Parameters:
  • final_code – The code to be executed

  • open_code – For local development, if true will open the code in Visual Studio Code

  • log – A callable that will be used to log messages

code_execution.run_subprocess(command: list[str]) tuple[str | None, str][source]#