Commit f807b0b6 authored by Ayush Tiwari's avatar Ayush Tiwari

erp5_data_notebook: Refactor jupyter_compile to only return the local...

erp5_data_notebook: Refactor jupyter_compile to only return the local variables which are added after code execution
parent 8e7fe93f
...@@ -16,7 +16,10 @@ def Base_compileJupyterCode(self, jupyter_code, old_local_variable_dict): ...@@ -16,7 +16,10 @@ def Base_compileJupyterCode(self, jupyter_code, old_local_variable_dict):
# Other way would be to use all the globals variables instead of just an empty # Other way would be to use all the globals variables instead of just an empty
# dictionary, but that might hamper the speed of exec or eval. # dictionary, but that might hamper the speed of exec or eval.
# Something like -- g = globals(); g['context'] = self; # Something like -- g = globals(); g['context'] = self;
g = globals() g = {}
# Saving the initial globals dict so as to compare it after code execution
globals_dict = globals()
g['context'] = self g['context'] = self
result_string = None result_string = None
ename, evalue, tb_list = None, None, None ename, evalue, tb_list = None, None, None
...@@ -66,9 +69,16 @@ def Base_compileJupyterCode(self, jupyter_code, old_local_variable_dict): ...@@ -66,9 +69,16 @@ def Base_compileJupyterCode(self, jupyter_code, old_local_variable_dict):
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
# Difference between the globals variable before and after exec/eval so that
# we don't have to save unnecessary variables in database which might or might
# not be picklabale
local_variable_dict = old_local_variable_dict
local_variable_dict_new = {key: val for key, val in g.items() if key not in globals_dict.keys()}
local_variable_dict.update(local_variable_dict_new)
result = { result = {
'result_string': result_string, 'result_string': result_string,
'local_variable_dict': g, 'local_variable_dict': local_variable_dict,
'status': status, 'status': status,
'evalue': evalue, 'evalue': evalue,
'ename': ename, 'ename': ename,
......
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple>
<string>W: 42, 18: Use of eval (eval-used)</string> <string>W: 45, 18: Use of eval (eval-used)</string>
<string>W: 55, 6: Use of exec (exec-used)</string> <string>W: 58, 6: Use of exec (exec-used)</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment