Nbdev_export() "AssertionError: "

I am trying to convert a library with nested dir structure to nbdev.

As the first cell I have:

#| default_exp utility.affine_transformations

However, when I run the last cell:

from nbdev import *

I get an assertion error (pasted below). The error suggest something about level being not equal to 0. Unfortunately, I am not able to decipher why. Would someone have an idea on how to debug this?

However, if I copy the same notebook into nbdev-hello-world library that I created in the tutorial, then the conversion works without a problem. I compared the settings.ini but did not find anything pointing to the problem.

AssertionError                            Traceback (most recent call last)
Cell In[12], line 3
      1 #| hide
      2 from nbdev import *
----> 3 nbdev_export()

File ~/mambaforge/lib/python3.10/site-packages/fastcore/script.py:110, in call_parse.<locals>._f(*args, **kwargs)
    107 @wraps(func)
    108 def _f(*args, **kwargs):
    109     mod = inspect.getmodule(inspect.currentframe().f_back)
--> 110     if not mod: return func(*args, **kwargs)
    111     if not SCRIPT_INFO.func and mod.__name__=="__main__": SCRIPT_INFO.func = func.__name__
    112     if len(sys.argv)>1 and sys.argv[1]=='': sys.argv.pop(1)

File ~/mambaforge/lib/python3.10/site-packages/nbdev/doclinks.py:138, in nbdev_export(path, **kwargs)
    136 if os.environ.get('IN_TEST',0): return
    137 files = nbglob(path=path, as_path=True, **kwargs).sorted('name')
--> 138 for f in files: nb_export(f)
    139 add_init(get_config().lib_path)
    140 _build_modidx()

File ~/mambaforge/lib/python3.10/site-packages/nbdev/export.py:59, in nb_export(nbname, lib_path, procs, debug, mod_maker, name)
     57     return
     58 mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')
---> 59 mm.make(cells, all_cells, lib_path=lib_path)

File ~/mambaforge/lib/python3.10/site-packages/nbdev/maker.py:195, in make(self, cells, all_cells, lib_path)
    193     if not lib_path: lib_path = get_config().lib_path
    194     mod_dir = os.path.relpath(self.fname.parent, Path(lib_path).parent)
--> 195     _import2relative(all_cells, mod_dir)
    196 if not self.is_new: return self._make_exists(cells, all_cells)
    198 self.fname.parent.mkdir(exist_ok=True, parents=True)

File ~/mambaforge/lib/python3.10/site-packages/nbdev/maker.py:174, in _import2relative(cells, lib_name)
    172 "Converts `cells` to use `import2relative` based on `lib_name`"
    173 if lib_name is None: lib_name = get_config().lib_name
--> 174 for cell in cells: cell.import2relative(lib_name)

File ~/mambaforge/lib/python3.10/site-packages/nbdev/maker.py:158, in import2relative(cell, libname)
    156 @patch
    157 def import2relative(cell:NbCell, libname):
--> 158     src = update_import(cell.source, cell.parsed_(), libname)
    159     if src: cell.set_source(src)

File ~/mambaforge/lib/python3.10/site-packages/nbdev/maker.py:149, in update_import(source, tree, libname, f)
    147 src = source.splitlines(True)
    148 for imp in imps:
--> 149     nmod = f(imp.module, libname, imp.level)
    150     lin = imp.lineno-1
    151     sec = src[lin][imp.col_offset:imp.end_col_offset]

File ~/mambaforge/lib/python3.10/site-packages/nbdev/maker.py:114, in relative_import(name, fname, level)
    112 def relative_import(name, fname, level=0):
    113     "Convert a module `name` to a name relative to `fname`"
--> 114     assert not level
    115     sname = name.replace('.','/')
    116     if not(os.path.commonpath([sname,fname])): return name


I have found that the reason for the error was a problem with relative imports in the other notebooks of the project. After fixing some of them the nbdev_export() worked. I have falsely thought that if I use nbdev_export() in one notebook, then the export will only affect that and only that notebook. The error is unfortunately not very informative. Also, strange that I did not have to fix the relative imports in all the notebooks for nbdev_export() to start working properly.