mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-24 02:16:59 +08:00
Refactor code to use pathlib for loading custom nodes
In this commit, I refactored the code responsible for loading custom nodes to use the pathlib module for improved readability and maintainability. Instead of using nested os.path.join calls to construct file paths, I utilized the Path class from pathlib. This change makes the code cleaner and more Pythonic. I created a Path object for the directory containing the custom nodes, based on the current script's location (Path(__file__).resolve().parent). Then, I iterated through a list of node file names, appending each one to the directory path to obtain the full path to the node file. This approach simplifies the code and makes it easier to add or modify custom node files in the future. Overall, this refactoring enhances the code's maintainability and readability while preserving its functionality.
This commit is contained in:
parent
05e661e5ef
commit
86740edfe9
29
nodes.py
29
nodes.py
@ -8,6 +8,7 @@ import traceback
|
|||||||
import math
|
import math
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
from PIL.PngImagePlugin import PngInfo
|
from PIL.PngImagePlugin import PngInfo
|
||||||
@ -1772,15 +1773,21 @@ def load_custom_nodes():
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
def init_custom_nodes():
|
def init_custom_nodes():
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_latent.py"))
|
extras_dir = Path(__file__).resolve().parent / "comfy_extras"
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_hypernetwork.py"))
|
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_upscale_model.py"))
|
for node_file in [
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_post_processing.py"))
|
"nodes_latent.py",
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_mask.py"))
|
"nodes_hypernetwork.py",
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_rebatch.py"))
|
"nodes_upscale_model.py",
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_model_merging.py"))
|
"nodes_post_processing.py",
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_tomesd.py"))
|
"nodes_mask.py",
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_clip_sdxl.py"))
|
"nodes_rebatch.py",
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_canny.py"))
|
"nodes_model_merging.py",
|
||||||
load_custom_node(os.path.join(os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras"), "nodes_freelunch.py"))
|
"nodes_tomesd.py",
|
||||||
|
"nodes_clip_sdxl.py",
|
||||||
|
"nodes_canny.py",
|
||||||
|
"nodes_freelunch.py"
|
||||||
|
]:
|
||||||
|
load_custom_node(extras_dir / node_file)
|
||||||
|
|
||||||
load_custom_nodes()
|
load_custom_nodes()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user