Files
2024-12-28 11:12:31 -08:00

52 lines
1.0 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Author: C0ffymachyne
License: GPLv3
Version: 1.0.0
Description:
various development utilities
"""
import os
import sys
import re
# Define the regex
pattern = r"^ComfyUI-\d+\.\d+\.\d+$"
this_file_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)))
def find_comfy_root() -> str:
path = os.fspath(this_file_directory)
if isinstance(this_file_directory, bytes):
sep = b"/"
else:
sep = "/"
tokens = path.split(sep)
while not re.match(pattern, tokens[-1]):
tokens.pop(-1)
path = "/".join(tokens)
return path
# add comfy to path for local devepment only
# find comfy root by going upwards hoping it match regex
# export coffy_local_dev=1
def comfy_root_to_syspath() -> None:
try:
if os.environ["coffy_local_dev"] == "1":
pass
else:
raise (Exception())
except Exception:
return
path = find_comfy_root()
if path not in sys.path:
sys.path.insert(0, path)