Skip to content

Commit

Permalink
Merged PR posit-dev/positron-python#120: add a progress indicator and…
Browse files Browse the repository at this point in the history
… cancel button during ipykernel install

Merge pull request #120 from posit-dev/ipykernel-progress-and-cancel

add a progress indicator and cancel button during ipykernel install
--------------------
Commit message for posit-dev/positron-python@d8c04ec:

add a progress indicator and cancel button during ipykernel install


Authored-by: Wasim Lorgat <[email protected]>
Signed-off-by: Wasim Lorgat <[email protected]>
  • Loading branch information
seeM authored and wesm committed Mar 28, 2024
1 parent 0c0b0ed commit 9d901d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,14 @@ export class PythonLanguageRuntime implements JupyterLanguageRuntime, Disposable
// Thow an error if it could not be installed.
const hasKernel = await this.installer.isInstalled(Product.ipykernel, this.interpreter);
if (!hasKernel) {
// Pass a cancellation token to enable VSCode's progress indicator and let the user
// cancel the install.
const tokenSource = new vscode.CancellationTokenSource();
const installerToken = tokenSource.token;

const response = await this.installer.promptToInstall(Product.ipykernel,
this.interpreter, undefined, undefined, this.installOptions);
this.interpreter, installerToken, undefined, this.installOptions);

switch (response) {
case InstallerResponse.Installed:
traceVerbose(`Successfully installed ipykernel for ${this.interpreter?.displayName}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IApplicationShell } from '../application/types';
import { wrapCancellationTokens } from '../cancellation';
import { IFileSystem } from '../platform/types';
import * as internalPython from '../process/internal/python';
import { IProcessServiceFactory } from '../process/types';
import { IProcessServiceFactory, SpawnOptions } from '../process/types';
import { ITerminalServiceFactory, TerminalCreationOptions } from '../terminal/types';
import { ExecutionInfo, IConfigurationService, ILogOutputChannel, Product } from '../types';
import { isResource } from '../utils/misc';
Expand All @@ -31,7 +31,7 @@ export abstract class ModuleInstaller implements IModuleInstaller {

public abstract get type(): ModuleInstallerType;

constructor(protected serviceContainer: IServiceContainer) {}
constructor(protected serviceContainer: IServiceContainer) { }

public async installModule(
productOrModuleName: Product | string,
Expand Down Expand Up @@ -230,7 +230,12 @@ export abstract class ModuleInstaller implements IModuleInstaller {
);
await processService.shellExec(quoted);
} else {
await processService.exec(command, args);
// --- Start Positron ---
// Pass the cancellation token through so that users can cancel installs via the UI
// when executeInTerminal is false
const spawnOptions: SpawnOptions = { token };
await processService.exec(command, args, spawnOptions);
// --- End Positron ---
}
}
}
Expand Down

0 comments on commit 9d901d5

Please sign in to comment.