mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-08 08:12:34 +08:00
Read .comfy_environment from ComfyUI install dir, not --base-directory
folder_paths.base_path is overridden by --base-directory to a user-supplied location. Launchers/installers write the .comfy_environment marker next to the ComfyUI install itself, so reading from base_path would silently fall back to 'local-git' whenever --base-directory is in use, defeating the purpose of the env header. Amp-Thread-ID: https://ampcode.com/threads/T-019df554-0cf8-755a-9f84-674e974aa5d1 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
parent
92096b3c85
commit
38e5aac7bd
@ -2,17 +2,22 @@ import functools
|
||||
import logging
|
||||
import os
|
||||
|
||||
import folder_paths
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_DEFAULT_DEPLOY_ENV = "local-git"
|
||||
_ENV_FILENAME = ".comfy_environment"
|
||||
|
||||
# Resolve the ComfyUI install directory (the parent of this `comfy/` package).
|
||||
# We deliberately avoid `folder_paths.base_path` here because that is overridden
|
||||
# by the `--base-directory` CLI arg to a user-supplied path, whereas the
|
||||
# `.comfy_environment` marker is written by launchers/installers next to the
|
||||
# ComfyUI install itself.
|
||||
_COMFY_INSTALL_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
|
||||
@functools.cache
|
||||
def get_deploy_environment() -> str:
|
||||
env_file = os.path.join(folder_paths.base_path, _ENV_FILENAME)
|
||||
env_file = os.path.join(_COMFY_INSTALL_DIR, _ENV_FILENAME)
|
||||
try:
|
||||
with open(env_file, encoding="utf-8") as f:
|
||||
# Cap the read so a malformed or maliciously crafted file (e.g.
|
||||
|
||||
@ -4,15 +4,15 @@ import os
|
||||
|
||||
import pytest
|
||||
|
||||
from comfy import deploy_environment
|
||||
from comfy.deploy_environment import get_deploy_environment
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_cache_and_base_path(tmp_path, monkeypatch):
|
||||
"""Reset the functools cache and point folder_paths.base_path at a tmp dir for each test."""
|
||||
def _reset_cache_and_install_dir(tmp_path, monkeypatch):
|
||||
"""Reset the functools cache and point the ComfyUI install dir at a tmp dir for each test."""
|
||||
get_deploy_environment.cache_clear()
|
||||
import folder_paths
|
||||
monkeypatch.setattr(folder_paths, "base_path", str(tmp_path))
|
||||
monkeypatch.setattr(deploy_environment, "_COMFY_INSTALL_DIR", str(tmp_path))
|
||||
yield
|
||||
get_deploy_environment.cache_clear()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user