From ca6da9fb1c556d84990bd91d46a6b0cae8c235bc Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Wed, 25 Dec 2024 17:22:30 +0800 Subject: [PATCH 1/9] fix version switch by persist sys python in idfSetup --- src/checkExtensionSettings.ts | 1 + src/setup/existingIdfSetups.ts | 2 ++ src/setup/pyReqsInstallStep.ts | 1 + src/setup/setupInit.ts | 8 +++++++- src/setup/setupValidation/espIdfSetup.ts | 16 +++++++++++----- src/versionSwitcher/index.ts | 1 + src/views/setup/types.ts | 1 + 7 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/checkExtensionSettings.ts b/src/checkExtensionSettings.ts index 6608ea7d7..ac929d419 100644 --- a/src/checkExtensionSettings.ts +++ b/src/checkExtensionSettings.ts @@ -80,6 +80,7 @@ export async function checkExtensionSettings( idfPath, gitPath, toolsPath: idfToolsPath, + sysPythonPath: "python", version: idfVersion, isValid: false, }; diff --git a/src/setup/existingIdfSetups.ts b/src/setup/existingIdfSetups.ts index 799f51616..06f8b7dc8 100644 --- a/src/setup/existingIdfSetups.ts +++ b/src/setup/existingIdfSetups.ts @@ -59,6 +59,7 @@ export async function clearPreviousIdfSetups() { export async function createIdfSetup( idfPath: string, toolsPath: string, + sysPythonBinPath: string, gitPath: string ) { const idfSetupId = getIdfMd5sum(idfPath); @@ -68,6 +69,7 @@ export async function createIdfSetup( idfPath, gitPath, toolsPath, + sysPythonPath: sysPythonBinPath, version: idfVersion, isValid: false, }; diff --git a/src/setup/pyReqsInstallStep.ts b/src/setup/pyReqsInstallStep.ts index cf489169c..00d0513e6 100644 --- a/src/setup/pyReqsInstallStep.ts +++ b/src/setup/pyReqsInstallStep.ts @@ -55,6 +55,7 @@ export async function createPyReqs( idfPath, toolsPath, gitPath, + pyPath, saveScope, workspaceFolderUri, espIdfStatusBar diff --git a/src/setup/setupInit.ts b/src/setup/setupInit.ts index 7ac4a36f4..03b51c42a 100644 --- a/src/setup/setupInit.ts +++ b/src/setup/setupInit.ts @@ -296,6 +296,7 @@ export async function saveSettings( espIdfPath: string, toolsPath: string, gitPath: string, + sysPythonBinPath: string, saveScope: ConfigurationTarget, workspaceFolderUri: Uri, espIdfStatusBar: StatusBarItem @@ -324,7 +325,12 @@ export async function saveSettings( gitPath, ConfigurationTarget.Global ); - let currentIdfSetup = await createIdfSetup(espIdfPath, toolsPath, gitPath); + let currentIdfSetup = await createIdfSetup( + espIdfPath, + toolsPath, + sysPythonBinPath, + gitPath + ); if (espIdfStatusBar) { const commandDictionary = createCommandDictionary(); espIdfStatusBar.text = diff --git a/src/setup/setupValidation/espIdfSetup.ts b/src/setup/setupValidation/espIdfSetup.ts index 6267e2c61..b5d42fc6a 100644 --- a/src/setup/setupValidation/espIdfSetup.ts +++ b/src/setup/setupValidation/espIdfSetup.ts @@ -24,7 +24,7 @@ import { pathExists } from "fs-extra"; import { Logger } from "../../logger/logger"; import { checkPyVenv } from "./pythonEnv"; import { ConfigurationTarget, StatusBarItem, Uri } from "vscode"; -import { getPythonEnvPath, getVirtualEnvPythonPath } from "../../pythonManager"; +import { getPythonEnvPath } from "../../pythonManager"; import { readParameter } from "../../idfConfiguration"; export async function useIdfSetupSettings( @@ -37,14 +37,17 @@ export async function useIdfSetupSettings( setupConf.idfPath, setupConf.toolsPath, setupConf.gitPath, + setupConf.sysPythonPath, saveScope, workspaceFolderUri, espIdfStatusBar ); } -export async function checkIdfSetup(setupConf: IdfSetup, - logToChannel: boolean = true) { +export async function checkIdfSetup( + setupConf: IdfSetup, + logToChannel: boolean = true +) { try { if (!setupConf.idfPath) { return false; @@ -75,8 +78,11 @@ export async function checkIdfSetup(setupConf: IdfSetup, if (failedToolsResult.length) { return false; } - let sysPythonBinPath = readParameter("idf.pythonInstallPath") as string; - const virtualEnvPython = await getPythonEnvPath(setupConf.idfPath, setupConf.toolsPath, sysPythonBinPath); + const virtualEnvPython = await getPythonEnvPath( + setupConf.idfPath, + setupConf.toolsPath, + setupConf.sysPythonPath + ); const pyEnvReqs = await checkPyVenv(virtualEnvPython, setupConf.idfPath); return pyEnvReqs; diff --git a/src/versionSwitcher/index.ts b/src/versionSwitcher/index.ts index d9de344da..c62e32b5f 100644 --- a/src/versionSwitcher/index.ts +++ b/src/versionSwitcher/index.ts @@ -78,6 +78,7 @@ export async function getCurrentIdfSetup(workspaceFolder: Uri, idfPath, gitPath, toolsPath, + sysPythonPath: sysPythonBinPath, version: idfVersion, isValid: false, }; diff --git a/src/views/setup/types.ts b/src/views/setup/types.ts index cdacae4cc..5fe979401 100644 --- a/src/views/setup/types.ts +++ b/src/views/setup/types.ts @@ -29,6 +29,7 @@ export interface IdfSetup { toolsPath: string; idfPath: string; gitPath: string; + sysPythonPath: string; isValid: boolean; } From b05f4d46e8dfa8e5775799fba989e9d926699e39 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Thu, 9 Jan 2025 11:29:09 +0800 Subject: [PATCH 2/9] idf pythonInstallPath saved as workspace folder setting --- package.json | 2 +- src/examples/ExamplesPanel.ts | 11 +++++------ src/newProject/newProjectInit.ts | 6 ++---- src/newProject/newProjectPanel.ts | 14 ++++++-------- src/newProject/utils.ts | 15 +++++++++------ src/pythonManager.ts | 19 ++++++++++--------- src/setup/pyReqsInstallStep.ts | 6 ------ src/setup/setupInit.ts | 13 +++++++------ 8 files changed, 40 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index e3589ba88..43de6f021 100644 --- a/package.json +++ b/package.json @@ -677,7 +677,7 @@ "type": "string", "default": "python", "description": "%param.pythonBinPath%", - "scope": "application" + "scope": "resource" }, "idf.flashBaudRate": { "type": "string", diff --git a/src/examples/ExamplesPanel.ts b/src/examples/ExamplesPanel.ts index dbe4e30a2..e05494955 100644 --- a/src/examples/ExamplesPanel.ts +++ b/src/examples/ExamplesPanel.ts @@ -122,8 +122,7 @@ export class ExamplesPlanel { ); await this.setCurrentSettingsInTemplate( settingsJsonPath, - idfSetup.idfPath, - idfSetup.toolsPath + idfSetup ); vscode.commands.executeCommand("vscode.openFolder", projectPath); } catch (error) { @@ -219,13 +218,13 @@ export class ExamplesPlanel { private async setCurrentSettingsInTemplate( settingsJsonPath: string, - idfPathDir: string, - toolsPath: string + idfSetup: IdfSetup ) { const settingsJson = await readJSON(settingsJsonPath); const isWin = process.platform === "win32" ? "Win" : ""; - settingsJson["idf.espIdfPath" + isWin] = idfPathDir; - settingsJson["idf.toolsPath" + isWin] = toolsPath; + settingsJson["idf.espIdfPath" + isWin] = idfSetup.idfPath; + settingsJson["idf.toolsPath" + isWin] = idfSetup.toolsPath; + settingsJson["idf.pythonInstallPath"] = idfSetup.sysPythonPath; await writeJSON(settingsJsonPath, settingsJson, { spaces: vscode.workspace.getConfiguration().get("editor.tabSize") || 2, }); diff --git a/src/newProject/newProjectInit.ts b/src/newProject/newProjectInit.ts index c498503a7..3b0de33bf 100644 --- a/src/newProject/newProjectInit.ts +++ b/src/newProject/newProjectInit.ts @@ -27,8 +27,7 @@ import { getPreviousIdfSetups } from "../setup/existingIdfSetups"; import { IdfSetup } from "../views/setup/types"; export interface INewProjectArgs { - espIdfPath: string; - espIdfToolsPath: string; + espIdfSetup: IdfSetup; espAdfPath: string; espMdfPath: string; espMatterPath: string; @@ -149,9 +148,8 @@ export async function getNewProjectArgs( return { boards: espBoards, components, - espIdfToolsPath: idfSetup.toolsPath, + espIdfSetup: idfSetup, espAdfPath: adfExists ? espAdfPath : undefined, - espIdfPath: idfExists ? idfSetup.idfPath : undefined, espMdfPath: mdfExists ? espMdfPath : undefined, espMatterPath: matterExists ? espMatterPath : undefined, espHomeKitSdkPath: homekitSdkExists ? espHomeKitSdkPath : undefined, diff --git a/src/newProject/newProjectPanel.ts b/src/newProject/newProjectPanel.ts index 316779a05..b98513f94 100644 --- a/src/newProject/newProjectPanel.ts +++ b/src/newProject/newProjectPanel.ts @@ -22,6 +22,7 @@ import * as utils from "../utils"; import { IExample } from "../examples/Example"; import { setCurrentSettingsInTemplate } from "./utils"; import { NotificationMode, readParameter } from "../idfConfiguration"; +import { IdfSetup } from "../views/setup/types"; export class NewProjectPanel { public static currentPanel: NewProjectPanel | undefined; @@ -70,8 +71,8 @@ export class NewProjectPanel { if (newProjectArgs.espAdfPath) { localResourceRoots.push(vscode.Uri.file(newProjectArgs.espAdfPath)); } - if (newProjectArgs.espIdfPath) { - localResourceRoots.push(vscode.Uri.file(newProjectArgs.espIdfPath)); + if (newProjectArgs.espIdfSetup.idfPath) { + localResourceRoots.push(vscode.Uri.file(newProjectArgs.espIdfSetup.idfPath)); } if (newProjectArgs.espMdfPath) { localResourceRoots.push(vscode.Uri.file(newProjectArgs.espMdfPath)); @@ -124,8 +125,7 @@ export class NewProjectPanel { message.template ) { this.createProject( - newProjectArgs.espIdfPath, - newProjectArgs.espIdfToolsPath, + newProjectArgs.espIdfSetup, JSON.parse(message.components), message.port, message.containerFolder, @@ -199,8 +199,7 @@ export class NewProjectPanel { } private async createProject( - idfPath: string, - idfToolsPath: string, + idfSetup: IdfSetup, components: IComponent[], port: string, projectDirectory: string, @@ -287,8 +286,7 @@ export class NewProjectPanel { ); const settingsJson = await setCurrentSettingsInTemplate( settingsJsonPath, - idfPath, - idfToolsPath, + idfSetup, port, openOcdConfigs, workspaceFolder diff --git a/src/newProject/utils.ts b/src/newProject/utils.ts index 195a1d7a5..e55c40b27 100644 --- a/src/newProject/utils.ts +++ b/src/newProject/utils.ts @@ -19,11 +19,11 @@ import { readParameter } from "../idfConfiguration"; import { readJSON } from "fs-extra"; import { Uri } from "vscode"; +import { IdfSetup } from "../views/setup/types"; export async function setCurrentSettingsInTemplate( settingsJsonPath: string, - idfPathDir: string, - toolsPath: string, + idfSetup: IdfSetup, port: string, openOcdConfigs?: string, workspace?: Uri @@ -32,8 +32,11 @@ export async function setCurrentSettingsInTemplate( const adfPathDir = readParameter("idf.espAdfPath", workspace); const mdfPathDir = readParameter("idf.espMdfPath", workspace); const isWin = process.platform === "win32" ? "Win" : ""; - if (idfPathDir) { - settingsJson["idf.espIdfPath" + isWin] = idfPathDir; + if (idfSetup.idfPath) { + settingsJson["idf.espIdfPath" + isWin] = idfSetup.idfPath; + } + if (idfSetup.sysPythonPath) { + settingsJson["idf.pythonInstallPath"] = idfSetup.sysPythonPath; } if (adfPathDir) { settingsJson["idf.espAdfPath" + isWin] = adfPathDir; @@ -50,8 +53,8 @@ export async function setCurrentSettingsInTemplate( if (port.indexOf("no port") === -1) { settingsJson["idf.port" + isWin] = port; } - if (toolsPath) { - settingsJson["idf.toolsPath" + isWin] = toolsPath; + if (idfSetup.toolsPath) { + settingsJson["idf.toolsPath" + isWin] = idfSetup.toolsPath; } return settingsJson; } diff --git a/src/pythonManager.ts b/src/pythonManager.ts index 111d24e95..a74eb9ac2 100644 --- a/src/pythonManager.ts +++ b/src/pythonManager.ts @@ -141,12 +141,6 @@ export async function installPythonEnvFromIdfTools( }); } - await writeParameter( - "idf.pythonInstallPath", - pythonBinPath, - ConfigurationTarget.Global - ); - await execProcessWithLog( pythonBinPath, [idfToolsPyPath, "install-python-env"], @@ -309,7 +303,10 @@ export async function execProcessWithLog( } export async function getVirtualEnvPythonPath(workspaceFolder: Uri) { - let pythonPath = readParameter("idf.pythonInstallPath") as string; + let pythonPath = readParameter( + "idf.pythonInstallPath", + workspaceFolder + ) as string; let espIdfDir = readParameter("idf.espIdfPath", workspaceFolder) as string; let idfToolsDir = readParameter("idf.toolsPath", workspaceFolder) as string; const idfPathExists = await pathExists(espIdfDir); @@ -327,7 +324,10 @@ export async function getVirtualEnvPythonPath(workspaceFolder: Uri) { } export async function getPythonPath(workspaceFolder: Uri) { - let sysPythonBinPath = readParameter("idf.pythonInstallPath") as string; + let sysPythonBinPath = readParameter( + "idf.pythonInstallPath", + workspaceFolder + ) as string; const doesSysPythonBinPathExist = await pathExists(sysPythonBinPath); if (!doesSysPythonBinPathExist) { sysPythonBinPath = await getSystemPython(workspaceFolder); @@ -335,7 +335,8 @@ export async function getPythonPath(workspaceFolder: Uri) { await writeParameter( "idf.pythonInstallPath", sysPythonBinPath, - ConfigurationTarget.Global + ConfigurationTarget.WorkspaceFolder, + workspaceFolder ); } } diff --git a/src/setup/pyReqsInstallStep.ts b/src/setup/pyReqsInstallStep.ts index 00d0513e6..8eb0b0493 100644 --- a/src/setup/pyReqsInstallStep.ts +++ b/src/setup/pyReqsInstallStep.ts @@ -19,7 +19,6 @@ import { SetupPanel } from "./SetupPanel"; import { saveSettings } from "./setupInit"; import { getOpenOcdRules } from "./addOpenOcdRules"; import { addIdfPath } from "./espIdfJson"; -import { writeParameter } from "../idfConfiguration"; export async function createPyReqs( idfPath: string, @@ -46,11 +45,6 @@ export async function createPyReqs( progress, cancelToken ); - await writeParameter( - "idf.pythonInstallPath", - pyPath, - vscode.ConfigurationTarget.Global - ); await saveSettings( idfPath, toolsPath, diff --git a/src/setup/setupInit.ts b/src/setup/setupInit.ts index 03b51c42a..868ba082e 100644 --- a/src/setup/setupInit.ts +++ b/src/setup/setupInit.ts @@ -22,11 +22,7 @@ import { pathExists } from "fs-extra"; import path from "path"; import { Logger } from "../logger/logger"; import * as idfConf from "../idfConfiguration"; -import { - addIdfPath, - getPropertyFromJson, - getSelectedIdfInstalled, -} from "./espIdfJson"; +import { getPropertyFromJson, getSelectedIdfInstalled } from "./espIdfJson"; import { createIdfSetup, getPreviousIdfSetups, @@ -35,7 +31,6 @@ import { import { checkPyVenv } from "./setupValidation/pythonEnv"; import { packageJson } from "../utils"; import { getPythonPath, getVirtualEnvPythonPath } from "../pythonManager"; -import { getCurrentIdfSetup } from "../versionSwitcher"; import { CommandKeys, createCommandDictionary } from "../cmdTreeView/cmdStore"; export interface ISetupInitArgs { @@ -325,6 +320,12 @@ export async function saveSettings( gitPath, ConfigurationTarget.Global ); + await idfConf.writeParameter( + "idf.pythonInstallPath", + sysPythonBinPath, + confTarget, + workspaceFolder + ); let currentIdfSetup = await createIdfSetup( espIdfPath, toolsPath, From 3be6d274b14fa41b0450ba22cc7ae02bbcc75c31 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Thu, 9 Jan 2025 16:18:33 +0800 Subject: [PATCH 3/9] fix project tests --- src/test/project.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/project.test.ts b/src/test/project.test.ts index c7cb69e4c..ab1834fb9 100644 --- a/src/test/project.test.ts +++ b/src/test/project.test.ts @@ -29,6 +29,7 @@ import { setExtensionContext, updateProjectNameInCMakeLists, } from "../utils"; +import { IdfSetup } from "../views/setup/types"; suite("Project tests", () => { const absPath = (filename) => resolve(__dirname, "..", "..", filename); @@ -147,10 +148,15 @@ suite("Project tests", () => { assert.equal(settingsJson["idf.espIdfPath"], undefined); const openOcdConfigs = "interface/ftdi/esp32_devkitj_v1.cfg,target/esp32.cfg"; + + const idfSetup = { + idfPath: process.env.IDF_PATH, + toolsPath: process.env.IDF_TOOLS_PATH, + sysPythonPath: "python" + } as IdfSetup; const newSettingsJson = await setCurrentSettingsInTemplate( settingsJsonPath, - process.env.IDF_PATH, - process.env.IDF_TOOLS_PATH, + idfSetup, "no port", openOcdConfigs, Uri.file(projectPath) From abfd49168ecac82a7b7f85f84887c7745573fa5f Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 13 Jan 2025 16:32:54 +0800 Subject: [PATCH 4/9] log cCppPropertiesJson --- src/utils.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 9e1d9d962..92c7260ff 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -322,11 +322,8 @@ export async function updateCCppPropertiesJson( cCppPropertiesJson.configurations && cCppPropertiesJson.configurations.length ) { - const buildDirPath = idfConf.readParameter( - "idf.buildPath", - workspaceUri - ) as string; cCppPropertiesJson.configurations[0][fieldToUpdate] = newFieldValue; + console.log(`BLaBLABLA ${cCppPropertiesJson}`); await writeJSON(cCppPropertiesJsonPath, cCppPropertiesJson, { spaces: vscode.workspace.getConfiguration().get("editor.tabSize") || 2, }); From fbb8b695e88a89528558438c75d4075882b853b0 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 13 Jan 2025 16:46:12 +0800 Subject: [PATCH 5/9] add more logs --- src/test/project.test.ts | 1 + src/utils.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/project.test.ts b/src/test/project.test.ts index ab1834fb9..0b56c1925 100644 --- a/src/test/project.test.ts +++ b/src/test/project.test.ts @@ -47,6 +47,7 @@ suite("Project tests", () => { }); test("vscode folder creation", async () => { + console.log(`BLaBLABLA ${targetFolder}`); await createVscodeFolder(Uri.file(targetFolder)); const resultFiles = await readdir(join(targetFolder, ".vscode")); assert.equal(resultFiles.includes("c_cpp_properties.json"), true); diff --git a/src/utils.ts b/src/utils.ts index 92c7260ff..1bb200b91 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -254,6 +254,7 @@ export async function createVscodeFolder(curWorkspaceFsPath: vscode.Uri) { await copy(fSrcPath, fPath); } } + console.log(`BLaBLABLA createVscodeFolder ${curWorkspaceFsPath.fsPath}`); await setCCppPropertiesJsonCompilerPath(curWorkspaceFsPath); } @@ -279,6 +280,8 @@ export async function setCCppPropertiesJsonCompilerPath( ? "${config:idf.toolsPathWin}" : "${config:idf.toolsPath}"; + + console.log(`BLaBLABLA setCCppPropertiesJsonCompilerPath ${curWorkspaceFsPath.fsPath}`); await updateCCppPropertiesJson( curWorkspaceFsPath, "compilerPath", @@ -323,7 +326,6 @@ export async function updateCCppPropertiesJson( cCppPropertiesJson.configurations.length ) { cCppPropertiesJson.configurations[0][fieldToUpdate] = newFieldValue; - console.log(`BLaBLABLA ${cCppPropertiesJson}`); await writeJSON(cCppPropertiesJsonPath, cCppPropertiesJson, { spaces: vscode.workspace.getConfiguration().get("editor.tabSize") || 2, }); From 2484a8a7ecef90f75f7c45a4c3ed39ea850bf8ed Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 13 Jan 2025 16:48:10 +0800 Subject: [PATCH 6/9] fix lint --- src/utils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 1bb200b91..45fa1ac42 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -280,8 +280,9 @@ export async function setCCppPropertiesJsonCompilerPath( ? "${config:idf.toolsPathWin}" : "${config:idf.toolsPath}"; - - console.log(`BLaBLABLA setCCppPropertiesJsonCompilerPath ${curWorkspaceFsPath.fsPath}`); + console.log( + `BLaBLABLA setCCppPropertiesJsonCompilerPath ${curWorkspaceFsPath.fsPath}` + ); await updateCCppPropertiesJson( curWorkspaceFsPath, "compilerPath", From 18dac4e8e8d33ac180ed37fb4655633b8ec68912 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 13 Jan 2025 17:08:01 +0800 Subject: [PATCH 7/9] update rw c cpp properties json --- src/test/project.test.ts | 1 - src/utils.ts | 1 - testFiles/testWorkspace/.vscode/c_cpp_properties.json | 0 3 files changed, 2 deletions(-) mode change 100644 => 100755 testFiles/testWorkspace/.vscode/c_cpp_properties.json diff --git a/src/test/project.test.ts b/src/test/project.test.ts index 0b56c1925..ab1834fb9 100644 --- a/src/test/project.test.ts +++ b/src/test/project.test.ts @@ -47,7 +47,6 @@ suite("Project tests", () => { }); test("vscode folder creation", async () => { - console.log(`BLaBLABLA ${targetFolder}`); await createVscodeFolder(Uri.file(targetFolder)); const resultFiles = await readdir(join(targetFolder, ".vscode")); assert.equal(resultFiles.includes("c_cpp_properties.json"), true); diff --git a/src/utils.ts b/src/utils.ts index 45fa1ac42..baffb824e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -254,7 +254,6 @@ export async function createVscodeFolder(curWorkspaceFsPath: vscode.Uri) { await copy(fSrcPath, fPath); } } - console.log(`BLaBLABLA createVscodeFolder ${curWorkspaceFsPath.fsPath}`); await setCCppPropertiesJsonCompilerPath(curWorkspaceFsPath); } diff --git a/testFiles/testWorkspace/.vscode/c_cpp_properties.json b/testFiles/testWorkspace/.vscode/c_cpp_properties.json old mode 100644 new mode 100755 From 1822039b13029406d3ae6cd73648b69605e28718 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 13 Jan 2025 17:14:57 +0800 Subject: [PATCH 8/9] test ci python install path --- testFiles/testWorkspace/.vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testFiles/testWorkspace/.vscode/settings.json b/testFiles/testWorkspace/.vscode/settings.json index c8fecd193..eb2b2f032 100644 --- a/testFiles/testWorkspace/.vscode/settings.json +++ b/testFiles/testWorkspace/.vscode/settings.json @@ -12,5 +12,5 @@ "window.dialogStyle": "custom", "idf.notificationMode": "Output", "idf.showOnboardingOnInit": false, - "idf.pythonInstallPath": "python" + "idf.pythonInstallPath": "/usr/bin/python3" } \ No newline at end of file From 3d1537edaede7d7061ec71ce128d7517e5bb572a Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Tue, 14 Jan 2025 19:35:47 +0800 Subject: [PATCH 9/9] add both venv sys python --- src/checkExtensionSettings.ts | 2 +- src/setup/setupInit.ts | 25 +++++++++++++++--------- src/setup/setupValidation/espIdfSetup.ts | 19 +++++++++++------- src/utils.ts | 9 +++------ src/views/setup/types.ts | 3 ++- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/checkExtensionSettings.ts b/src/checkExtensionSettings.ts index ac929d419..38dad3c12 100644 --- a/src/checkExtensionSettings.ts +++ b/src/checkExtensionSettings.ts @@ -80,7 +80,7 @@ export async function checkExtensionSettings( idfPath, gitPath, toolsPath: idfToolsPath, - sysPythonPath: "python", + sysPythonPath: "/usr/bin/python3", version: idfVersion, isValid: false, }; diff --git a/src/setup/setupInit.ts b/src/setup/setupInit.ts index 868ba082e..df18054af 100644 --- a/src/setup/setupInit.ts +++ b/src/setup/setupInit.ts @@ -231,7 +231,15 @@ export async function isCurrentInstallValid(workspaceFolder: Uri) { // REMOVE this line after next release const sysPythonBinPath = await getPythonPath(workspaceFolder); - const pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder); + let pythonBinPath: string = ""; + if (sysPythonBinPath) { + pythonBinPath = await getVirtualEnvPythonPath(workspaceFolder); + } else { + pythonBinPath = idfConf.readParameter( + "idf.pythonBinPath", + workspaceFolder + ) as string; + } let espIdfPath = idfConf.readParameter("idf.espIdfPath", workspaceFolder); let idfPathVersion = await utils.getEspIdfFromCMake(espIdfPath); @@ -294,7 +302,8 @@ export async function saveSettings( sysPythonBinPath: string, saveScope: ConfigurationTarget, workspaceFolderUri: Uri, - espIdfStatusBar: StatusBarItem + espIdfStatusBar: StatusBarItem, + saveGlobalState: boolean = true ) { const confTarget = saveScope || @@ -326,18 +335,16 @@ export async function saveSettings( confTarget, workspaceFolder ); - let currentIdfSetup = await createIdfSetup( - espIdfPath, - toolsPath, - sysPythonBinPath, - gitPath - ); + const idfPathVersion = await utils.getEspIdfFromCMake(espIdfPath); + if (saveGlobalState) { + await createIdfSetup(espIdfPath, toolsPath, sysPythonBinPath, gitPath); + } if (espIdfStatusBar) { const commandDictionary = createCommandDictionary(); espIdfStatusBar.text = `$(${ commandDictionary[CommandKeys.SelectCurrentIdfVersion].iconId - }) ESP-IDF v` + currentIdfSetup.version; + }) ESP-IDF v` + idfPathVersion; } Logger.infoNotify("ESP-IDF has been configured"); } diff --git a/src/setup/setupValidation/espIdfSetup.ts b/src/setup/setupValidation/espIdfSetup.ts index b5d42fc6a..2b13c2536 100644 --- a/src/setup/setupValidation/espIdfSetup.ts +++ b/src/setup/setupValidation/espIdfSetup.ts @@ -25,7 +25,6 @@ import { Logger } from "../../logger/logger"; import { checkPyVenv } from "./pythonEnv"; import { ConfigurationTarget, StatusBarItem, Uri } from "vscode"; import { getPythonEnvPath } from "../../pythonManager"; -import { readParameter } from "../../idfConfiguration"; export async function useIdfSetupSettings( setupConf: IdfSetup, @@ -40,7 +39,8 @@ export async function useIdfSetupSettings( setupConf.sysPythonPath, saveScope, workspaceFolderUri, - espIdfStatusBar + espIdfStatusBar, + false ); } @@ -78,11 +78,16 @@ export async function checkIdfSetup( if (failedToolsResult.length) { return false; } - const virtualEnvPython = await getPythonEnvPath( - setupConf.idfPath, - setupConf.toolsPath, - setupConf.sysPythonPath - ); + let virtualEnvPython = ""; + if (setupConf.python) { + virtualEnvPython = setupConf.python; + } else { + virtualEnvPython = await getPythonEnvPath( + setupConf.idfPath, + setupConf.toolsPath, + setupConf.sysPythonPath + ); + } const pyEnvReqs = await checkPyVenv(virtualEnvPython, setupConf.idfPath); return pyEnvReqs; diff --git a/src/utils.ts b/src/utils.ts index baffb824e..7e679dbcd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -278,10 +278,6 @@ export async function setCCppPropertiesJsonCompilerPath( process.platform === "win32" ? "${config:idf.toolsPathWin}" : "${config:idf.toolsPath}"; - - console.log( - `BLaBLABLA setCCppPropertiesJsonCompilerPath ${curWorkspaceFsPath.fsPath}` - ); await updateCCppPropertiesJson( curWorkspaceFsPath, "compilerPath", @@ -1275,9 +1271,10 @@ export async function startPythonReqsProcess( "tools", "check_python_dependencies.py" ); - const modifiedEnv = await appendIdfAndToolsToPath( - extensionContext.extensionUri + const modifiedEnv: { [key: string]: string } = <{ [key: string]: string }>( + Object.assign({}, process.env) ); + modifiedEnv.IDF_PATH = espIdfPath; return execChildProcess( pythonBinPath, [reqFilePath, "-r", requirementsPath], diff --git a/src/views/setup/types.ts b/src/views/setup/types.ts index 5fe979401..a43d90868 100644 --- a/src/views/setup/types.ts +++ b/src/views/setup/types.ts @@ -29,7 +29,8 @@ export interface IdfSetup { toolsPath: string; idfPath: string; gitPath: string; - sysPythonPath: string; + python?: string; + sysPythonPath?: string; isValid: boolean; }