Skip to content

Commit

Permalink
Try alternative implementation of importlib file-based module loader
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Aug 17, 2023
1 parent 32b67e3 commit 2f14b21
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def _import_from(mod, path, mod_dir=None):
mod_info = imp.find_module(mod_dir, [path])
return imp.load_module(mod, *mod_info)
else:
mod_info = importlib.machinery.PathFinder().find_spec(mod_dir, [path])
return importlib.import_module(mod, *mod_info)
spec = importlib.machinery.PathFinder().find_spec(mod_dir, [path])
module = importlib.util.module_from_spec(spec)
sys.modules[mod] = module
spec.loader.exec_module(module)
except ImportError:
return None

Expand Down

0 comments on commit 2f14b21

Please sign in to comment.