From 38dca3a826ebb186da048e70322634f3a09418ba Mon Sep 17 00:00:00 2001 From: Scott Date: Fri, 29 Dec 2023 23:21:50 +0100 Subject: [PATCH] Fix sync for nested libraries --- nbdev/sync.py | 7 +++++-- nbs/api/06_sync.ipynb | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/nbdev/sync.py b/nbdev/sync.py index 7beeb5795..c76a62bfa 100644 --- a/nbdev/sync.py +++ b/nbdev/sync.py @@ -19,7 +19,7 @@ from fastcore.xtras import * import ast -from importlib import import_module +import importlib # %% ../nbs/api/06_sync.ipynb def absolute_import(name, fname, level): @@ -32,7 +32,10 @@ def absolute_import(name, fname, level): # %% ../nbs/api/06_sync.ipynb @functools.lru_cache(maxsize=None) def _mod_files(): - midx = import_module(f'{get_config().lib_path.name}._modidx') + midx_spec = importlib.util.spec_from_file_location("_modidx", get_config().lib_path / "_modidx.py") + midx = importlib.util.module_from_spec(midx_spec) + midx_spec.loader.exec_module(midx) + return L(files for mod in midx.d['syms'].values() for _,files in mod.values()).unique() # %% ../nbs/api/06_sync.ipynb diff --git a/nbs/api/06_sync.ipynb b/nbs/api/06_sync.ipynb index 356c2754c..23dbcb33f 100644 --- a/nbs/api/06_sync.ipynb +++ b/nbs/api/06_sync.ipynb @@ -46,7 +46,7 @@ "from fastcore.xtras import *\n", "\n", "import ast\n", - "from importlib import import_module" + "import importlib" ] }, { @@ -98,7 +98,10 @@ "#|export\n", "@functools.lru_cache(maxsize=None)\n", "def _mod_files():\n", - " midx = import_module(f'{get_config().lib_path.name}._modidx')\n", + " midx_spec = importlib.util.spec_from_file_location(\"_modidx\", get_config().lib_path / \"_modidx.py\")\n", + " midx = importlib.util.module_from_spec(midx_spec)\n", + " midx_spec.loader.exec_module(midx)\n", + "\n", " return L(files for mod in midx.d['syms'].values() for _,files in mod.values()).unique()" ] },