I read all (most) of the documentation a few times, but couldn’t see clearly how all works out or what translates to what.
I have never built a python module before using
nbdev, so there is a knowledge gap I need to fill.
So here are my thoughts / experiences / lessons to self.
Running the notebook exports Python modules because of this cell.
Yes and no.
If you run that cell in the notebook, the corresponding module (and all other modules in that project) will be recreated, BUT only if the notebook file has changed. And with changed I mean ‘you change it and save the file’.
- Do changes
- Save file
- run the cell
- .py module file is recreated
I guess it applies
if the file hasn't changed from last time:
If you want to see the notebook and the corresponding module_name.py side by side in Jupyter.
module files in:
An update in module1.py file does not update what you see on the screen (right side) automatically.
You need to use this “Reload python file from disk”
Another option is to “Open in new browser tab” and press F5 to refresh it.
If you make changes in the Notebook that don’t make sense, running this from the Notebook won’t alert you that something is wrong.
Q: Will the module_name.py still be recreated?
A: Yes, even if there is something wrong in it.
Q: How do I know what is wrong?
A: One way is to run, on the console/terminal
nbdev_prepare while you are inside
Q: Is there a way to get notified within the Notebook?
A: Yes, run
nbdev_prepare from it.
WARNING! Read below why this is a
BAD TERRIBLE IDEA.
On the image you can see ‘what happens if’ for some cases.
Q: Do I need to use
#| export on import statements?
dumb vs no-dumb ( left: notebook, right: module.py )
- Do NOT assume that nbdev will figure out something for you.
- If you want it IN the module use
Example: import statements
This doesn’t make sense unless you also
More dumb stuff yet to come …
I have been trying to figure out why
nbdev would eat all the RAM I can give to it…
It turns out I left that line with
in the test notebook, which I added just for the photo and question above.
And whenever I run on the Terminal
it just never ends (eating all the RAM until the machine crashes).
Running one by one all the pieces:
I found out that
nbdev_test was the problem.
Then I used
# nbdev_test --do_print --n_workers 1
to find out on which Notebook it was … forever.
- Completed /home/jupyter/p/n1.ipynb
- Completed /home/jupyter/p/n2.ipynb
It runs all the cells in the Notebook, being the last one (here is the dumb idea) a call to itself (i.e. do it again, and again, and again …).
Don’t add the line
nbdev_test in the notebook.
I created this little table to help me separate the concepts of ‘what goes where’. Comments/corrections welcome.
---- DOCUMENTATION Visibility ---- cell/line/code/output/etc.
#|filter_stream <keyword> ...
---- Python MODULE specification/details ----
---- TESTING specification/details ----
Don’t put anything after
#| export # Goes to module
or you will get a
TypeError: _export_() takes from 2 to 3 positional arguments but 15 were given
I guess it because of this other export
which has a parameter.