mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-20 03:13:30 +00:00
Prevent custom nodes from accidentally overwriting global modules. (#7167)
* Prevent custom nodes from accidentally overwriting global modules. * Improve.
This commit is contained in:
parent
cc7e023a4a
commit
8c6b9f4481
12
nodes.py
12
nodes.py
@ -2130,21 +2130,25 @@ def get_module_name(module_path: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes") -> bool:
|
def load_custom_node(module_path: str, ignore=set(), module_parent="custom_nodes") -> bool:
|
||||||
module_name = os.path.basename(module_path)
|
module_name = get_module_name(module_path)
|
||||||
if os.path.isfile(module_path):
|
if os.path.isfile(module_path):
|
||||||
sp = os.path.splitext(module_path)
|
sp = os.path.splitext(module_path)
|
||||||
module_name = sp[0]
|
module_name = sp[0]
|
||||||
|
sys_module_name = module_name
|
||||||
|
elif os.path.isdir(module_path):
|
||||||
|
sys_module_name = module_path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.debug("Trying to load custom node {}".format(module_path))
|
logging.debug("Trying to load custom node {}".format(module_path))
|
||||||
if os.path.isfile(module_path):
|
if os.path.isfile(module_path):
|
||||||
module_spec = importlib.util.spec_from_file_location(module_name, module_path)
|
module_spec = importlib.util.spec_from_file_location(sys_module_name, module_path)
|
||||||
module_dir = os.path.split(module_path)[0]
|
module_dir = os.path.split(module_path)[0]
|
||||||
else:
|
else:
|
||||||
module_spec = importlib.util.spec_from_file_location(module_name, os.path.join(module_path, "__init__.py"))
|
module_spec = importlib.util.spec_from_file_location(sys_module_name, os.path.join(module_path, "__init__.py"))
|
||||||
module_dir = module_path
|
module_dir = module_path
|
||||||
|
|
||||||
module = importlib.util.module_from_spec(module_spec)
|
module = importlib.util.module_from_spec(module_spec)
|
||||||
sys.modules[module_name] = module
|
sys.modules[sys_module_name] = module
|
||||||
module_spec.loader.exec_module(module)
|
module_spec.loader.exec_module(module)
|
||||||
|
|
||||||
LOADED_MODULE_DIRS[module_name] = os.path.abspath(module_dir)
|
LOADED_MODULE_DIRS[module_name] = os.path.abspath(module_dir)
|
||||||
|
Loading…
Reference in New Issue
Block a user