Skip to content

Commit d5f749e

Browse files
shivansh-gupta4rakki194
authored andcommitted
Added parameter required_frontend_version in the /system_stats API response (comfyanonymous#8875)
* Added the parameter required_frontend_version in the /system_stats api response * Update server.py * Created a function get_required_frontend_version and wrote tests for it * Refactored the function to return currently installed frontend pacakage version * Moved required_frontend to a new function and imported that in server.py * Corrected test cases using mocking techniques * Corrected files to comply with ruff formatting
1 parent d5f623d commit d5f749e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

app/frontend_management.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,65 @@ def frontend_install_warning_message():
3838
If you are on the portable package you can run: update\\update_comfyui.bat to solve this problem
3939
""".strip()
4040

41+
def parse_version(version: str) -> tuple[int, int, int]:
42+
return tuple(map(int, version.split(".")))
43+
44+
def is_valid_version(version: str) -> bool:
45+
"""Validate if a string is a valid semantic version (X.Y.Z format)."""
46+
pattern = r"^(\d+)\.(\d+)\.(\d+)$"
47+
return bool(re.match(pattern, version))
48+
49+
def get_installed_frontend_version():
50+
"""Get the currently installed frontend package version."""
51+
frontend_version_str = version("comfyui-frontend-package")
52+
return frontend_version_str
53+
54+
def get_required_frontend_version():
55+
"""Get the required frontend version from requirements.txt."""
56+
try:
57+
with open(requirements_path, "r", encoding="utf-8") as f:
58+
for line in f:
59+
line = line.strip()
60+
if line.startswith("comfyui-frontend-package=="):
61+
version_str = line.split("==")[-1]
62+
if not is_valid_version(version_str):
63+
logging.error(f"Invalid version format in requirements.txt: {version_str}")
64+
return None
65+
return version_str
66+
logging.error("comfyui-frontend-package not found in requirements.txt")
67+
return None
68+
except FileNotFoundError:
69+
logging.error("requirements.txt not found. Cannot determine required frontend version.")
70+
return None
71+
except Exception as e:
72+
logging.error(f"Error reading requirements.txt: {e}")
73+
return None
74+
75+
def check_frontend_version():
76+
"""Check if the frontend version is up to date."""
77+
78+
try:
79+
frontend_version_str = get_installed_frontend_version()
80+
frontend_version = parse_version(frontend_version_str)
81+
required_frontend_str = get_required_frontend_version()
82+
required_frontend = parse_version(required_frontend_str)
83+
if frontend_version < required_frontend:
84+
app.logger.log_startup_warning(
85+
f"""
86+
________________________________________________________________________
87+
WARNING WARNING WARNING WARNING WARNING
88+
89+
Installed frontend version {".".join(map(str, frontend_version))} is lower than the recommended version {".".join(map(str, required_frontend))}.
90+
91+
{frontend_install_warning_message()}
92+
________________________________________________________________________
93+
""".strip()
94+
)
95+
else:
96+
logging.info("ComfyUI frontend version: {}".format(frontend_version_str))
97+
except Exception as e:
98+
logging.error(f"Failed to check frontend version: {e}")
99+
41100

42101
REQUEST_TIMEOUT = 10 # seconds
43102

@@ -135,6 +194,11 @@ def download_release_asset_zip(release: Release, destination_path: str) -> None:
135194
class FrontendManager:
136195
CUSTOM_FRONTENDS_ROOT = str(Path(__file__).parents[1] / "web_custom_versions")
137196

197+
@classmethod
198+
def get_required_frontend_version(cls) -> str:
199+
"""Get the required frontend package version."""
200+
return get_required_frontend_version()
201+
138202
@classmethod
139203
def default_frontend_path(cls) -> str:
140204
try:

server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,15 @@ async def system_stats(request):
553553
ram_free = comfy.model_management.get_free_memory(cpu_device)
554554
vram_total, torch_vram_total = comfy.model_management.get_total_memory(device, torch_total_too=True)
555555
vram_free, torch_vram_free = comfy.model_management.get_free_memory(device, torch_free_too=True)
556+
required_frontend_version = FrontendManager.get_required_frontend_version()
556557

557558
system_stats = {
558559
"system": {
559560
"os": os.name,
560561
"ram_total": ram_total,
561562
"ram_free": ram_free,
562563
"comfyui_version": __version__,
564+
"required_frontend_version": required_frontend_version,
563565
"python_version": sys.version,
564566
"pytorch_version": comfy.model_management.torch_version,
565567
"embedded_python": os.path.split(os.path.split(sys.executable)[0])[1] == "python_embeded",

0 commit comments

Comments
 (0)