Skip to content

Commit

Permalink
[vscode install] 4/n add retry for pip install dependencies (#1294)
Browse files Browse the repository at this point in the history
[vscode install] 4/n add retry for pip install dependencies

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with
[ReviewStack](https://reviewstack.dev/lastmile-ai/aiconfig/pull/1294).
* #1289
* __->__ #1294
* #1290
  • Loading branch information
Ankush-lastmile authored Feb 22, 2024
2 parents 32307b6 + ea1664f commit b7a74bf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@vscode/python-extension": "^1.0.5",
"oboe": "^2.1.5",
"portfinder": "^1.0.32",
"ufetch": "^1.6.0"
Expand Down
24 changes: 21 additions & 3 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from "./util";
import { AIConfigEditorProvider } from "./aiConfigEditor";
import { AIConfigEditorManager } from "./aiConfigEditorManager";
import { PythonExtension } from "@vscode/python-extension";

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
Expand All @@ -39,7 +40,7 @@ export function activate(context: vscode.ExtensionContext) {
});

const setupCommand = vscode.commands.registerCommand(COMMANDS.INIT, () => {
installDependencies(context, extensionOutputChannel);
initialize(context, extensionOutputChannel);
});
context.subscriptions.push(setupCommand);

Expand Down Expand Up @@ -570,16 +571,18 @@ async function installRequirements(
vscode.window
.showErrorMessage(
`Failed to install dependencies. Pip exited with code ${code}. Please try again later`,
...["Retry"]
...["Select Interpreter", "Retry Install Dependencies"]
)
.then((selection) => {
if (selection === "Retry") {
if (selection === "Retry Install Dependencies") {
installRequirements(
context,
progress,
cancellationToken,
outputChannel
);
} else if (selection === "Select Interpreter") {
vscode.commands.executeCommand(COMMANDS.INIT);
}
});
resolve(false);
Expand Down Expand Up @@ -906,3 +909,18 @@ async function shareAIConfig(
});
}
}

/**
* Selects a Python interpreter and initiates the dependency installation flow.
*/
async function initialize(
context: vscode.ExtensionContext,
outputChannel: vscode.LogOutputChannel
) {
// Make sure Python API is activated
const pythonApi: PythonExtension = await PythonExtension.api();

await vscode.commands.executeCommand("python.setInterpreter");

installDependencies(context, outputChannel);
}
5 changes: 5 additions & 0 deletions vscode-extension/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@
resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406"
integrity sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==

"@vscode/python-extension@^1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@vscode/python-extension/-/python-extension-1.0.5.tgz#881878006ad3f4b70e81b20d21a91f56dd577481"
integrity sha512-uYhXUrL/gn92mfqhjAwH2+yGOpjloBxj9ekoL4BhUsKcyJMpEg6WlNf3S3si+5x9zlbHHe7FYQNjZEbz1ymI9Q==

"@vscode/test-cli@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@vscode/test-cli/-/test-cli-0.0.4.tgz#eeeb5620ff8b9eb31ae3e5b01af322ca68fcfaae"
Expand Down

0 comments on commit b7a74bf

Please sign in to comment.