litex/misoc_import.py

18 lines
499 B
Python
Raw Normal View History

2015-04-13 10:56:25 -04:00
import sys
import importlib
2014-08-09 02:39:38 -04:00
2015-04-13 10:47:22 -04:00
2014-08-09 02:39:38 -04:00
def misoc_import(default, external, name):
if external:
try:
2015-04-13 11:16:12 -04:00
del sys.modules[name] # force external path search
except KeyError:
pass
loader = importlib.find_loader(name, [external])
if loader is None:
# try internal import
return importlib.import_module(default + "." + name)
return loader.load_module()
else:
return importlib.import_module(default + "." + name)