Skip to content

Commit

Permalink
use older embed python for older that idf 5 (#1021)
Browse files Browse the repository at this point in the history
* use older embed python for older that idf 5

* fix idf version check

* fix tools errors on setup

* fix lint

* fix existing setup validation
  • Loading branch information
brianignacio5 authored Aug 24, 2023
1 parent 7c0e20a commit a305386
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export namespace ESP {
export const VERSION = "2.39.2";
export const IDF_EMBED_GIT_URL = `https://dl.espressif.com/dl/idf-git/idf-git-${VERSION}-win64.zip`;
}
export namespace OLD_IDF_EMBED_PYTHON {
export const VERSION = "3.8.7";
export const IDF_EMBED_PYTHON_URL = `https://dl.espressif.com/dl/idf-python/idf-python-${VERSION}-embed-win64.zip`;
}
export namespace IDF_EMBED_PYTHON {
export const VERSION = "3.11.2";
export const IDF_EMBED_PYTHON_URL = `https://dl.espressif.com/dl/idf-python/idf-python-${VERSION}-embed-win64.zip`;
Expand Down
2 changes: 1 addition & 1 deletion src/idfToolsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export class IdfToolsManager {
const expectedVersions = pkgVersionsForPlatform.map((p) => p.name);
let isToolVersionCorrect =
expectedVersions.indexOf(versions[pkg.name]) > -1 ||
versions[pkg.name] === "No command version";
(versions[pkg.name] && versions[pkg.name] === "No command version");
const versionToUse = this.getVersionToUse(pkg);
let pkgExportedPath: string = "";
let pkgVars = pkg.export_vars;
Expand Down
31 changes: 25 additions & 6 deletions src/setup/SetupPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { createPyReqs } from "./pyReqsInstallStep";
import { downloadIdfTools } from "./toolsDownloadStep";
import { installIdfGit, installIdfPython } from "./embedGitPy";
import { getOpenOcdRules } from "./addOpenOcdRules";
import { checkSpacesInPath } from "../utils";
import { checkSpacesInPath, getEspIdfFromCMake } from "../utils";
import { useIdfSetupSettings } from "./setupValidation/espIdfSetup";
import { clearPreviousIdfSetups } from "./existingIdfSetups";

Expand Down Expand Up @@ -264,9 +264,8 @@ 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",
Expand Down Expand Up @@ -369,16 +368,31 @@ export class SetupPanel {
let idfPythonPath = pyPath,
idfGitPath = "git";
if (process.platform === "win32") {
let idfVersion = "";
if (selectedIdfVersion.filename === "manual") {
idfVersion = await getEspIdfFromCMake(espIdfPath);
} else if (selectedIdfVersion.filename === "master") {
idfVersion = "5.1";
} else {
const matches = selectedIdfVersion.name.split(" ")[0].match(/v(.+)/);
if (matches && matches.length) {
idfVersion = matches[1];
} else {
idfVersion = "5.0";
}
}
const embedPaths = await this.installEmbedPyGit(
toolsPath,
idfVersion,
progress,
cancelToken
);
idfGitPath = embedPaths.idfGitPath;
idfPythonPath = embedPaths.idfPythonPath;
}
const pathToCheck = selectedIdfVersion.filename === "manual" ? espIdfPath : idfContainerPath;
this.checkSpacesInPaths(
espIdfPath,
pathToCheck,
toolsPath,
idfGitPath,
idfPythonPath
Expand Down Expand Up @@ -422,7 +436,8 @@ export class SetupPanel {
);
const updatedToolsInfo = toolsInfo.map((tool) => {
const isToolVersionCorrect =
tool.expected.indexOf(foundVersions[tool.name]) > -1;
tool.expected.indexOf(foundVersions[tool.name]) > -1 ||
(foundVersions[tool.name] && foundVersions[tool.name] === "No command version");
tool.doesToolExist = isToolVersionCorrect;
if (isToolVersionCorrect) {
tool.progress = "100.00%";
Expand Down Expand Up @@ -484,8 +499,10 @@ export class SetupPanel {
let idfPythonPath = pyPath,
idfGitPath = gitPath || "/usr/bin/git";
if (process.platform === "win32") {
const idfVersion = await getEspIdfFromCMake(idfPath);
const embedPaths = await this.installEmbedPyGit(
toolsPath,
idfVersion,
progress,
cancelToken
);
Expand Down Expand Up @@ -561,6 +578,7 @@ export class SetupPanel {

private async installEmbedPyGit(
toolsPath: string,
idfVersion: string,
progress: vscode.Progress<{ message: string; increment?: number }>,
cancelToken: vscode.CancellationToken
) {
Expand All @@ -571,6 +589,7 @@ export class SetupPanel {
});
const idfPythonPath = await installIdfPython(
toolsPath,
idfVersion,
progress,
cancelToken
);
Expand Down
37 changes: 27 additions & 10 deletions src/setup/embedGitPy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function installIdfGit(
if (!binVersion || binVersion === "Not found") {
const msg = `Using existing ${idfGitDestPath}`;
OutputChannel.appendLine(msg);
Logger.info(msg)
Logger.info(msg);
return resultGitPath;
}
}
Expand Down Expand Up @@ -108,28 +108,33 @@ export async function installIdfGit(

export async function installIdfPython(
idfToolsDir: string,
idfVersion: string,
progress?: Progress<{ message: string; increment?: number }>,
cancelToken?: CancellationToken
) {
const downloadManager = new DownloadManager(idfToolsDir);
const installManager = new InstallManager(idfToolsDir);
const idfPyZipPath = join(
idfToolsDir,
"dist",
basename(ESP.URL.IDF_EMBED_PYTHON.IDF_EMBED_PYTHON_URL)
);
const pythonURLToUse =
idfVersion >= "5.0"
? ESP.URL.IDF_EMBED_PYTHON.IDF_EMBED_PYTHON_URL
: ESP.URL.OLD_IDF_EMBED_PYTHON.IDF_EMBED_PYTHON_URL;
const idfPyZipPath = join(idfToolsDir, "dist", basename(pythonURLToUse));
const pkgProgress = new PackageProgress(
basename(ESP.URL.IDF_EMBED_PYTHON.IDF_EMBED_PYTHON_URL),
basename(pythonURLToUse),
sendIdfPythonDownloadProgress,
null,
sendIdfPythonDownloadDetail,
null
);
const pythonVersionToUse =
idfVersion >= "5.0"
? ESP.URL.IDF_EMBED_PYTHON.VERSION
: ESP.URL.OLD_IDF_EMBED_PYTHON.VERSION;
const idfPyDestPath = join(
idfToolsDir,
"tools",
"idf-python",
ESP.URL.IDF_EMBED_PYTHON.VERSION
pythonVersionToUse
);
const pyPathExists = await pathExists(idfPyDestPath);
if (pyPathExists) {
Expand All @@ -148,7 +153,7 @@ export async function installIdfPython(
if (!pyZipPathExists) {
progress.report({ message: `Downloading ${idfPyZipPath}...` });
await downloadManager.downloadWithRetries(
ESP.URL.IDF_EMBED_PYTHON.IDF_EMBED_PYTHON_URL,
pythonURLToUse,
join(idfToolsDir, "dist"),
pkgProgress,
cancelToken
Expand All @@ -163,6 +168,18 @@ export async function installIdfPython(
const extractePyDestMsg = `Extracted ${idfPyDestPath} ...`;
progress.report({ message: extractePyDestMsg });
OutputChannel.appendLine(extractePyDestMsg);
await spawn(join(idfPyDestPath, "python.exe"), ["-m", "ensurepip", "--upgrade"], { cwd: idfPyDestPath });
if (idfVersion >= "5.0") {
await spawn(
join(idfPyDestPath, "python.exe"),
["-m", "ensurepip", "--upgrade"],
{ cwd: idfPyDestPath }
);
} else {
await spawn(join(idfPyDestPath, "python.exe"),
["-m", "pip", "install", "virtualenv"],
{cwd : idfPyDestPath}
);
}

return join(idfPyDestPath, "python.exe");
}
6 changes: 1 addition & 5 deletions src/setup/espIdfDownloadStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,9 @@ export async function expressInstall(
const idfToolsManager = await IdfToolsManager.createIdfToolsManager(
espIdfPath
);
const exportedToolsPaths = await idfToolsManager.exportPathsInString(
join(toolsPath, "tools"),
onReqPkgs
);
const toolsInfo = await idfToolsManager.getRequiredToolsInfo(
join(toolsPath, "tools"),
exportedToolsPaths,
undefined,
onReqPkgs
);
SetupPanel.postMessage({
Expand Down
2 changes: 1 addition & 1 deletion src/setup/toolsDownloadStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function downloadIdfTools(
);
const requiredTools = await idfToolsManager.getRequiredToolsInfo(
toolsPath,
exportPaths,
undefined,
onReqPkgs
);
SetupPanel.postMessage({
Expand Down
6 changes: 5 additions & 1 deletion src/views/setup/ToolsCustom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<label for="idf-version-select" class="label">ESP-IDF Tools</label>
<div class="control">
<div class="select">
<select v-model="selectedIdfTools" data-config-id="select-esp-idf-tools">
<select
v-model="selectedIdfTools"
data-config-id="select-esp-idf-tools"
>
<option value="toolsDownload">Download ESP-IDF Tools</option>
<option value="toolsExisting">Use existing ESP-IDF Tools</option>
</select>
Expand Down Expand Up @@ -92,6 +95,7 @@ export default class CustomSetup extends Vue {
}
mounted() {
this.checkEspIdfTools();
const updatedToolsInfo = this.storeToolsResults.map((tool) => {
if (tool.doesToolExist) {
tool.progress = "100.00%";
Expand Down
2 changes: 1 addition & 1 deletion src/views/setup/components/toolDownload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
</div>
<div class="progressText">
<span v-if="tool.progress === '100.00%'">
<span v-if="tool.progress === '100.00%' && isInstallationCompleted">
<span>Checksum :</span>
{{ tool.hashResult ? "OK" : "Invalid" }}
<br />
Expand Down

0 comments on commit a305386

Please sign in to comment.