()
| 58 | |
| 59 | |
| 60 | def update_backend(): |
| 61 | target = get_target() |
| 62 | backend_dir = os.path.join(BACKENDS_ROOT_DIR, "sdkit3", target) |
| 63 | |
| 64 | config = getConfig() |
| 65 | backend_config = config.get("backend_config") or {} |
| 66 | |
| 67 | if os.path.exists(backend_dir): |
| 68 | print("Updating sdkit3 backend..") |
| 69 | else: |
| 70 | print("Installing sdkit3 backend..") |
| 71 | |
| 72 | print("Looking for backend build for target:", target) |
| 73 | |
| 74 | backend_version = backend_config.get("version", DEFAULT_BACKEND_VERSION) |
| 75 | backend_binary_url = f"{BACKEND_BINARY_URL_BASE}/{backend_version}" |
| 76 | manifest_url = f"{backend_binary_url}/{target}-manifest.json" |
| 77 | |
| 78 | print(f"Fetching manifest from {manifest_url}") |
| 79 | response = requests.get(manifest_url) |
| 80 | try: |
| 81 | response.raise_for_status() |
| 82 | except requests.exceptions.HTTPError as e: |
| 83 | if response.status_code == 404: |
| 84 | raise ValueError( |
| 85 | f"Target platform {target} does not exist. Please post a message on our Discord server ( https://discord.com/invite/u9yhsFmEkB ) or create a new issue at https://github.com/easydiffusion/sdkit/issues to request this platform build." |
| 86 | ) |
| 87 | else: |
| 88 | raise |
| 89 | manifest = response.json() |
| 90 | files = manifest["files"] |
| 91 | |
| 92 | os.makedirs(backend_dir, exist_ok=True) |
| 93 | |
| 94 | with concurrent.futures.ThreadPoolExecutor() as executor: |
| 95 | futures = [ |
| 96 | executor.submit(update_or_download_file, filename, info, backend_binary_url, backend_dir) |
| 97 | for filename, info in files.items() |
| 98 | ] |
| 99 | for future in concurrent.futures.as_completed(futures): |
| 100 | future.result() |
| 101 | |
| 102 | print("Backend update complete.") |
| 103 | |
| 104 | |
| 105 | def update_or_download_file(filename, info, base_url, backend_dir): |
no test coverage detected