How to import all modules

I would like to import a bunch of modules using the “.all” for my library the same way it is working for fastai.

from fastai.data.all import *

How can I make this to work in my custom nbdev library? I’ve created a sub module but it does not seem to work by importing

from mynbdevlib.submodule.all import *

Instead I need to do this

from mynbdevlib.submodule.a import *
from mynbdevlib.submodule.b import *
etc..

Is the “all” notation something that nbdev supports or do I need to manually add my modules inside the all.py file for my autogenerated library?

best regards/
Daniel

all.py is a separate module inside each module(like Vision, Tabular, etc) in the fastai library. As the first chapter of the fastbook says, all is a module that contains all the necessary functions that you need to do anything related to the parent module (Like Vision, for example), so you don’t run into any import or recurse errors!
Cheers

1 Like

Thanks. But do I create the all.py my self or can it be generated using nbdev? I mean it always feels strange to manually add a file to an auto generated folder with files.

I don’t think there is any way to generate all.py with nbdev - so I’m pretty sure these are all created by hand for fastai.

You can see from https://github.com/fastai/fastai/blob/master/fastai/vision/all.py that all.py might need to import from outside the submodule - I can’t think of a way that nbdev could know what should be in all.py.

1 Like

thanks!
I solved it by creating a notebook that was exported as “all” and where I wrote all import statements.

1 Like