mirror of https://github.com/VLSIDA/OpenRAM.git
Use custom module name in module finder
This commit is contained in:
parent
441aff8e09
commit
79a10dc63b
20
__init__.py
20
__init__.py
|
|
@ -60,16 +60,15 @@ class custom_module_finder(MetaPathFinder):
|
||||||
# Skip if the package is not openram
|
# Skip if the package is not openram
|
||||||
if package_name != "openram":
|
if package_name != "openram":
|
||||||
return None
|
return None
|
||||||
# Check if this module can be custom
|
customizable = False
|
||||||
|
# Search for the module name in customizable modules
|
||||||
from openram import OPTS
|
from openram import OPTS
|
||||||
if hasattr(OPTS, module_name):
|
for k, v in OPTS.__dict__.items():
|
||||||
# Get custom name from OPTS
|
if module_name == v:
|
||||||
custom_name = getattr(OPTS, module_name)
|
customizable = True
|
||||||
# Skip if the module is default, it will be handled by Python
|
# Search for the custom module
|
||||||
if custom_name == module_name:
|
if customizable:
|
||||||
return None
|
|
||||||
import sys
|
import sys
|
||||||
from importlib.util import spec_from_file_location
|
|
||||||
# Try to find the module in sys.path
|
# Try to find the module in sys.path
|
||||||
for path in sys.path:
|
for path in sys.path:
|
||||||
# Skip this path if not directory
|
# Skip this path if not directory
|
||||||
|
|
@ -78,8 +77,9 @@ class custom_module_finder(MetaPathFinder):
|
||||||
for file in os.listdir(path):
|
for file in os.listdir(path):
|
||||||
# If there is a script matching the custom module name,
|
# If there is a script matching the custom module name,
|
||||||
# import it with the default module name
|
# import it with the default module name
|
||||||
if file == (custom_name + ".py"):
|
if file == (module_name + ".py"):
|
||||||
return spec_from_file_location(module_name, "{0}/{1}.py".format(path, custom_name))
|
from importlib.util import spec_from_file_location
|
||||||
|
return spec_from_file_location(module_name, "{0}/{1}.py".format(path, module_name))
|
||||||
return None
|
return None
|
||||||
# Python calls meta path finders and asks them to handle the module import if
|
# Python calls meta path finders and asks them to handle the module import if
|
||||||
# they can
|
# they can
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue