Refactored the function to return currently installed frontend pacakage version

This commit is contained in:
shivansh-gupta4 2025-07-12 23:41:25 +05:30
parent e7040c37e3
commit b3eed4fa35
3 changed files with 15 additions and 31 deletions

View File

@ -29,38 +29,22 @@ def frontend_install_warning_message():
This error is happening because the ComfyUI frontend is no longer shipped as part of the main repo but as a pip package instead. This error is happening because the ComfyUI frontend is no longer shipped as part of the main repo but as a pip package instead.
""".strip() """.strip()
def is_valid_version(version: str) -> bool: def parse_version(version: str) -> tuple[int, int, int]:
"""Validate if a string is a valid semantic version (X.Y.Z format).""" return tuple(map(int, version.split(".")))
pattern = r"^(\d+)\.(\d+)\.(\d+)$"
return bool(re.match(pattern, version))
def get_required_frontend_version(): def get_installed_frontend_version():
"""Get the required frontend version from requirements.txt.""" """Get the currently installed frontend package version."""
try: frontend_version_str = version("comfyui-frontend-package")
with open(requirements_path, "r", encoding="utf-8") as f: return frontend_version_str
version_str = f.readline().split("=")[-1].strip()
if not is_valid_version(version_str):
logging.error(f"Invalid version format in requirements.txt: {version_str}")
return None
return version_str
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."""
def parse_version(version: str) -> tuple[int, int, int]:
return tuple(map(int, version.split(".")))
try: try:
frontend_version_str = version("comfyui-frontend-package") frontend_version_str = get_installed_frontend_version()
frontend_version = parse_version(frontend_version_str) frontend_version = parse_version(frontend_version_str)
required_frontend_str = get_required_frontend_version() with open(requirements_path, "r", encoding="utf-8") as f:
required_frontend = parse_version(required_frontend_str) required_frontend = parse_version(f.readline().split("=")[-1])
if frontend_version < required_frontend: if frontend_version < required_frontend:
app.logger.log_startup_warning( app.logger.log_startup_warning(
f""" f"""
@ -189,9 +173,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_required_frontend_version(cls) -> str: def get_frontend_version(cls) -> str:
"""Get the required frontend version from requirements.txt.""" """Get the currently installed frontend package version."""
return get_required_frontend_version() return get_installed_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_required_frontend_version() required_frontend_version = FrontendManager.get_frontend_version()
system_stats = { system_stats = {
"system": { "system": {

View File

@ -173,11 +173,11 @@ def test_init_frontend_fallback_on_error():
assert frontend_path == "/default/path" assert frontend_path == "/default/path"
mock_check.assert_called_once() mock_check.assert_called_once()
def test_get_required_frontend_version(): def test_get_frontend_version():
#Arrange #Arrange
expected_version = "1.23.4" expected_version = "1.23.4"
version = FrontendManager.get_required_frontend_version() version = FrontendManager.get_frontend_version()
#Assert #Assert
assert version == expected_version assert version == expected_version