MCPcopy
hub / github.com/MaaEnd/MaaEnd / install_cpp_algo

Function install_cpp_algo

tools/setup_workspace.py:1202–1429  ·  view source on GitHub ↗
(
    install_root: Path,
    skip_if_exist: bool = True,
    update_mode: bool = False,
    local_version: str | None = None,
    pr_number: int | None = None,
    run_id: int | None = None,
)

Source from the content-addressed store, hash-verified

1200
1201
1202def install_cpp_algo(
1203 install_root: Path,
1204 skip_if_exist: bool = True,
1205 update_mode: bool = False,
1206 local_version: str | None = None,
1207 pr_number: int | None = None,
1208 run_id: int | None = None,
1209) -> tuple[bool, str | None, bool]:
1210 real_install_root = install_root.resolve()
1211 cpp_algo_path = real_install_root / "agent" / CPP_ALGO_DIST_NAME
1212 cpp_algo_installed = cpp_algo_path.exists()
1213
1214 # When a specific PR or run is requested, always proceed past the skip
1215 # check — the user explicitly asked for a particular artifact.
1216 if skip_if_exist and cpp_algo_installed and pr_number is None and run_id is None:
1217 print(Console.ok(t("inf_cpp_algo_installed_skip")))
1218 return True, local_version, False
1219
1220 # ~~~ CI artifact fast path ~~~
1221 # Try to grab just the cpp-algo binary from a recent successful workflow run.
1222 # Default: latest v2 push. Optionally: from a specific PR or run ID.
1223 auth_headers = _github_auth_headers()
1224 ci_url, ci_version = _find_cpp_algo_in_ci(
1225 auth_headers, pr_number=pr_number, run_id=run_id,
1226 )
1227
1228 # When a specific PR/run was requested but no artifact was found, fall
1229 # back to the default CI search (latest v2 push) before trying a release.
1230 if ci_url is None and (pr_number is not None or run_id is not None):
1231 print(Console.warn(t("wrn_ci_artifact_pr_run_not_found_fallback")))
1232 ci_url, ci_version = _find_cpp_algo_in_ci(auth_headers)
1233
1234 if ci_url:
1235 ci_should_skip = (
1236 update_mode
1237 and cpp_algo_installed
1238 and _is_git_sha(local_version)
1239 and _is_git_sha(ci_version)
1240 and local_version == ci_version
1241 )
1242 if ci_should_skip:
1243 print(Console.ok(t("inf_cpp_algo_latest_version", version=local_version)))
1244 return True, local_version, False
1245
1246 cache_dir = ensure_cache_dir()
1247 ci_download_path = (
1248 cache_dir / f"cpp-algo-{OS_KEYWORD}-{ARCH_KEYWORD}.zip"
1249 )
1250 ci_downloaded = False
1251
1252 if auth_headers is not None:
1253 # GitHub artifact API returns a 302 redirect to Azure blob storage.
1254 # urllib's default redirect handler strips Authorization on cross-origin
1255 # redirects, causing a 401. Resolve the redirect with http.client
1256 # (which does not auto-follow redirects) and then download from the
1257 # storage URL with auth headers intact.
1258 storage_url: str | None = None
1259 try:

Callers 1

mainFunction · 0.85

Calls 15

_github_auth_headersFunction · 0.85
_find_cpp_algo_in_ciFunction · 0.85
_is_git_shaFunction · 0.85
ensure_cache_dirFunction · 0.85
download_fileFunction · 0.85
find_cpp_algo_binaryFunction · 0.85
copy_cpp_algo_binaryFunction · 0.85
cleanup_cache_fileFunction · 0.85
get_latest_release_urlFunction · 0.85
compare_semverFunction · 0.85
_is_supported_archiveFunction · 0.85

Tested by

no test coverage detected