emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Proposal and RFC for improving ob-python


From: Kyle Meyer
Subject: Re: [O] Proposal and RFC for improving ob-python
Date: Thu, 10 Dec 2015 02:22:13 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Ondřej Grover <address@hidden> writes:

[...]

> The ob-ipython project tries to solve this hackiness in a different way by
> using the client-server infrastructure of IPython/Jupyter. That works quite
> well too, but my hope is that improving ob-python.el would also make it
> simpler to use IPython as the python REPL, relying only on the core of the
> Python language.

As I understand it (and if I'm remembering correctly), there are at
least three issues with ob-python sessions:

1. Shell prompt markers leak into the output.

2. Whitespace at the beginning of the output is swallowed.

3. Valid code that has indentation and spaces cannot be sent.

I think the first one is the race conditions that ob-ipython.el's README
refers to.

> It essentially boils down to implementing progn-like eval() function in
> Python which would return the result of the last statement if it is an
> expression.
[...]
> My proposal is to implement an equivalent of the following bash pseudo code
> for non session mode
>
> python -i << HEREDOC_END
> ret = block_eval("""
> <CODE BLOCK BODY>
> """)
> open(<TMP FILE or PIPE>).write(str(ret))
> HEREDOC_END

So for non-session code and value results, the main idea is to get rid
of the need for "return" at the end?

This seems useful to me.  Requiring a trailing "return", which is a
syntax error when the code is taken by itself, is a quirk of the
implementation (the code ends up being wrapped in a function to get the
return value).  Also, it would allow switching from ":results value" to
":results output" without needing to remove "return" in order to avoid a
syntax error.

> For session mode it would be even simpler, lines containing HEREDOC above
> would be dropped and the rest piped directly into the Python REPL.
>
> This also means that the 'org_babel_python_eoe' string indicator may not be
> necessary anymore because end of evaluation would be simply shown by a new
> line with the primary prompt appearing.

But what about when :results != value?  Doesn't your proposal only
handle returning the last value?

--
Kyle



reply via email to

[Prev in Thread] Current Thread [Next in Thread]