Nbdev v2 launched

Is it possible to patch a static method to a class?

Try it and see how it goes? I don’t see any fundamental reason it shouldn’t be possible.

Many thanks to the fastai team for nbdev2 - looks and feels awesome. I have faced two issues in migrating - any help is appreciated:

  1. there is no longer a link to source code for functions and classes
  2. the automagic backtick links to other modules/functions/classes no longer work.

Are there any pointers there that could help? Sorry if I missed anything.

EDIT:
3) the Google Cola badges no longer appear on any page

Hi @dkgaraujo . Unfortunately you haven’t provided enough information for us to know how to help you. If we don’t have enough information to reproduce your problem, we can’t help you fix it. Could you let us know what version of nbdev, fastcore, and execnb you’re using, what operating system you’re on, what you’ve done exactly, and what happened when you did that? Can you provided a minimum reproducible example in a public repo that we could run to see your problem?

We don’t have a Google Colab badge feature in v2 at the moment.

@jeremy sorry, I should have been more specific. I tried, and it didn’t work.

This works:

#|export
class ClassName:
    def __init__(self):
        pass

@staticmethod    
  def func_name(x):
      return x^2

This does not work:

#|export
class ClassName:
    def __init__(self):
        pass

@staticmethod    
@patch_to(ClassName)
def func_name(x):
    return x^2

I might be missing something, but all the fastcore doc patch examples use non-static methods.

1 Like

Just fixed this in fix exporting `patch_to` which is decorated with `staticmethod` by seeM · Pull Request #1100 · fastai/nbdev · GitHub. Could you please try again with latest master?

2 Likes

Thanks for replying, @Jeremy. And sorry for the lack of info - I thought a more fully-fledged reprex would be something more for the repo Issues page and here something more informal, but of course I understand why it would be helpful.
I was able to solve the issues in the meantime. In case it’s helpful to anyone, I’m writing my setting and what I did below (no public repo to share unfortunately). Thanks also for the response on the Google Colab badges. I judge by the “at the moment” in our reply that this is forthcoming at some point - please do let us all know if there is something the community could help with in this.

Going back to my original issue:
Setting
macOS 12.6
python 3.10.2
nbdev v.2.3.4
fastcore 1.5.27
execnb 0.1.3

Steps

  • Ported an nbdev1 repo exactly as shown in nbdev - nbdev1 Migration
  • cleaned any missing changes (eg, removed nbdev1 #collapse_output directives, which were not automatically ported in my case)
  • executed nbdev_preview

The resulting website running locally presented the two issues I mentioned.

What I did to solve it was incredibly simple. After all the steps in the migration tutorial above, I also:

  • went through all of my pages to ensure that no import clause was in the same cell as normal code
  • then I ran nbdev_export and nbdev_docs in that order

And it worked!

Separately, let me take the chance to report the following:

  • I’m facing the issue described here. export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES or running nbdev_test --n_workers 0 does the trick for me.
  • one inconsequential oddity is that at least in the way that Quarto is rendering my markdowns, I now have to include a carriage return before every bullet point, otherwise it doesn’t read as a bullet point list, but rather as simple asterisks.

Thanks again for your attention to this, and of course for having created this amazing tool in the first place!

1 Like

Assume I have an image.png file under the resources folder: resources/image.png

I use the following on a markdown cell to display the picture on the notebook, which works great.

![](resources/image.png)

But now, when nbdev generates the docs, I get /resources/image.png (404: Not Found), and the image is not displayed locally via nbdev_preview or in the GitHub pages.

This used to work in previous versions. Any idea what changed?

Why is the error message saying it is located at the root?

Good question; I don’t know. But this is the message I get when using nbdev_preview. See the screenshot attached:
nbdev_preview_fail

Are you sure that there isn’t a link to the image somewhere with a leading slash?

I just searched. The link to the notebook: https://raw.githubusercontent.com/thigm85/learntorank/main/011_passage_uncertainty_evaluation.ipynb

Are you sure its from that notebook? Can you make a minimal version of your project that isolates this error and share that?

I am pretty sure it comes from that notebook as it is the only file that contains passage_uncertainty.png as you can see below:

grep --exclude-dir=data -r "passage_uncertainty.png" *
011_passage_uncertainty_evaluation.ipynb:    "![](resources/passage/passage_uncertainty.png)"

But I can create a minimal version to make it easier to see.

Is this enough as a minimal example: GitHub - thigm85/learntorank at tgm/minimal-version?

There is only an empty index.ipynb and the offending notebook with only one cell, including the passage_uncertainty.png file.

@tgmstat thanks! This is indeed a bug. For now, can you move your notebooks out of the root of the repo and put it in a nbs/ folder and change the appropriate setting settings.ini called nbs_folder accordingly?

We are tracking this bug here: When notebooks are in the root, assets are not being copied over for site rendering · Issue #1114 · fastai/nbdev · GitHub

1 Like

I think the issue might be that recursive=False in settings.ini, which excludes any sub-directories from being copied. Could you try setting it to True?

@hamelsmu should we set recursive=True as the default?

Thanks for the timestamps, Daniel! This is super useful! :slight_smile:

2 Likes

Hi guys, how do I add a folder of notebooks to be nbdev_previewed?

Here is what my project folder look like:

Previously, I felt like nbdev automatically display the folder for me in the sidebar when I nbdev_preview, and I have the sidebar.yml of my earlier version project here:

but now my current project’s sidebar.yml does not include any folder for me, and looks like this:

What should I do to include folders of notebooks into the sidebar for preview? Thanks a lot!