|
11 | 11 | from functools import cached_property |
12 | 12 | from pathlib import Path |
13 | 13 | from typing import TypedDict, Optional |
| 14 | +from importlib.metadata import version |
14 | 15 |
|
15 | 16 | import requests |
16 | 17 | from typing_extensions import NotRequired |
17 | 18 |
|
18 | 19 | from comfy.cli_args import DEFAULT_VERSION_STRING |
19 | 20 |
|
| 21 | +# The path to the requirements.txt file |
| 22 | +req_path = Path(__file__).parents[1] / "requirements.txt" |
20 | 23 |
|
21 | 24 | def frontend_install_warning_message(): |
22 | | - req_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'requirements.txt')) |
| 25 | + """The warning message to display when the frontend version is not up to date.""" |
| 26 | + |
23 | 27 | extra = "" |
24 | 28 | if sys.flags.no_user_site: |
25 | 29 | extra = "-s " |
26 | 30 | return f"Please install the updated requirements.txt file by running:\n{sys.executable} {extra}-m pip install -r {req_path}\n\nThis error is happening because the ComfyUI frontend is no longer shipped as part of the main repo but as a pip package instead.\n\nIf you are on the portable package you can run: update\\update_comfyui.bat to solve this problem" |
27 | 31 |
|
28 | | -try: |
29 | | - import comfyui_frontend_package |
30 | | -except ImportError: |
31 | | - # TODO: Remove the check after roll out of 0.3.16 |
32 | | - logging.error(f"\n\n********** ERROR ***********\n\ncomfyui-frontend-package is not installed. {frontend_install_warning_message()}\n********** ERROR **********\n") |
33 | | - exit(-1) |
34 | 32 |
|
| 33 | +def check_frontend_version(): |
| 34 | + """Check if the frontend version is up to date.""" |
| 35 | + |
| 36 | + def parse_version(version: str) -> tuple[int, int, int]: |
| 37 | + return tuple(map(int, version.split("."))) |
| 38 | + |
| 39 | + try: |
| 40 | + frontend_version_str = version("comfyui-frontend-package") |
| 41 | + frontend_version = parse_version(frontend_version_str) |
| 42 | + with open(req_path, "r", encoding="utf-8") as f: |
| 43 | + required_frontend = parse_version(f.readline().split("=")[-1]) |
| 44 | + if frontend_version < required_frontend: |
| 45 | + logging.warning("________________________________________________________________________\nWARNING WARNING WARNING WARNING WARNING\n\nInstalled frontend version {} is lower than the recommended version {}.\n\n{}\n________________________________________________________________________".format('.'.join(map(str, frontend_version)), '.'.join(map(str, required_frontend)), frontend_install_warning_message())) |
| 46 | + else: |
| 47 | + logging.info("ComfyUI frontend version: {}".format(frontend_version_str)) |
| 48 | + except Exception as e: |
| 49 | + logging.error(f"Failed to check frontend version: {e}") |
35 | 50 |
|
36 | | -try: |
37 | | - frontend_version = tuple(map(int, comfyui_frontend_package.__version__.split("."))) |
38 | | -except: |
39 | | - frontend_version = (0,) |
40 | | - pass |
41 | 51 |
|
42 | 52 | REQUEST_TIMEOUT = 10 # seconds |
43 | 53 |
|
@@ -133,9 +143,17 @@ def download_release_asset_zip(release: Release, destination_path: str) -> None: |
133 | 143 |
|
134 | 144 |
|
135 | 145 | class FrontendManager: |
136 | | - DEFAULT_FRONTEND_PATH = str(importlib.resources.files(comfyui_frontend_package) / "static") |
137 | 146 | CUSTOM_FRONTENDS_ROOT = str(Path(__file__).parents[1] / "web_custom_versions") |
138 | 147 |
|
| 148 | + @classmethod |
| 149 | + def default_frontend_path(cls) -> str: |
| 150 | + try: |
| 151 | + import comfyui_frontend_package |
| 152 | + return str(importlib.resources.files(comfyui_frontend_package) / "static") |
| 153 | + except ImportError: |
| 154 | + logging.error(f"\n\n********** ERROR ***********\n\ncomfyui-frontend-package is not installed. {frontend_install_warning_message()}\n********** ERROR **********\n") |
| 155 | + sys.exit(-1) |
| 156 | + |
139 | 157 | @classmethod |
140 | 158 | def parse_version_string(cls, value: str) -> tuple[str, str, str]: |
141 | 159 | """ |
@@ -172,7 +190,8 @@ def init_frontend_unsafe(cls, version_string: str, provider: Optional[FrontEndPr |
172 | 190 | main error source might be request timeout or invalid URL. |
173 | 191 | """ |
174 | 192 | if version_string == DEFAULT_VERSION_STRING: |
175 | | - return cls.DEFAULT_FRONTEND_PATH |
| 193 | + check_frontend_version() |
| 194 | + return cls.default_frontend_path() |
176 | 195 |
|
177 | 196 | repo_owner, repo_name, version = cls.parse_version_string(version_string) |
178 | 197 |
|
@@ -225,4 +244,5 @@ def init_frontend(cls, version_string: str) -> str: |
225 | 244 | except Exception as e: |
226 | 245 | logging.error("Failed to initialize frontend: %s", e) |
227 | 246 | logging.info("Falling back to the default frontend.") |
228 | | - return cls.DEFAULT_FRONTEND_PATH |
| 247 | + check_frontend_version() |
| 248 | + return cls.default_frontend_path() |
0 commit comments