Skip to content
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

New Demo Mode #14

Closed
wants to merge 14 commits into from
Closed

Conversation

jankatins
Copy link
Member

Builds new notebook cells from the source of a function:

Example:

from ipyext.demo import demo
import ipyext.demo
# ---
demo(ipyext.demo)
# ---
demo(ipyext.demo.demo_example)

Closes: #13

Todo

This will either use a special module/function or a special URL at github as
the source for the next cells in a notebook.

Currently only the notebook version is available.

```
from ipyext.demo import notebook_demo
import ipyext.demo
notebook_demo(ipyext.demo)
notebook_demo(ipyext.demo.demo_example)
notebook_demo("<gh_matplotlib>/animation/")
notebook_demo("<gh_matplotlib>/animation/animate_decay.py")
```
This is a bit of a hack: the run_cell method is wrapped so that as
long as there is demo materialin a buffer, after the execution of the
cell, the next cell is set to the next demo material.
@jankatins
Copy link
Member Author

And now I have it working in the notebook and in ipython/qtconsole directly...

Also added matplotlib examples directly from github...

@juhasch
Copy link
Member

juhasch commented Nov 14, 2015

Nice!
Seems like notebook_demo is actutally demo ?

import ipyext.demo
from ipyext.demo import demo
demo(ipyext.demo.demo_example)

@jankatins
Copy link
Member Author

@juhasch yep... Renamed it after I got the ipython version running

@jankatins
Copy link
Member Author

Example and some demo of the demo mode: http://janschulz.github.io/demo_mode_ipython.html

@juhasch
Copy link
Member

juhasch commented Nov 14, 2015

Looks like it could be really useful.

@jankatins
Copy link
Member Author

Lets see if someone uses it... Having the function here and not in ipython is a little entry barrier :-/

@jankatins
Copy link
Member Author

Ok, IMO this is ready if travis gets green...

The only open todo is how to handle matplotlib examples, but I tested this and the current approach (aka not splitting it into multiple cells) is the only one which works due to the way they are written (comments with # and also because they expect that plt.show() is called in the end... It's even worse when you use %matplotlib inline as that produces one plot per cell :-()

If it is merged I will write demos for the current magics and then lets see if there are some other projects which want to write demos...

@jankatins
Copy link
Member Author

@juhasch a short review and if satisfied a merge would be nice :-)

@juhasch
Copy link
Member

juhasch commented Dec 10, 2015

Hmm,
tried to run tests and generate docs:

$ make
python autogen_api.py
python: can't open file 'autogen_api.py': [Errno 2] No such file or directory
make: *** [source/api/generated/gen.txt] Error 2

$ iptest3 ipyext

Test group: ipyext
E
======================================================================
ERROR: Failure: ImportError (No module named 'ipyext')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/users/juhasch/anaconda/lib/python3.5/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/users/juhasch/anaconda/lib/python3.5/site-packages/nose/loader.py", line 407, in loadTestsFromName
    module = resolve_name(addr.module)
  File "/users/juhasch/anaconda/lib/python3.5/site-packages/nose/util.py", line 312, in resolve_name
    module = __import__('.'.join(parts_copy))
ImportError: No module named 'ipyext'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

______________________________________________________________________
Test suite completed for system with the following information:
IPython version: 4.0.0
IPython commit : f534027 (installation)
IPython package: /users/juhasch/anaconda/lib/python3.5/site-packages/IPython
Python version : 3.5.0 |Anaconda 2.4.0 (x86_64)| (default, Oct 20 2015, 14:39:26) [GCC 4.2.1 (Apple Inc. build 5577)]
sys.executable : /users/juhasch/anaconda/bin/python
Platform       : Darwin-15.2.0-x86_64-i386-64bit

Tools and libraries available at test time:
   matplotlib pygments sqlite3

Status: ERROR - 1 out of 1 test groups failed (ipyext). Took 1.191s.

You may wish to rerun these, with:
  iptest ipyext

@jankatins
Copy link
Member Author

The first (make) should be fixed (I use make.cmd and RTD something else, so it wasn't catched,,,)

@jankatins
Copy link
Member Author

I can't reproduce the second problem. Could it be that you ran the tests in the docs subdir?

@juhasch
Copy link
Member

juhasch commented Dec 10, 2015

Adding the extension to PYTHONPATH let's me run the tests, but now they loop endlessly.
Will look into it tomorrow.

The doc is now generated fine.

@jankatins
Copy link
Member Author

there is also python tests.py but that should actualy be mostly the same as iptest ipyext.

print(_sum)

# This lets the `demo(ipyext.demo)` find only the `demo_example`.
# Only modues with that variable will display an overview of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type: modues->modules

@juhasch
Copy link
Member

juhasch commented Dec 20, 2015

Works fine in the notebook.
In the shell I get

In [4]: demo(ipyext.demo.demo_example)
<IPython.core.display.Javascript object>

Would it make sense to return a text representation in this case ?

@jankatins
Copy link
Member Author

In [4]: demo(ipyext.demo.demo_example)
IPython.core.display.Javascript object
Would it make sense to return a text representation in this case ?

You need to use demo(..., frontend="ipython")... I've actually no idea how to find out if a kernel is run in a notebook or in the qtconsole/console :-(

@juhasch
Copy link
Member

juhasch commented Dec 21, 2015

How about adding a __repr__() function ?
This should be called if _repr_javascript_ is not supported at the output.

@jankatins
Copy link
Member Author

Currently I use the normal JavaScript object... Hm, I would need to subclass that... ok, good idea, incoming... :-)

Curently I don't know any way to detect which frontent is used to
run a kernel, so if the demo is used in the defualt mode (=notebook)
make it at least output a helpful message if the frontend does not
understand the javscript code to insert the new cells.

Alos fix some typos...
@jankatins
Copy link
Member Author

done :-)

@jankatins jankatins closed this Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

demo mode
2 participants