Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VSC-1546] fix version switch by persist sys python in idfSetup #1384

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@
"type": "string",
"default": "python",
"description": "%param.pythonBinPath%",
"scope": "application"
"scope": "resource"
},
"idf.flashBaudRate": {
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions src/checkExtensionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export async function checkExtensionSettings(
idfPath,
gitPath,
toolsPath: idfToolsPath,
sysPythonPath: "python",
version: idfVersion,
isValid: false,
};
Expand Down
11 changes: 5 additions & 6 deletions src/examples/ExamplesPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ export class ExamplesPlanel {
);
await this.setCurrentSettingsInTemplate(
settingsJsonPath,
idfSetup.idfPath,
idfSetup.toolsPath
idfSetup
);
vscode.commands.executeCommand("vscode.openFolder", projectPath);
} catch (error) {
Expand Down Expand Up @@ -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,
});
Expand Down
6 changes: 2 additions & 4 deletions src/newProject/newProjectInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions src/newProject/newProjectPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -199,8 +199,7 @@ export class NewProjectPanel {
}

private async createProject(
idfPath: string,
idfToolsPath: string,
idfSetup: IdfSetup,
components: IComponent[],
port: string,
projectDirectory: string,
Expand Down Expand Up @@ -287,8 +286,7 @@ export class NewProjectPanel {
);
const settingsJson = await setCurrentSettingsInTemplate(
settingsJsonPath,
idfPath,
idfToolsPath,
idfSetup,
port,
openOcdConfigs,
workspaceFolder
Expand Down
15 changes: 9 additions & 6 deletions src/newProject/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
19 changes: 10 additions & 9 deletions src/pythonManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ export async function installPythonEnvFromIdfTools(
});
}

await writeParameter(
"idf.pythonInstallPath",
pythonBinPath,
ConfigurationTarget.Global
);

await execProcessWithLog(
pythonBinPath,
[idfToolsPyPath, "install-python-env"],
Expand Down Expand Up @@ -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);
Expand All @@ -327,15 +324,19 @@ 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);
if (sysPythonBinPath) {
await writeParameter(
"idf.pythonInstallPath",
sysPythonBinPath,
ConfigurationTarget.Global
ConfigurationTarget.WorkspaceFolder,
workspaceFolder
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/setup/existingIdfSetups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function clearPreviousIdfSetups() {
export async function createIdfSetup(
idfPath: string,
toolsPath: string,
sysPythonBinPath: string,
gitPath: string
) {
const idfSetupId = getIdfMd5sum(idfPath);
Expand All @@ -68,6 +69,7 @@ export async function createIdfSetup(
idfPath,
gitPath,
toolsPath,
sysPythonPath: sysPythonBinPath,
version: idfVersion,
isValid: false,
};
Expand Down
7 changes: 1 addition & 6 deletions src/setup/pyReqsInstallStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -46,15 +45,11 @@ export async function createPyReqs(
progress,
cancelToken
);
await writeParameter(
"idf.pythonInstallPath",
pyPath,
vscode.ConfigurationTarget.Global
);
await saveSettings(
idfPath,
toolsPath,
gitPath,
pyPath,
saveScope,
workspaceFolderUri,
espIdfStatusBar
Expand Down
21 changes: 14 additions & 7 deletions src/setup/setupInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -296,6 +291,7 @@ export async function saveSettings(
espIdfPath: string,
toolsPath: string,
gitPath: string,
sysPythonBinPath: string,
saveScope: ConfigurationTarget,
workspaceFolderUri: Uri,
espIdfStatusBar: StatusBarItem
Expand Down Expand Up @@ -324,7 +320,18 @@ export async function saveSettings(
gitPath,
ConfigurationTarget.Global
);
let currentIdfSetup = await createIdfSetup(espIdfPath, toolsPath, gitPath);
await idfConf.writeParameter(
"idf.pythonInstallPath",
sysPythonBinPath,
confTarget,
workspaceFolder
);
let currentIdfSetup = await createIdfSetup(
espIdfPath,
toolsPath,
sysPythonBinPath,
gitPath
);
if (espIdfStatusBar) {
const commandDictionary = createCommandDictionary();
espIdfStatusBar.text =
Expand Down
16 changes: 11 additions & 5 deletions src/setup/setupValidation/espIdfSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/test/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
setExtensionContext,
updateProjectNameInCMakeLists,
} from "../utils";
import { IdfSetup } from "../views/setup/types";

suite("Project tests", () => {
const absPath = (filename) => resolve(__dirname, "..", "..", filename);
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ export async function setCCppPropertiesJsonCompilerPath(
? "${config:idf.toolsPathWin}"
: "${config:idf.toolsPath}";

console.log(
`BLaBLABLA setCCppPropertiesJsonCompilerPath ${curWorkspaceFsPath.fsPath}`
);
await updateCCppPropertiesJson(
curWorkspaceFsPath,
"compilerPath",
Expand Down Expand Up @@ -322,10 +325,6 @@ export async function updateCCppPropertiesJson(
cCppPropertiesJson.configurations &&
cCppPropertiesJson.configurations.length
) {
const buildDirPath = idfConf.readParameter(
"idf.buildPath",
workspaceUri
) as string;
cCppPropertiesJson.configurations[0][fieldToUpdate] = newFieldValue;
await writeJSON(cCppPropertiesJsonPath, cCppPropertiesJson, {
spaces: vscode.workspace.getConfiguration().get("editor.tabSize") || 2,
Expand Down
1 change: 1 addition & 0 deletions src/versionSwitcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export async function getCurrentIdfSetup(workspaceFolder: Uri,
idfPath,
gitPath,
toolsPath,
sysPythonPath: sysPythonBinPath,
version: idfVersion,
isValid: false,
};
Expand Down
1 change: 1 addition & 0 deletions src/views/setup/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IdfSetup {
toolsPath: string;
idfPath: string;
gitPath: string;
sysPythonPath: string;
isValid: boolean;
}

Expand Down
Empty file modified testFiles/testWorkspace/.vscode/c_cpp_properties.json
100644 → 100755
Empty file.
Loading
Loading