Migrating from nbdev1 to nbdev2

Another thing I miss is having a link to the source code. Did I miss that somewhere or is this feature no longer available nbdev :frowning: ?

1 Like

I just added support for #|exports in master.

1 Like

So I installed nbdev from master using pip install -U git+https://github.com/fastai/nbdev.git@master and also changed

  • test.yml to read:
    python - m pip install -U git+https://github.com/fastai/nbdev.git@master.

  • and deploy.yml file to read:
    pip install -U git+https://github.com/fastai/nbdev.git@master.

However, when I build the docs locally with nbdev_preview it works as expected but it doesn’t work on Github Pages. That is, the dictionary gets exported to the module but it doesn’t show in the documentation on the website. Am I missing something (in the yaml files)?

is there any progress? Or should I rather construct a minimal example?

I would consider this a minimal example exposing the relative import failing from a subpackage: GitHub - michaelaye/nbdev-nested-lib: trying to create minimal example for nested lib with nbdev2

2 Likes

That’s super helpful, thanks Michael! It does look like a bug in nbdev, we’re tracking it here: Incorrect relative import from package root inside nested module · Issue #773 · fastai/nbdev · GitHub

1 Like

@michaelaye this is now fixed on master

3 Likes

great stuff, thanks!

My libname is clean-plot. So should my name be
export LIBNAME=clean-plot or export LIBNAME=clean_plot?

This one

Thank Jeremy! I was able to migrate to nbdev2, however the sidebar does not show up. I tried to build the sidebar with nbdev_sidebar --path nbs/ but nothing shows up.

My sidebar previously looked something like this,
image

Now, it looks something like this

Here is the link to the repo. deven367/clean_plot

You don’t need --path nbs fyi, since you have that defined in your settings.ini.

There’s no nbs/sidebar.yml in your repo. Therefore you don’t have a sidebar!

I tried running nbdev_sidebar from the root of the repo, it didn’t create a sidebar.yml file.

This is because you have custom_sidebar=True, so nbdev_sidebar will not autogenerate anything. If you want to bootstrap it so you can manually maintain it you can always do nbdev_sidebar --force however if you want it to autogenerate based on your notebooks, I suggest setting custom_sidebar=False

1 Like

Thanks Hamel. I got it to work.

I think I executed these commands, incorrectly.

I ended up ignoring the sidebar.yml file which is required, I guess.

Also, a follow up question, does nbdev2 still support the _not_finished convention for incomplete nbs?

You can name your notebook with a leading underscore and it will be ignored. This is the same as Quarto (not nbdev specific)

3 Likes

Hello,
Thanks for all the work around nbdev !
I have problems migrating an existing project. nbdev_export seems to work well, but shows an error:

  File "/home/jupyter-benoit/.cache/pypoetry/virtualenvs/leximpact-prepare-data-0Rkp9wuO-py3.8/lib/python3.8/site-packages/nbdev/maker.py", line 44, in read_var
    except SyntaxError: raise Exception('\n'.join(res)) from None
Exception: [
<list of all my functions without closing bracket>

But the big problem is that nbdev_preview fail even for my contributing that has no Python code in it : contributing.ipynb
Same problem if I copy this file in a fresh new nbdev v2 project.
EDIT: Ok, found a solution for that : `nbdev_preview` : nb_fmdict fail in some case · Issue #801 · fastai/nbdev · GitHub

My problem with notebook with code is it seems nbdev do not execute all the notebook code (as a loop with sleep do not slow it) but still execute some, as from nowhere import nothing make it fail. And somehow don’t find the right env as it fail with notebooks where running it with papermill works fine.

The first error with my project is due to the import of Seaborn that fail:

Preparing to preview
Traceback (most recent call last):
  File "/home/jupyter-benoit/.cache/pypoetry/virtualenvs/leximpact-prepare-data-0Rkp9wuO-py3.8/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3398, in run_code
[...]
  File "/home/jupyter-benoit/.cache/pypoetry/virtualenvs/leximpact-prepare-data-0Rkp9wuO-py3.8/lib/python3.8/site-packages/ipywidgets/__init__.py", line 40, in register_comm_target
    kernel.comm_manager.register_target('jupyter.widget', Widget.handle_comm_opened)
AttributeError: 'NoneType' object has no attribute 'comm_manager'
The above exception was the direct cause of the following exception:
[...]
  File "/home/jupyter-benoit/.cache/pypoetry/virtualenvs/leximpact-prepare-data-0Rkp9wuO-py3.8/lib/python3.8/site-packages/nbdev/processors.py", line 145, in __call__
    if self.k.exc: raise Exception(f'Error: cell {cell.idx_}:\n{cell.source}') from self.k.exc[1]
Exception: Error: cell 7:

I have no such problem with nbdev v1 (the site is here).

EDIT: After some test it seems that nbdev only execute cells with import keyword.
Using seaborn in a new project work.

Thanks for your help.

I finally make an existing notebook display with nbdev_preview, but I advise other users that there may be lot of work to migrate existing project as you may need to change code due to execution of block code with import if you forget to put them all in one cell.
The markdown rendering has also changed:

And new feature allowing Mermaid don’t seems to work yet : `nbdev_preview` Mermaid doesn't work · Issue #804 · fastai/nbdev · GitHub.

That being said, all the feature of Quarto are quite exiting and are worth migrating !