mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-20 15:32:32 +08:00
Read a .comfy_environment file from the ComfyUI base directory to determine the deployment environment (e.g. standalone, portable, desktop). Defaults to 'local_git' when the file is absent. The value is sent as an X-Comfy-Deploy-Env header on all requests to api.comfy.org, allowing the API to differentiate between environment types. The .comfy_environment file is gitignored so launchers/installers can write it without affecting the repository. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d939e-6b4d-738b-8d1a-ac7cbf6736a4
34 lines
859 B
Python
34 lines
859 B
Python
import logging
|
|
import os
|
|
|
|
import folder_paths
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_DEFAULT_DEPLOY_ENV = "local_git"
|
|
_ENV_FILENAME = ".comfy_environment"
|
|
|
|
_cached_value: str | None = None
|
|
|
|
|
|
def get_deploy_environment() -> str:
|
|
global _cached_value
|
|
if _cached_value is not None:
|
|
return _cached_value
|
|
|
|
env_file = os.path.join(folder_paths.base_path, _ENV_FILENAME)
|
|
try:
|
|
with open(env_file, encoding="utf-8") as f:
|
|
first_line = f.readline().strip()
|
|
value = "".join(c for c in first_line if 32 <= ord(c) < 127)
|
|
if value:
|
|
_cached_value = value
|
|
return _cached_value
|
|
except FileNotFoundError:
|
|
pass
|
|
except Exception as e:
|
|
logger.warning("Failed to read %s: %s", env_file, e)
|
|
|
|
_cached_value = _DEFAULT_DEPLOY_ENV
|
|
return _cached_value
|