-
Notifications
You must be signed in to change notification settings - Fork 79
Custom displayhook #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom displayhook #7
Conversation
4f8d85e to
f18e7b8
Compare
|
|
||
| builtins.attr("exec")(compiled_code, py::globals()); | ||
| builtins.attr("exec")(compiled_interactive_code, py::globals()); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Carreau would you mind telling me what you think about that code? What I want to do is display the last expression of the cell (e.g. "Out [3]: ...")
What I do is:
- I use the AST to extract the last expression of the cell
- I execute the remaining expressions normally
- I execute the last expression in an Interactive way
Do you think it's how it should be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the same as what we do in IPython. The smaller difference is that we loop of the n-1 non-final statement manually. Not sure it makes a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note we also have other mode where
- all the top-level expressions trigger display
- the last assigment also trigger display
- Async-mode
But those can be done later or not at all I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your reply! When are those modes used? Is it a command line option? (I can't find it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are both CLI and dynamic options. Rarely used. So I wouldn't worry about theses yet.
| m_displayhook.attr("add_hook")(publish_display); | ||
|
|
||
| sys.attr("displayhook") = m_displayhook; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Carreau And here I overwrite sys.displayhook which is called when the interactive code is executed, my displayhook publish the execution result to clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If we do not do this extra check, and if the last statement is for
example:
```python
for x in range(10):
x
```
the display hook will be triggered 10 times, while it shouldn't be
triggered at all
xeus-python v0.1.4
Add Matplotlib to the env

First simple version for display of the last expression of cells (objects are first converted to string, then displayed)