On Sun, Nov 3, 2013 at 10:41 AM, Christophe Bal <
proj...@gmail.com> wrote:
> Here are two a real questions. ;-) Let me talk please. :-)
>
> Can you give an example of code sent to `divide_into_blocks` ? It seems to
> be a mixture.
In any cloud.sagemath project, take a look at
$HOME/.sagemathcloud
and you'll find a couple of (BSD-licensed) Python files:
sage_server.py
sage_salvus.py
parsing.py
I wrote all of these from scratch for SMC. (As it is set up, it can
be painful to debug, unfortunately.)
sage_server.py -- a forking Sage session TCP server. It starts
up, imports the sage library, monkey patches it with functionality
mostly defined in sage_salvus.py, imports a bunch of stuff *in* the
sage library that is normally slow, e.g., graphics, and then waits for
connections. When a connection comes in, it forks off and the fork
handles that session. This is why you can open a new cloud.sagemath
sage worksheet and immediately draw plots, do integrals, etc., without
the significant startup time you might have on the command line or in
sagenb.
sage_salvus.py -- python parts of implementation of the SMC version
of a notebook interface, including a new implementation from scratch
of interact, of 3d graphics, etc.
parsing.py -- when you type code in a cell and press "shift-enter",
it is mostly parsed using functions defined here (and also there is
some relevant code in sage_server.py).
The function divide_into_blocks gets called when you type a bunch of
code into a cell and press shift-enter. Each individual block then
gets exec'd separately, one by one, with execution stopping when you
hit an error. This is why:
2+2
3+3
prints out both 4 and 6.
So to get to the point, open a new worksheet and type this in a cell
import parsing; reload(parsing)
then in another cell, type this
parsing.divide_into_blocks("""
for i in range(10):
# Here is a basic comment...
print i, "-->", i**2
""")
then see this output:
[[0, 0, 'for i in range(10):'], [1, 2, 'print i, "-->", i**2']]
This is wrong, it should be one single block.
Now copy $HOME/.sagemathcloud/parsing.py to somewhere else, say your
home directory, then edit it, and do
sys.path.insert(0,os.environ['HOME']); import parsing; reload(parsing)
and the above (and other) tests.
If you have any trouble getting going with this, just share a project
with me and I can help.
>
> Another thing. Is `divide_into_blocks` which takes care of docstring ? If it
> is, I could also try to improve the printing of triple quoting via an
> optional parameter.
I don't understand the question yet.