()
| 89 | |
| 90 | |
| 91 | def start_backend(): |
| 92 | config = getConfig() |
| 93 | backend_config = config.get("backend_config") or {} |
| 94 | |
| 95 | log.info(f"Backend dir: {BACKEND_DIR}") |
| 96 | |
| 97 | install_backend() # will do nothing if already installed |
| 98 | |
| 99 | env = dict(os.environ) |
| 100 | env.update(get_env()) |
| 101 | |
| 102 | was_still_installing = not is_installed() |
| 103 | |
| 104 | if backend_config.get("auto_update", True): |
| 105 | # Ensure the remote origin points to the correct repository |
| 106 | try: |
| 107 | current_remote = ( |
| 108 | check_output_in_conda(["git", "remote", "get-url", "origin"], cwd=WEBUI_DIR, env=env) |
| 109 | .decode("utf-8") |
| 110 | .strip() |
| 111 | ) |
| 112 | if current_remote != WEBUI_REPO: |
| 113 | log.info(f"Updating remote origin from {current_remote} to {WEBUI_REPO}") |
| 114 | run_in_conda(["git", "remote", "set-url", "origin", WEBUI_REPO], cwd=WEBUI_DIR, env=env) |
| 115 | except Exception as e: |
| 116 | log.warning(f"Failed to check/update git remote: {e}") |
| 117 | |
| 118 | run_in_conda(["git", "add", "-A", "."], cwd=WEBUI_DIR, env=env) |
| 119 | run_in_conda(["git", "stash"], cwd=WEBUI_DIR, env=env) |
| 120 | run_in_conda(["git", "reset", "--hard"], cwd=WEBUI_DIR, env=env) |
| 121 | run_in_conda(["git", "fetch"], cwd=WEBUI_DIR, env=env) |
| 122 | run_in_conda(["git", "-c", "advice.detachedHead=false", "checkout", WEBUI_COMMIT], cwd=WEBUI_DIR, env=env) |
| 123 | |
| 124 | # workaround for the installations that broke out of conda and used ED's python 3.8 instead of WebUI conda's Py 3.10 |
| 125 | run_in_conda(["python", "-m", "pip", "install", "-q", "--upgrade", "urllib3==2.2.3"], cwd=WEBUI_DIR, env=env) |
| 126 | |
| 127 | webui_common.WEBUI_API_PREFIX = "" |
| 128 | |
| 129 | def run_fn(): |
| 130 | cmd = "webui.bat" if OS_NAME == "Windows" else "./webui.sh" |
| 131 | |
| 132 | log.info(f"starting: {cmd} in {WEBUI_DIR}") |
| 133 | log.info(f"COMMANDLINE_ARGS: {env['COMMANDLINE_ARGS']}") |
| 134 | |
| 135 | return run_in_conda([cmd], cwd=WEBUI_DIR, env=env, wait=False, output_prefix="[WebUI] ") |
| 136 | |
| 137 | do_start_backend(was_still_installing, run_fn) |
| 138 | |
| 139 | start_proxy() |
| 140 | |
| 141 | |
| 142 | def start_proxy(): |
nothing calls this directly
no test coverage detected