From d021d323c1209c897f912a23c5b2d1581e9c56de Mon Sep 17 00:00:00 2001 From: lilly Date: Wed, 22 Mar 2023 17:26:57 +0900 Subject: [PATCH] 1 --- CheckpointLoaderSimpleText.py | 11 +++++---- Colors.py | 39 ------------------------------- ConsoleColor.py | 41 +++++++++++++++++++++++++++++++++ LoraLoaderText.py | 25 +++++++++++--------- LoraLoaderTextRandom.py | 2 +- SaveImageSimple.py | 22 ++++++++++-------- SimpleSampler.py | 13 +++++++---- __init__.py | 24 ++++++++----------- mypath.py | 43 +++++++++++++++++++++++++---------- wildcards.py | 17 +++++--------- 10 files changed, 130 insertions(+), 107 deletions(-) delete mode 100644 Colors.py create mode 100644 ConsoleColor.py diff --git a/CheckpointLoaderSimpleText.py b/CheckpointLoaderSimpleText.py index e049dcf..cf6e1e9 100644 --- a/CheckpointLoaderSimpleText.py +++ b/CheckpointLoaderSimpleText.py @@ -4,16 +4,19 @@ from nodes import * import folder_paths import random from .check_name import * -from .Colors import cprint, Colors as Colors import os -py_name=os.path.basename(__file__) -cprint(py_name, Colors.BLUE) +if __name__ == os.path.splitext(os.path.basename(__file__))[0] : + from ConsoleColor import print, console +else: + from .ConsoleColor import print, console +print(__file__) +print(os.path.basename(__file__)) class CheckpointLoaderSimpleText: @classmethod def INPUT_TYPES(s): t_checkpoints=folder_paths.get_filename_list("checkpoints") - #cprint(f"checkpoints count : {len(t_checkpoints)}", Colors.BGREEN) + #print(f"checkpoints count : {len(t_checkpoints)}", Colors.BGREEN) return { "required": { "ckpt_name": ( diff --git a/Colors.py b/Colors.py deleted file mode 100644 index 09829f1..0000000 --- a/Colors.py +++ /dev/null @@ -1,39 +0,0 @@ - - -print(f"Colors __name__ {__name__}") - -class Colors: - BLACK = '\033[30m' #Colors.BLACK - RED = '\033[31m' #Colors.BLACK - GREEN = '\033[32m' #Colors.BLACK - YELLOW = '\033[33m' #Colors.YELLOW - BLUE = '\033[34m' #Colors.BLACK - MAGENTA = '\033[35m' #Colors.BLACK - CYAN = '\033[36m' #Colors.BLACK - WHITE = '\033[37m' #Colors.BLACK - BBLACK = '\033[90m' #Colors.BLACK - BRED = '\033[91m' #Colors.BLACK - BGREEN = '\033[92m' #Colors.BLACK - BYELLOW = '\033[93m' #Colors.YELLOW - BBLUE = '\033[94m' #Colors.BLACK - BMAGENTA = '\033[95m' #Colors.BLACK - BCYAN = '\033[96m' #Colors.BLACK - BWHITE = '\033[97m' #Colors.BLACK - UNDERLINE = '\033[4m' #Colors.BLACK - RESET = '\033[0m' #Colors.BLACK - -def cprint(text,color=None): - if color: - print(color + text + Colors.RESET) - else: - print(text) - -#from Colors import cprint, Colors as Colors -import os -py_name=os.path.basename(__file__) -cprint(py_name, Colors.BLUE) -cprint("BLACK", Colors.BLACK) -cprint("RED", Colors.RED) -cprint("GREEN", Colors.GREEN) -cprint("MAGENTA", Colors.MAGENTA) -cprint("CYAN", Colors.CYAN) \ No newline at end of file diff --git a/ConsoleColor.py b/ConsoleColor.py new file mode 100644 index 0000000..d93b441 --- /dev/null +++ b/ConsoleColor.py @@ -0,0 +1,41 @@ +import os, sys +import sys +import subprocess +import pkg_resources + +required = {'rich'} +installed = {pkg.key for pkg in pkg_resources.working_set} +missing = required - installed + +if missing: + python = sys.executable + subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL) + +from rich.console import Console + +console=Console() +print=console.log +print( + { + 'test1':'tset', + 'test2':'tset', + } +) +print("test", style="bold white on blue") +""" +import os +if __name__ == os.path.splitext(os.path.basename(__file__))[0] : + from ConsoleColor import print, console +else: + from .ConsoleColor import print, console +print(__file__) +print(os.path.basename(__file__)) +""" + +print(__file__) +print(os.path.basename(__file__)) +try: + Exception_test() +except Exception: + #console.print_exception(show_locals=True) + console.print_exception() \ No newline at end of file diff --git a/LoraLoaderText.py b/LoraLoaderText.py index e16d22a..8395c7e 100644 --- a/LoraLoaderText.py +++ b/LoraLoaderText.py @@ -6,16 +6,19 @@ import folder_paths class LoraLoaderText: @classmethod def INPUT_TYPES(s): - return {"required": { "model": ("MODEL",), - "clip": ("CLIP", ), - "lora_name": ("STRING", { - "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node - "default": (folder_paths.get_filename_list("loras"), ) - }), - #"lora_name": (folder_paths.get_filename_list("loras"), ), - "strength_model": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), - "strength_clip": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), - }} + return { + "required": { + "model": ("MODEL",), + "clip": ("CLIP", ), + "lora_name": ("STRING", { + "multiline": False, #True if you want the field to look like the one on the ClipTextEncode node + "default": (folder_paths.get_filename_list("loras"), ) + }), + #"lora_name": (folder_paths.get_filename_list("loras"), ), + "strength_model": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), + "strength_clip": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), + } + } RETURN_TYPES = ("MODEL", "CLIP") FUNCTION = "load_lora" @@ -45,7 +48,7 @@ class LoraLoaderText: return (model_lora, clip_lora) except Exception as e: print("LoraLoaderText Exception : "+ e) - return (strength_model, strength_clip) + return (model, clip) #NODE_CLASS_MAPPINGS = { # "LoraLoaderText": LoraLoaderText, diff --git a/LoraLoaderTextRandom.py b/LoraLoaderTextRandom.py index 8528ec2..0713a0a 100644 --- a/LoraLoaderTextRandom.py +++ b/LoraLoaderTextRandom.py @@ -21,7 +21,7 @@ class LoraLoaderTextRandom: "strength_model_min": ("FLOAT", {"default": 0.50, "min": 0.0, "max": 10.0, "step": 0.01}), "strength_model_max": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), "strength_clip_min": ("FLOAT", {"default": 0.50, "min": 0.0, "max": 10.0, "step": 0.01}), - "strength_clip_max": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), + "strength_clip_max": ("FLOAT", {"default": 1.50, "min": 0.0, "max": 10.0, "step": 0.01}), } } RETURN_TYPES = ("MODEL", "CLIP") diff --git a/SaveImageSimple.py b/SaveImageSimple.py index ccd5428..a76fa8e 100644 --- a/SaveImageSimple.py +++ b/SaveImageSimple.py @@ -5,12 +5,16 @@ import json import time -from .Colors import cprint, Colors -import os, sys -py_name=os.path.basename(__file__) -cprint(py_name, Colors.BLUE) +import os +if __name__ == os.path.splitext(os.path.basename(__file__))[0] : + from ConsoleColor import print, console + from mypath import * +else: + from .ConsoleColor import print, console + from .mypath import * +print(__file__) +print(os.path.basename(__file__)) -from .mypath import * class SaveImageSimple: def __init__(self): @@ -37,9 +41,9 @@ class SaveImageSimple: def save_images(self, images, filename_prefix="", prompt=None, extra_pnginfo=None): outputdir=os.path.join(mainfolder, "output") - #cprint("outputdir : " + outputdir , Colors.CYAN) + #print("outputdir : " + outputdir , Colors.CYAN) - #cprint("len(images) : " + str(len(images)) , Colors.CYAN) + #print("len(images) : " + str(len(images)) , Colors.CYAN) filename_prefix+=time.strftime('_%Y%m%d_%H%M%S') results = list() cnt=1 @@ -50,11 +54,11 @@ class SaveImageSimple: if prompt is not None: metadata.add_text("prompt", json.dumps(prompt)) if extra_pnginfo is not None: - #cprint("extra_pnginfo : " + json.dumps(extra_pnginfo) , Colors.CYAN) + #print("extra_pnginfo : " + json.dumps(extra_pnginfo) , Colors.CYAN) for x in extra_pnginfo: metadata.add_text(x, json.dumps(extra_pnginfo[x])) if not os.path.exists(outputdir): - cprint("makedirs : " + outputdir , Colors.CYAN) + print("makedirs : " + outputdir , Colors.CYAN) os.makedirs(outputdir) filename=filename_prefix+f"_{cnt:05}_.png" filename=os.path.join(outputdir, filename) diff --git a/SimpleSampler.py b/SimpleSampler.py index 6418b0b..fe188ed 100644 --- a/SimpleSampler.py +++ b/SimpleSampler.py @@ -24,10 +24,13 @@ import numpy as np print(f"SimpleSampler __name__ {__name__}") print(f"SimpleSampler __file__ {os.path.splitext(os.path.basename(__file__))[0]}") -from .Colors import cprint, Colors as Colors import os -py_name=os.path.basename(__file__) -cprint(py_name, Colors.BLUE) +if __name__ == os.path.splitext(os.path.basename(__file__))[0] : + from ConsoleColor import print, console +else: + from .ConsoleColor import print, console +print(__file__) +print(os.path.basename(__file__)) #---------------------------- # wildcards support check @@ -36,9 +39,9 @@ try: from wildcards import * wildcardsOn=True #wildcards.card_path=os.path.dirname(__file__)+"\\..\\wildcards\\**\\*.txt" - cprint(f"{py_name} : import wildcards succ", Colors.GREEN ) + print(f"import wildcards succ", style="bold GREEN" ) except: - cprint(f"{py_name} : import wildcards fail", Colors.RED) + print(f"import wildcards fail", style="bold RED") wildcardsOn=False err_msg = traceback.format_exc() print(err_msg) diff --git a/__init__.py b/__init__.py index 7e5034d..41a673e 100644 --- a/__init__.py +++ b/__init__.py @@ -1,15 +1,12 @@ import os -#from ComfyUI_script import mypath +if __name__ == os.path.splitext(os.path.basename(__file__))[0] : + from ConsoleColor import print, console +else: + from .ConsoleColor import print, console +print(__file__) +print(os.path.basename(__file__)) -print(f"init __name__ {__name__}") -print(f"init __file__ {os.path.splitext(os.path.basename(__file__))[0]}") -from .Colors import cprint, Colors as Colors - -py_name=os.path.basename(__file__) -cprint(py_name, Colors.BLUE) - -import os import sys #print(f"sys.modules : {sys.modules}") @@ -55,12 +52,9 @@ if not md.startswith("custom_nodes."): try: pkg = importlib.import_module(f"{md}.{name}") NODE_CLASS_MAPPINGS[name]=eval(f"pkg.{name}") - cprint(f"Load ok : {name}") - except Exception as e: - cprint(f"Load fail : {name}",Colors.YELLOW) - cprint(f"Exception : {e}",Colors.YELLOW) - err_msg = traceback.format_exc() - cprint(err_msg,Colors.YELLOW) + print(f"Load ok : {name}", style="bold green") + except Exception: + console.print_exception() add("CheckpointLoaderRandom") add("CheckpointLoaderSimpleText") diff --git a/mypath.py b/mypath.py index af6bb10..34a4811 100644 --- a/mypath.py +++ b/mypath.py @@ -1,31 +1,50 @@ -import os, sys - +import sys +import os if __name__ == os.path.splitext(os.path.basename(__file__))[0] : - from Colors import cprint, Colors as Colors + from ConsoleColor import print, console else: - from .Colors import cprint, Colors as Colors + from .ConsoleColor import print, console +print(__file__) +print(os.path.basename(__file__)) + + +""" +import psutil +for proc in psutil.process_iter(): + ps_name = proc.name() + if ps_name == 'python3': + cmdline = proc.cmdline() + print(cmdline) +""" + +""" +print() +for key, value in os.environ.items(): + print('{}: {}'.format(key, value)) +print() +""" py_name=os.path.basename(__file__) -cprint(py_name, Colors.BLUE) +print(py_name, style="bold CYAN") absFilePath = os.path.abspath(__file__) -cprint("abspath : " + absFilePath , Colors.CYAN) +print("abspath : " + absFilePath , style="bold CYAN") realFilePath = os.path.realpath(__file__) -cprint("realpath : " + realFilePath , Colors.CYAN) +print("realpath : " + realFilePath , style="bold CYAN") normpath=os.path.normpath(__file__) -cprint("normpath : " + normpath , Colors.CYAN) +print("normpath : " + normpath , style="bold CYAN") subfolder = os.path.dirname(normpath) -cprint("subfolder : " + subfolder , Colors.CYAN) +print("subfolder : " + subfolder , style="bold CYAN") filename = os.path.basename(normpath) -cprint("filename : " + filename , Colors.CYAN) +print("filename : " + filename , style="bold CYAN") mainFile = os.path.abspath(sys.modules['__main__'].__file__) -cprint("mainFile : " + mainFile , Colors.CYAN) +print("mainFile : " + mainFile ,style="bold CYAN") mainfolder = os.path.dirname(mainFile) -cprint("mainfolder : " + mainfolder , Colors.CYAN) +print("mainfolder : " + mainfolder , style="bold CYAN") diff --git a/wildcards.py b/wildcards.py index e66edb0..f8cd061 100644 --- a/wildcards.py +++ b/wildcards.py @@ -2,17 +2,12 @@ import glob, sys import random import re import os - -print(f"init __name__ {__name__}") -print(f"init __file__ {os.path.splitext(os.path.basename(__file__))[0]}") - -#import wildcards if __name__ == os.path.splitext(os.path.basename(__file__))[0] : - from Colors import cprint, Colors as Colors + from ConsoleColor import print, console else: - from .Colors import cprint, Colors as Colors -py_name=os.path.basename(__file__) -cprint(py_name, Colors.BLUE) + from .ConsoleColor import print, console +print(__file__) +print(os.path.basename(__file__)) #print(os.getcwd()) # ============================================================ @@ -83,8 +78,8 @@ class wildcards: except Exception as e: - cprint(f"Error : {match.groups()}" ,Colors.YELLOW) - cprint(f"Exception : {e}" ,Colors.YELLOW) + print(f"Error : {match.groups()}" ,Colors.YELLOW) + print(f"Exception : {e}" ,Colors.YELLOW) return ""