Commit 93bf6051 authored by Douglas's avatar Douglas Committed by Ivan Tyagov

erp5_data_notebook: documentation about environment object and astor egg added

@Tyagov this is the slapos part of erp5!131. It includes:

- Documentation on top on each Jupyter notebook about why and how we use the
environment object.

- astor egg, used to convert abstract syntax tree objects back to source
code.

/reviewed-on !76
parent d2a5902d
...@@ -17,6 +17,7 @@ parts = ...@@ -17,6 +17,7 @@ parts =
; ipython notebook component ; ipython notebook component
eggs += eggs +=
requests requests
astor
${scipy:egg} ${scipy:egg}
${pandas:egg} ${pandas:egg}
${scikit-learn:egg} ${scikit-learn:egg}
...@@ -52,7 +53,7 @@ md5sum = ab6e78ea20855e07d388b5b86d1770fe ...@@ -52,7 +53,7 @@ md5sum = ab6e78ea20855e07d388b5b86d1770fe
[custom-js] [custom-js]
<= download-file-base <= download-file-base
filename = custom.js.jinja filename = custom.js.jinja
md5sum = 0e8262d04a6dafbc1b77d95aea2192bc md5sum = a851a68667a4e676cfa86b34a86b4239
[instance-jupyter] [instance-jupyter]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
...@@ -176,3 +177,5 @@ pickleshare = 0.5 ...@@ -176,3 +177,5 @@ pickleshare = 0.5
# ipython==4.0.0 # ipython==4.0.0
# notebook==4.0.6 # notebook==4.0.6
traitlets = 4.1.0b1 traitlets = 4.1.0b1
astor = 0.5
...@@ -86,7 +86,7 @@ $([IPython.events]).on('notebook_loaded.Notebook', function(){ ...@@ -86,7 +86,7 @@ $([IPython.events]).on('notebook_loaded.Notebook', function(){
var display_text="<div class='output_subarea output_text output_result'>\ var display_text="<div class='output_subarea output_text output_result'>\
<pre>Follow these steps to customize your notebook with ERP5 kernel :-</br>\ <pre>Follow these steps to customize your notebook with ERP5 kernel :-</br>\
1. Add <b>%erp5_url &lt;your_erp5_url&gt;/erp5/Base_executeJupyter</b>.</br>\ 1. Add <b>%erp5_url &lt;your_erp5_url&gt;/erp5/Base_executeJupyter</b>.</br>\
Make sure you have 'erp5_data_notebook' business template installed in your erp5</br>\ Make sure you have 'erp5_data_notebook' business template installed in your ERP5</br>\
2. <b>%notebook_set_reference &lt;your_notebook_refernce&gt;</b></br>\ 2. <b>%notebook_set_reference &lt;your_notebook_refernce&gt;</b></br>\
It would be better to set the reference to match with erp5 reference pattern.</br>\ It would be better to set the reference to match with erp5 reference pattern.</br>\
3. <b>%erp5_user &lt;your_erp5_username&gt;</b></br>\ 3. <b>%erp5_user &lt;your_erp5_username&gt;</b></br>\
...@@ -96,8 +96,26 @@ $([IPython.events]).on('notebook_loaded.Notebook', function(){ ...@@ -96,8 +96,26 @@ $([IPython.events]).on('notebook_loaded.Notebook', function(){
<b>%my_notebooks</b> -This is used to display all the notebooks created by the specific user.</br>\ <b>%my_notebooks</b> -This is used to display all the notebooks created by the specific user.</br>\
NOTE: Do not dynamically alter imported module objects as they are not being saved in DB, </br>\ NOTE: Do not dynamically alter imported module objects as they are not being saved in DB, </br>\
so changes to them would be disregarded and would throw an error.</br>\ so changes to them would be disregarded and would throw an error.</br>\
<p><u>About classes, functions and global state on modules:</u></p>\
Your code is going to be executed by ERP5, which can have many nodes </br>\
and there is no guarantee that your code is always going to be executed by the same server.</br>\
This means that objects which cannot be stored in the ZODB, like functions, classes and modules </br>\
won't be available across nodes. To solve this issue, you need to use a special object </br>\
called 'environment' to store your global setup. This object was designed to hold global </br>\
state and restore it for each code cell. Example:</br></br>\
<b>def my_setup():</br>\
# import modules, define functions and classes</br>\
# and set global state on modules</br>\
# return dict of variables to be available in code cells</br>\
{'my_var': 1}</br>\
environment.define(my_setup, 'my custom setup')</b></br></br>\
After you execute this cell, the <b>my_setup</b> function will run before each of the</br>\
following cells and the <b>my_var</b> variable will be created and set to 1.</br></br>\
<b>WARNING:</b> it is not recommended to have too many setup functions in the environment, </br>\
because they will be executed in every code cell and can cause a substantial slow down.\
</pre></div>"; </pre></div>";
if (kernelname=="erp5"){ if (kernelname=="erp5"){
$('div#notebook-container').prepend(display_text); $('div#notebook-container').prepend(display_text);
} }
}); });
\ No newline at end of file
\ No newline at end of file
...@@ -19,6 +19,7 @@ initialization = ...@@ -19,6 +19,7 @@ initialization =
extra-paths += extra-paths +=
${wendelin:location} ${wendelin:location}
eggs += eggs +=
astor
${scipy:egg} ${scipy:egg}
${msgpack-python:egg} ${msgpack-python:egg}
${wendelin.core:egg} ${wendelin.core:egg}
......
...@@ -483,6 +483,7 @@ eggs = ...@@ -483,6 +483,7 @@ eggs =
${pycrypto-python:egg} ${pycrypto-python:egg}
${scikit-learn:egg} ${scikit-learn:egg}
lock_file lock_file
astor
PyStemmer PyStemmer
PyXML PyXML
Pympler Pympler
......
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