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

[vscode install] 4/n add retry for pip install dependencies #1294

Merged
merged 2 commits into from
Feb 22, 2024
Merged
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
1 change: 1 addition & 0 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,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