Jupyter4Science / scipy23-jupyter-web-app-tutorial

A 4-hour tutorial entitled "How the Little Jupyter Notebook Became a Web App: Managing Increasing Complexity with nbdev" presented at SciPy 2023 in Austin, TX.
https://cfp.scipy.org/2023/talk/NFWZXD/
Apache License 2.0
6 stars 4 forks source link

%load answers #23

Open nicole-brewer opened 1 year ago

nicole-brewer commented 1 year ago

For each notebook:

Before the tutorial:

nicole-brewer commented 1 year ago

Okay, instead of making this an issue for every notebook, I'm going to just do something more centralized here. I need to make a script that does a lot of this for me. One goal is to pull in answers to a cell when the user gets stuck. I can see two ways to do this...

  1. Keep two copies of every notebook. One that is hidden and one that isn't. Create cell magic that pulls in the answer from the answer notebook.
  2. Don't have two copies of every notebook. Instead, have two copies of every python file, one of which is an answer key. Use cell magic to pull in the answer from the answer key. Load was giving me trouble because I can't put a comment to the right of it. But if I made my own cell magic, I could.

The part I haven't figured out here is how to deal with editing notebooks.

nicole-brewer commented 1 year ago

Okay so I'm going with option two. I wrote an ipython magic that pulls in code chunks from the exported python file with filepath and cell number parameters. I decided to have the answers (for any part of the tutorial, doesn't have to just be dashboard) go in a key directory. I was going to have it be a hidden folder, but that's not agreeable with the way python imports work. I was thinking about putting the key folder inside the dashboard folder, but that's a bad idea because I don't want bad things to happen if we delete the dashboard folder altogether for some reason

nicole-brewer commented 1 year ago

So perhaps I've established somewhere that the ipython magic that pulls chunks from the exported python file can only do so on exported cells, which is an oversight on my part. What about cells that aren't exported? I was thinking I'd have to scrap the old magic and write a new one that writes all the answers to files, but actually, the old way of doing it is still needed. If a user has trouble with an old notebook, they can import the module from the key directory. So it's not like I wasted work there. But I also need a solution for pulling in answers from cells that weren't exported. So I need to write another magic function that exports answers to a different directory in key. I can write this function so that it leaves in the comments to the right hand side. But when to do this. Could make it an option to leave in the answer until a flag is used. Only then does the code get stripped away leaving the comments. A commented out command with %load or %answer needs to be added before the first line. Probably %answer to keep it consistent. This means I need to add an option to answer that doesn't take a cell number, just a file. The command for exporting the answer could be %%export --hold could prevent the answer being replaced with the comments. This will be a little ugly, because the imported answer needs to have the commented out code on it still in case the code gets exported but then needs to be imported to get changed again. But that's a small thing.