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

Converting demos from py to ipynb #34

Open
ddundo opened this issue Aug 16, 2024 · 3 comments
Open

Converting demos from py to ipynb #34

ddundo opened this issue Aug 16, 2024 · 3 comments
Assignees
Labels
docsprint To be addressed in next documentation sprint documentation Improvements or additions to documentation

Comments

@ddundo
Copy link
Member

ddundo commented Aug 16, 2024

Further to our discussion this morning, I converted animate's simple_metric.py demo to a format suitable for converting it to a Jupyter notebook using jupytext. This is very simple - I just had to add # %% [markdown] before text blocks and # %% before code blocks. This is actually standard formatting - I noticed now that VS code automatically recognised it in the .py script and asked me to run each of these partition interactively. So that's nice too :)

So my idea was to keep demos in this .py format and then only convert them to notebooks when building the website. This can be easily done in command line or in a python script, e.g.:

import jupytext

nb = jupytext.read('simple_metric.py')
jupytext.write(nb, 'simple_metric.ipynb', fmt='.ipynb')

and then the notebook can be executed with jupytext --execute simple_metric.ipynb which runs the code and produces figures in the notebook, etc.

Here is the demo script if you'd like to test it out: https://gist.github.com/ddundo/32fc425e0e1de246b06b6cf09d903818

@ddundo ddundo added the documentation Improvements or additions to documentation label Aug 16, 2024
@ddundo
Copy link
Member Author

ddundo commented Aug 19, 2024

Actually, the # %% [markdown] labels aren't necessary and neither are the code cell labels # %%. Although without the code labels, each empty line in the .py script would mean end of the cell. So e.g.

a = 1

b = 2

would be 2 cells in the notebook. Maybe this could be modified in the jupytext config... not sure.

There are also some jupytext settings for sphinx/rst compatibility. I didn't test this out. But potentially we could keep the demos exactly as they are.

I can test all of this out if we decide to go with the notebooks idea :)

@jwallwork23
Copy link
Member

Sounds good, thanks! Happy for you to do this.

@jwallwork23
Copy link
Member

jwallwork23 commented Nov 8, 2024

@jwallwork23 jwallwork23 added the docsprint To be addressed in next documentation sprint label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docsprint To be addressed in next documentation sprint documentation Improvements or additions to documentation
Projects
Development

No branches or pull requests

2 participants