Skip to content

Conversation

@ozpau
Copy link

@ozpau ozpau commented Feb 5, 2025

Currently, if you just happen to include string nbdev_export( in your code cell, the whole cell will be silently ignored by nbdev_prepare, nbdev_test, nbdev_proc_nbs and nbdev_preview. If this cell happens to contain code that is exported or rendered in docs, it would result in the corresponding command failing with hard to decipher error.

I have removed the corresponding check from the nbdev code. I am not sure we need it, but I can make a version of this pull request that handles that more gracefully by injecting monkey patching code into notebooks, something like this:

k.run_cell('import nbdev\ndef noop(*args, **kw): pass\nnbdev.nbdev_export = noop')

I imagine the check was there to prevent infinite loops of nbdev_prepare calling itself, but this doesn't happen because the check is for nbdev_export and not for nbdev_prepare.

@hamelsmu
Copy link
Contributor

hamelsmu commented Feb 27, 2025

Can you give me an example use case where you need to have the string nbdev_export() in a code cell ? Is this something that is blocking you or more theoretical?

cc: @jph00

@ozpau
Copy link
Author

ozpau commented Feb 27, 2025

I have stumbled upon this while creating a tool to generate notebook from a template. https://github.com/ozpau/oztools/blob/main/nbs/api/02_nbd.ipynb see new_notebook_template.

It's not a blocker, since there's a simple solution to instead write something like 'nbdev.nbdev_e'+'xport()' in the code cell (and that's what nbdev uses internally).

But it was confusing at first because my notebook run, but exported code was wrong.

@jph00 jph00 closed this Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants