Avoid import conflicts with other custom nodes

This commit is contained in:
ssit
2023-06-28 15:13:40 -04:00
parent 0cb6c54eb3
commit ebeca1daff
3 changed files with 14 additions and 9 deletions
+12
View File
@@ -1,3 +1,15 @@
import sys
import os
from itertools import dropwhile
repo_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, repo_dir)
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
# Clean up imports
sys.path.remove(repo_dir)
repo_name = os.path.basename(repo_dir)
imported_modules = [k for k, v in dropwhile(lambda item: item[0] != repo_name, sys.modules.items())]
for m in imported_modules[1:]:
del sys.modules[m]
-3
View File
@@ -1,10 +1,7 @@
# ComfyUI Node for Ultimate SD Upscale by Coyote-A: https://github.com/Coyote-A/ultimate-upscale-for-automatic1111
import os
import sys
import torch
import comfy
sys.path.append(os.path.dirname(__file__))
from usdu_patch import usdu
from utils import tensor_to_pil, pil_to_tensor
from modules.processing import StableDiffusionProcessing
+2 -6
View File
@@ -2,16 +2,12 @@ import os
import sys
import importlib.util
repos_path = os.path.dirname(os.path.realpath(__file__))
# Add the root directory to the path
root_path = os.path.dirname(repos_path)
sys.path.insert(0, root_path)
repositories_path = os.path.dirname(os.path.realpath(__file__))
# Import the script
script_name = "scripts/ultimate-upscale"
repo_name = "ultimate_sd_upscale"
script_path = f"{repos_path}/{repo_name}/{script_name}.py"
script_path = f"{repositories_path}/{repo_name}/{script_name}.py"
spec = importlib.util.spec_from_file_location(script_name, script_path)
ultimate_upscale = importlib.util.module_from_spec(spec)
sys.modules[script_name] = ultimate_upscale