-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updater for the runner (#1042)
### Summary of Changes Add a command to automatically update the runner to a suitable version.
- Loading branch information
1 parent
622740d
commit 610d45b
Showing
6 changed files
with
114 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/safe-ds-vscode/src/extension/commands/updateRunner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import vscode, { ExtensionContext } from 'vscode'; | ||
import { LanguageClient } from 'vscode-languageclient/node.js'; | ||
import { rpc, SafeDsServices } from '@safe-ds/lang'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import { installRunner, installRunnerInVirtualEnvironment } from './installRunner.js'; | ||
import { platform } from 'node:os'; | ||
import { logError } from '../output.js'; | ||
|
||
export const updateRunner = (context: ExtensionContext, client: LanguageClient, services: SafeDsServices) => { | ||
return async () => { | ||
// If the runner is already started, do nothing | ||
if (services.runtime.Runner.isPythonServerAvailable()) { | ||
vscode.window.showInformationMessage('The runner is already installed and running.'); | ||
return; | ||
} | ||
|
||
// If the runner executable cannot be found at all, install it from scratch | ||
if (!fs.existsSync(await getRunnerCommand())) { | ||
await installRunner(context, client, services)(); | ||
return; | ||
} | ||
|
||
// Update the runner if it is already installed | ||
const success = await doUpdateRunner(); | ||
if (!success) { | ||
return; | ||
} | ||
|
||
// Start the runner (needed if the configuration did not change, so no event is fired) | ||
await client.sendNotification(rpc.runnerStart); | ||
|
||
// Inform the user | ||
vscode.window.showInformationMessage('The runner has been updated successfully.'); | ||
}; | ||
}; | ||
|
||
const doUpdateRunner = async (): Promise<boolean> => { | ||
// Check if pip is available | ||
const pipCommand = await getPipCommand(); | ||
if (!pipCommand) { | ||
vscode.window.showErrorMessage('Failed to find pip.'); | ||
logError('Failed to find pip.'); | ||
return false; | ||
} | ||
|
||
// Install the runner in the virtual environment | ||
return vscode.window.withProgress( | ||
{ | ||
location: vscode.ProgressLocation.Window, | ||
title: 'Installing the runner (this may take a few minutes)...', | ||
}, | ||
async () => { | ||
try { | ||
await installRunnerInVirtualEnvironment(pipCommand); | ||
return true; | ||
} catch (error) { | ||
vscode.window.showErrorMessage('Failed to install the runner.'); | ||
logError(String(error)); | ||
return false; | ||
} | ||
}, | ||
); | ||
}; | ||
|
||
const getRunnerCommand = async (): Promise<string> => { | ||
return vscode.workspace.getConfiguration('safe-ds.runner').get('command') ?? ''; | ||
}; | ||
|
||
const getPipCommand = async (): Promise<string | undefined> => { | ||
const runnerCommand = await getRunnerCommand(); | ||
if (!runnerCommand) { | ||
return; | ||
} | ||
|
||
const runnerDir = path.dirname(runnerCommand); | ||
if (platform() === 'win32') { | ||
return path.join(runnerDir, 'pip.exe'); | ||
} else { | ||
return path.join(runnerDir, 'pip'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters