mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-14 04:22:31 +08:00
fix: override inherited env vars and merge partial CLI proxy args
- Use direct assignment instead of setdefault so CLI/settings proxy values actually override inherited environment variables. - Always read settings file for unspecified fields, so partial CLI overrides (e.g. only --http-proxy) still pick up saved https/no-proxy.
This commit is contained in:
parent
70313b7f00
commit
15a932e655
49
main.py
49
main.py
@ -34,37 +34,40 @@ def _apply_proxy_env_vars():
|
|||||||
https_proxy = args.https_proxy
|
https_proxy = args.https_proxy
|
||||||
no_proxy = args.no_proxy
|
no_proxy = args.no_proxy
|
||||||
|
|
||||||
# Fall back to settings file if CLI args are not provided.
|
# Fall back to settings file for any field not provided via CLI.
|
||||||
if not http_proxy and not https_proxy:
|
user_dir = args.user_directory or os.path.join(
|
||||||
user_dir = args.user_directory or os.path.join(
|
args.base_directory or os.path.dirname(os.path.realpath(__file__)), "user"
|
||||||
args.base_directory or os.path.dirname(os.path.realpath(__file__)), "user"
|
)
|
||||||
)
|
settings_path = os.path.join(user_dir, "default", "comfy.settings.json")
|
||||||
settings_path = os.path.join(user_dir, "default", "comfy.settings.json")
|
if os.path.isfile(settings_path):
|
||||||
if os.path.isfile(settings_path):
|
try:
|
||||||
try:
|
with open(settings_path, "r") as f:
|
||||||
with open(settings_path, "r") as f:
|
settings = _json.load(f)
|
||||||
settings = _json.load(f)
|
http_proxy = http_proxy or settings.get("Comfy.Network.Proxy.HttpUrl") or ""
|
||||||
http_proxy = http_proxy or settings.get("Comfy.Network.Proxy.HttpUrl") or ""
|
https_proxy = https_proxy or settings.get("Comfy.Network.Proxy.HttpsUrl") or ""
|
||||||
https_proxy = https_proxy or settings.get("Comfy.Network.Proxy.HttpsUrl") or ""
|
no_proxy = no_proxy or settings.get("Comfy.Network.Proxy.NoProxy") or ""
|
||||||
no_proxy = no_proxy or settings.get("Comfy.Network.Proxy.NoProxy") or ""
|
except Exception:
|
||||||
except Exception:
|
pass
|
||||||
pass
|
|
||||||
|
def _set_proxy_var(name, value):
|
||||||
|
"""Set env var, overriding inherited values when explicitly configured."""
|
||||||
|
os.environ[name] = value
|
||||||
|
|
||||||
if http_proxy:
|
if http_proxy:
|
||||||
os.environ.setdefault('HTTP_PROXY', http_proxy)
|
_set_proxy_var('HTTP_PROXY', http_proxy)
|
||||||
os.environ.setdefault('http_proxy', http_proxy)
|
_set_proxy_var('http_proxy', http_proxy)
|
||||||
# Use http_proxy for HTTPS too unless https_proxy is explicitly set
|
# Use http_proxy for HTTPS too unless https_proxy is explicitly set
|
||||||
if not https_proxy:
|
if not https_proxy:
|
||||||
os.environ.setdefault('HTTPS_PROXY', http_proxy)
|
_set_proxy_var('HTTPS_PROXY', http_proxy)
|
||||||
os.environ.setdefault('https_proxy', http_proxy)
|
_set_proxy_var('https_proxy', http_proxy)
|
||||||
logging.info("HTTP proxy configured: %s", http_proxy)
|
logging.info("HTTP proxy configured: %s", http_proxy)
|
||||||
if https_proxy:
|
if https_proxy:
|
||||||
os.environ.setdefault('HTTPS_PROXY', https_proxy)
|
_set_proxy_var('HTTPS_PROXY', https_proxy)
|
||||||
os.environ.setdefault('https_proxy', https_proxy)
|
_set_proxy_var('https_proxy', https_proxy)
|
||||||
logging.info("HTTPS proxy configured: %s", https_proxy)
|
logging.info("HTTPS proxy configured: %s", https_proxy)
|
||||||
if no_proxy:
|
if no_proxy:
|
||||||
os.environ.setdefault('NO_PROXY', no_proxy)
|
_set_proxy_var('NO_PROXY', no_proxy)
|
||||||
os.environ.setdefault('no_proxy', no_proxy)
|
_set_proxy_var('no_proxy', no_proxy)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user