Moved required_frontend to a new function and imported that in server.py

This commit is contained in:
shivansh-gupta4 2025-07-13 23:51:06 +05:30
parent b3eed4fa35
commit 8355adc750
3 changed files with 33 additions and 7 deletions

View File

@ -31,20 +31,46 @@ This error is happening because the ComfyUI frontend is no longer shipped as par
def parse_version(version: str) -> tuple[int, int, int]: def parse_version(version: str) -> tuple[int, int, int]:
return tuple(map(int, version.split("."))) return tuple(map(int, version.split(".")))
def is_valid_version(version: str) -> bool:
"""Validate if a string is a valid semantic version (X.Y.Z format)."""
pattern = r"^(\d+)\.(\d+)\.(\d+)$"
return bool(re.match(pattern, version))
def get_installed_frontend_version(): def get_installed_frontend_version():
"""Get the currently installed frontend package version.""" """Get the currently installed frontend package version."""
frontend_version_str = version("comfyui-frontend-package") frontend_version_str = version("comfyui-frontend-package")
return frontend_version_str return frontend_version_str
def get_required_frontend_version():
"""Get the required frontend version from requirements.txt."""
try:
with open(requirements_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if line.startswith("comfyui-frontend-package=="):
version_str = line.split("==")[-1]
if not is_valid_version(version_str):
logging.error(f"Invalid version format in requirements.txt: {version_str}")
return None
return version_str
logging.error("comfyui-frontend-package not found in requirements.txt")
return None
except FileNotFoundError:
logging.error("requirements.txt not found. Cannot determine required frontend version.")
return None
except Exception as e:
logging.error(f"Error reading requirements.txt: {e}")
return None
def check_frontend_version(): def check_frontend_version():
"""Check if the frontend version is up to date.""" """Check if the frontend version is up to date."""
try: try:
frontend_version_str = get_installed_frontend_version() frontend_version_str = get_installed_frontend_version()
frontend_version = parse_version(frontend_version_str) frontend_version = parse_version(frontend_version_str)
with open(requirements_path, "r", encoding="utf-8") as f: required_frontend_str = get_required_frontend_version()
required_frontend = parse_version(f.readline().split("=")[-1]) required_frontend = parse_version(required_frontend_str)
if frontend_version < required_frontend: if frontend_version < required_frontend:
app.logger.log_startup_warning( app.logger.log_startup_warning(
f""" f"""
@ -173,9 +199,9 @@ class FrontendManager:
CUSTOM_FRONTENDS_ROOT = str(Path(__file__).parents[1] / "web_custom_versions") CUSTOM_FRONTENDS_ROOT = str(Path(__file__).parents[1] / "web_custom_versions")
@classmethod @classmethod
def get_frontend_version(cls) -> str: def get_required_frontend_version(cls) -> str:
"""Get the currently installed frontend package version.""" """Get the required frontend package version."""
return get_installed_frontend_version() return get_required_frontend_version()
@classmethod @classmethod
def default_frontend_path(cls) -> str: def default_frontend_path(cls) -> str:

View File

@ -553,7 +553,7 @@ class PromptServer():
ram_free = comfy.model_management.get_free_memory(cpu_device) ram_free = comfy.model_management.get_free_memory(cpu_device)
vram_total, torch_vram_total = comfy.model_management.get_total_memory(device, torch_total_too=True) vram_total, torch_vram_total = comfy.model_management.get_total_memory(device, torch_total_too=True)
vram_free, torch_vram_free = comfy.model_management.get_free_memory(device, torch_free_too=True) vram_free, torch_vram_free = comfy.model_management.get_free_memory(device, torch_free_too=True)
required_frontend_version = FrontendManager.get_frontend_version() required_frontend_version = FrontendManager.get_required_frontend_version()
system_stats = { system_stats = {
"system": { "system": {

View File

@ -177,7 +177,7 @@ def test_get_frontend_version():
#Arrange #Arrange
expected_version = "1.23.4" expected_version = "1.23.4"
version = FrontendManager.get_frontend_version() version = FrontendManager.get_required_frontend_version()
#Assert #Assert
assert version == expected_version assert version == expected_version