From e7fd8a9c774e77df1eb606967257140b8865aa5c Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 20 Oct 2025 12:50:00 +0800 Subject: [PATCH 1/2] Add PIP_INDEX_URL to cn pypi registry --- src/pythonManager.ts | 4 ++++ src/setup/SetupPanel.ts | 31 +++++++++++++++++++------------ src/setup/installPyReqs.ts | 3 +++ src/setup/pyReqsInstallStep.ts | 5 ++++- src/setup/toolsDownloadStep.ts | 3 ++- src/views/setup/store.ts | 7 ++++--- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/pythonManager.ts b/src/pythonManager.ts index c3c3929f9..434343a0e 100644 --- a/src/pythonManager.ts +++ b/src/pythonManager.ts @@ -115,6 +115,7 @@ export async function installPythonEnvFromIdfTools( pythonBinPath: string, gitPath: string, context: ExtensionContext, + mirror: ESP.IdfMirror, cancelToken?: CancellationToken ) { const idfToolsPyPath = join(espDir, "tools", "idf_tools.py"); @@ -123,6 +124,9 @@ export async function installPythonEnvFromIdfTools( ); modifiedEnv.IDF_TOOLS_PATH = idfToolsDir; modifiedEnv.IDF_PATH = espDir; + if (mirror === ESP.IdfMirror.Espressif) { + modifiedEnv.PIP_INDEX_URL = "https://dl.espressif.cn/pypi"; + } if (process.platform === "win32") { let pathToGitDir: string; if (gitPath && gitPath !== "git") { diff --git a/src/setup/SetupPanel.ts b/src/setup/SetupPanel.ts index fe2e0a7f6..0ea17ddd2 100644 --- a/src/setup/SetupPanel.ts +++ b/src/setup/SetupPanel.ts @@ -244,7 +244,8 @@ export class SetupPanel { message.toolsPath && message.pyBinPath && message.tools && - message.saveScope + message.saveScope && + typeof message.mirror !== undefined ) { this.panel.webview.postMessage({ command: "updateEspIdfToolsStatus", @@ -258,7 +259,8 @@ export class SetupPanel { message.saveScope, context, setupArgs.workspaceFolder, - setupArgs.espIdfStatusBar + setupArgs.espIdfStatusBar, + message.mirror ); } break; @@ -281,8 +283,9 @@ export class SetupPanel { }); SetupPanel.postMessage({ command: "setEspIdfErrorStatus", - errorMsg: `ESP-IDF is installed in ${setupArgs.existingIdfSetups[message.selectedIdfSetup].idfPath - }`, + errorMsg: `ESP-IDF is installed in ${ + setupArgs.existingIdfSetups[message.selectedIdfSetup].idfPath + }`, }); this.panel.webview.postMessage({ command: "updateEspIdfToolsStatus", @@ -329,7 +332,10 @@ export class SetupPanel { const pathIdfPy = path.join(message.path, "tools", "idf.py"); // Only require read and execute permissions - const fileExists = await canAccessFile(pathIdfPy, fs.constants.R_OK | fs.constants.X_OK); + const fileExists = await canAccessFile( + pathIdfPy, + fs.constants.R_OK | fs.constants.X_OK + ); if (!fileExists) { this.panel.webview.postMessage({ command: "canAccessFileResponse", @@ -349,8 +355,7 @@ export class SetupPanel { versionEspIdf = await getEspIdfFromCMake(message.path); } // compareVersion returns a negative value if versionEspIdf is less than "5.0" - const noWhiteSpaceSupport = - compareVersion(versionEspIdf, "5.0") < 0; + const noWhiteSpaceSupport = compareVersion(versionEspIdf, "5.0") < 0; const hasWhitespace = /\s/.test(message.path); this.panel.webview.postMessage({ command: "canAccessFileResponse", @@ -427,7 +432,7 @@ export class SetupPanel { ) as string; const progressLocation = notificationMode === idfConf.NotificationMode.All || - notificationMode === idfConf.NotificationMode.Notifications + notificationMode === idfConf.NotificationMode.Notifications ? ProgressLocation.Notification : ProgressLocation.Window; return await window.withProgress( @@ -561,7 +566,7 @@ export class SetupPanel { ) as string; const progressLocation = notificationMode === idfConf.NotificationMode.All || - notificationMode === idfConf.NotificationMode.Notifications + notificationMode === idfConf.NotificationMode.Notifications ? ProgressLocation.Notification : ProgressLocation.Window; return await window.withProgress( @@ -624,14 +629,15 @@ export class SetupPanel { saveScope: ConfigurationTarget, context: ExtensionContext, workspaceFolderUri: Uri, - espIdfStatusBar: StatusBarItem + espIdfStatusBar: StatusBarItem, + mirror: ESP.IdfMirror ) { const notificationMode = idfConf.readParameter( "idf.notificationMode" ) as string; const progressLocation = notificationMode === idfConf.NotificationMode.All || - notificationMode === idfConf.NotificationMode.Notifications + notificationMode === idfConf.NotificationMode.Notifications ? ProgressLocation.Notification : ProgressLocation.Window; return await window.withProgress( @@ -660,7 +666,8 @@ export class SetupPanel { progress, cancelToken, workspaceFolderUri, - espIdfStatusBar + espIdfStatusBar, + mirror ); } catch (error) { this.setupErrHandler(error); diff --git a/src/setup/installPyReqs.ts b/src/setup/installPyReqs.ts index 5a31c0413..8e7be59fd 100644 --- a/src/setup/installPyReqs.ts +++ b/src/setup/installPyReqs.ts @@ -19,6 +19,7 @@ import { OutputChannel } from "../logger/outputChannel"; import { PyReqLog } from "../PyReqLog"; import { CancellationToken, ExtensionContext, Progress } from "vscode"; import { Logger } from "../logger/logger"; +import { ESP } from "../config"; export async function installPyReqs( espIdfPath: string, @@ -27,6 +28,7 @@ export async function installPyReqs( gitPath: string, context: ExtensionContext, progress: Progress<{ message: string; increment?: number }>, + mirror: ESP.IdfMirror, cancelToken?: CancellationToken ) { progress.report({ @@ -68,6 +70,7 @@ export async function installPyReqs( sysPyBinPath, gitPath, context, + mirror, cancelToken ); if (virtualEnvPyBin) { diff --git a/src/setup/pyReqsInstallStep.ts b/src/setup/pyReqsInstallStep.ts index 8eb0b0493..79c04d98b 100644 --- a/src/setup/pyReqsInstallStep.ts +++ b/src/setup/pyReqsInstallStep.ts @@ -19,6 +19,7 @@ import { SetupPanel } from "./SetupPanel"; import { saveSettings } from "./setupInit"; import { getOpenOcdRules } from "./addOpenOcdRules"; import { addIdfPath } from "./espIdfJson"; +import { ESP } from "../config"; export async function createPyReqs( idfPath: string, @@ -30,7 +31,8 @@ export async function createPyReqs( progress: vscode.Progress<{ message: string; increment?: number }>, cancelToken: vscode.CancellationToken, workspaceFolderUri: vscode.Uri, - espIdfStatusBar: vscode.StatusBarItem + espIdfStatusBar: vscode.StatusBarItem, + mirror: ESP.IdfMirror ) { SetupPanel.postMessage({ command: "updatePyVEnvStatus", @@ -43,6 +45,7 @@ export async function createPyReqs( gitPath, context, progress, + mirror, cancelToken ); await saveSettings( diff --git a/src/setup/toolsDownloadStep.ts b/src/setup/toolsDownloadStep.ts index ef24ba77f..a625041bd 100644 --- a/src/setup/toolsDownloadStep.ts +++ b/src/setup/toolsDownloadStep.ts @@ -68,6 +68,7 @@ export async function downloadIdfTools( progress, cancelToken, workspaceFolderUri, - espIdfStatusBar + espIdfStatusBar, + mirror ); } diff --git a/src/views/setup/store.ts b/src/views/setup/store.ts index 43c920409..bd4ad7688 100644 --- a/src/views/setup/store.ts +++ b/src/views/setup/store.ts @@ -177,9 +177,9 @@ export const useSetupStore = defineStore("setup", () => { function checkEspIdfTools() { const pyPath = - selectedSysPython === pyVersionsList[pyVersionsList.value.length - 1] - ? manualPythonPath - : selectedSysPython; + selectedSysPython.value === pyVersionsList.value[pyVersionsList.value.length - 1] + ? manualPythonPath.value + : selectedSysPython.value; console.log({ command: "checkEspIdfTools", espIdf: espIdf.value, @@ -254,6 +254,7 @@ export const useSetupStore = defineStore("setup", () => { tools: JSON.stringify(toolsResults.value), toolsPath: toolsFolder.value, saveScope: saveScope.value, + mirror: selectedIdfMirror.value, }); } From a545e90182c781e7f7ea8c130569727e9357c7f2 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Tue, 21 Oct 2025 15:20:26 +0800 Subject: [PATCH 2/2] PIP_EXTRA_INDEX_URL instead of PIP_INDEX_URL --- src/pythonManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pythonManager.ts b/src/pythonManager.ts index 434343a0e..8109ebcdb 100644 --- a/src/pythonManager.ts +++ b/src/pythonManager.ts @@ -125,7 +125,7 @@ export async function installPythonEnvFromIdfTools( modifiedEnv.IDF_TOOLS_PATH = idfToolsDir; modifiedEnv.IDF_PATH = espDir; if (mirror === ESP.IdfMirror.Espressif) { - modifiedEnv.PIP_INDEX_URL = "https://dl.espressif.cn/pypi"; + modifiedEnv.PIP_EXTRA_INDEX_URL = "https://dl.espressif.cn/pypi"; } if (process.platform === "win32") { let pathToGitDir: string;