From 157da4c7a70372cc52ccf968dd27adf1828409b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=A9=E6=B0=8F=E8=AF=B9=E8=AF=B9=E5=AD=90?= <65452214+aldlss@users.noreply.github.com> Date: Tue, 2 Sep 2025 12:58:34 +0800 Subject: [PATCH] Fix mirror configuration not working during launcher download (#4280) Use environment variable instead of configuration file --- CONTRIBUTORS | 1 + qt/launcher/src/main.rs | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 496f11855..70032a23c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -240,6 +240,7 @@ Thomas Rixen Siyuan Mattuwu Yan Lee Doughty <32392044+leedoughty@users.noreply.github.com> memchr +Aldlss ******************** diff --git a/qt/launcher/src/main.rs b/qt/launcher/src/main.rs index 297df5b8b..ccc4022b7 100644 --- a/qt/launcher/src/main.rs +++ b/qt/launcher/src/main.rs @@ -309,6 +309,13 @@ fn handle_version_install_or_update(state: &State, choice: MainMenuChoice) -> Re command.env("UV_NO_CACHE", "1"); } + // Add mirror environment variable if enabled + if let Some((python_mirror, pypi_mirror)) = get_mirror_urls(state)? { + command + .env("UV_PYTHON_INSTALL_MIRROR", &python_mirror) + .env("UV_DEFAULT_INDEX", &pypi_mirror); + } + match command.ensure_success() { Ok(_) => { // Sync succeeded @@ -673,6 +680,12 @@ fn fetch_versions(state: &State) -> Result> { cmd.arg(&versions_script); + // Add mirror environment variable if enabled + if let Some((python_mirror, pypi_mirror)) = get_mirror_urls(state)? { + cmd.env("UV_PYTHON_INSTALL_MIRROR", &python_mirror) + .env("UV_DEFAULT_INDEX", &pypi_mirror); + } + let output = match cmd.utf8_output() { Ok(output) => output, Err(e) => { @@ -725,15 +738,7 @@ fn apply_version_kind(version_kind: &VersionKind, state: &State) -> Result<()> { &format!("anki-release=={version}\",\n \"anki=={version}\",\n \"aqt=={version}"), ), }; - - // Add mirror configuration if enabled - let final_content = if let Some((python_mirror, pypi_mirror)) = get_mirror_urls(state)? { - format!("{updated_content}\n\n[[tool.uv.index]]\nname = \"mirror\"\nurl = \"{pypi_mirror}\"\ndefault = true\n\n[tool.uv]\npython-install-mirror = \"{python_mirror}\"\n") - } else { - updated_content - }; - - write_file(&state.user_pyproject_path, &final_content)?; + write_file(&state.user_pyproject_path, &updated_content)?; // Update .python-version based on version kind match version_kind {