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:
- there is no longer a link to source code for functions and classes
- 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.
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?
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
andnbdev_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 runningnbdev_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!
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:
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
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!
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!