Skip to content

demo mode #13

Open
Open
@jankatins

Description

@jankatins

R has the concept of a demo: https://stat.ethz.ch/R-manual/R-devel/library/utils/html/demo.html

It would be nice if we had a demo function, which would take a module/function and turn it into jupyter notebook cells:

from ipyext.demo import notebook_demo as demo # make it cristall clear that we only work in the notebook
import matplotlib.demo # something which isn't there yet :-)
demo(matplotlib.demo)
# shows available demos, as that's a module
demo(matplotlib.demo.gridspec)
# would add some cells below which are prefilled with examples how to use gridspec

Demo would:

  • make sure that the function takes no argument
  • get the source of a function and dedent it
  • split the source into blocks (code + comments with ^# Text -> comments with ^#text stay as comments in the code cell)
  • remove # from all comment lines
  • add the blocks to the notebook (see here for an example how to do that

Only problem when using functions: we can't use %magics in demos. Not sure if there is a workaround that, maybe treat #%magic ... as code, aka s/#%/%/ before splitting into blocks?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions