GitHub user agoodm reopened a pull request:

    https://github.com/apache/zeppelin/pull/1439

    [ZEPPELIN-1423] Allow users to specify pre/post-execute callbacks for 
interpreters

    ### What is this PR for?
    One feature built-in to Jupyter's ipykernel that is currently missing in 
Zeppelin are pre/post-execute "callbacks". This PR allows for the possibility 
of entering code that is set to be executed by the interpreter before  the code 
entered into the paragraph (pre-execute) and after (post-execute). In addition 
to saving some users the effort of writing code that they want executed in 
every paragraph, this will help pave the way for more advanced features coming 
soon, like automatically displaying matplotlib figures without an explicit call 
to a `show()` function. See the JIRA issue for more details on this.
    
    The core implementation for this is primarily contained in a new class 
called `InterpreterCallbackRegistry` which heavily mimics the Angular Display 
system (eg, `AngularObjectRegistry`). While this interface alone should suffice 
for Interpreter maintainers on the Java/JVM side, I also thought it might be 
useful to expose the system directly to the users in their notebooks. Hence, an 
implementation that works with the spark and pyspark interpreters (via the 
`ZeppelinContext` class) is also included here.
    
    ### What type of PR is it?
    New Feature
    
    ### Todos
    * [x] - Add unit tests
    * [x] - Add new documentation
    
    (Maybe) - Find a better way to check for errors in pre-execute as this can 
brick the REPL (see more info below)
    
    ### What is the Jira issue?
    [ZEPPELIN-1423](https://issues.apache.org/jira/browse/ZEPPELIN-1423)
    
    ### How should this be tested?
    In a new note, add the following lines of code to a paragraph:
    ```python
    %pyspark
    z.registerCallback("post_exec", "print 'This code should be executed before 
the parapgraph code!'")
    z.registerCallback("pre_exec", "print 'This code should be executed after 
the paragraph code!'")
    ```
    
    Then run any other paragraph in the note containing some other code, eg
    ```python
    %pyspark
    print "This code should be entered into the paragraph by the user!"
    ```
    
    The output should be:
    ```
    This code should be executed before the paragraph code!
    This code should be entered into the paragraph by the user!
    This code should be executed after the paragraph code!
    ```
    
    You should also test out the other two methods (`getCallback()` and 
`unregisterCallback()`) specified in `ZeppelinContext.java`.
    
    One final caveat that should be mentioned: If there are errors in the code 
you specify for a pre-execute event, it will render the interpreter useless 
since the current implementation prepends the the code specified in `pre_exec` 
directly to the paragraph entered code before calling `interpret()`. The 
current workaround for this would be to either restart the interpreter group or 
call `unregisterCallback()` via a different REPL within the interpreter group 
(eg, `z.unregisterCallback("pre_exec", "pyspark")` from the spark interpreter). 
I would appreciate if anyone here would be willing to share any better 
approaches here.
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? Yes


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/agoodm/zeppelin ZEPPELIN-1423

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/zeppelin/pull/1439.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1439
    
----
commit eb26886986ec067a6104fa5de6f8bd99deb2ee1b
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-13T20:32:36Z

    First attempt at adding pre/post-execute callbacks
    
    Added support for pre/post-execute callback hooks to interpreters

commit f50eccaa56889f0feda4a48a2222226df6596d53
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-19T22:48:34Z

    Added support for user defined callbacks in spark/pyspark interpreters

commit 1594dfbcb2df805705143df913e9a5eb63c6be18
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-20T18:14:47Z

    Deleted unused files

commit e1ba95b4e8a8c46ac8f685d64ff1cd59ea9c71c1
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-20T18:16:28Z

    Regenerated thrift files using v0.9.2

commit b8265fea798c92a411324a2eb3a73f245b8e50ee
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-20T20:13:33Z

    Added unit tests for InterpreterCallbackRegistry

commit 3e7c8520786190891e70762828406f5ff7b431b0
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-20T21:02:19Z

    Cleaned up ZeppelinContext callback registry API

commit 5822ecd85ec19c156ee7722fcab90dac675e94dd
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-20T21:11:25Z

    Added documentation for callback registry system

commit ffc02f7f1e29d7e635ee7562d493fd305a45479a
Author: Alex Goodman <ago...@users.noreply.github.com>
Date:   2016-09-23T20:49:02Z

    Get default replName for callback registry from paragraph

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to