Skip to content

Install jupyter instead of installing kernel spec (#10080) #10083

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

Merged
merged 1 commit into from
Feb 12, 2020
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 news/2 Fixes/10071.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Re-install `Jupyter` instead of installing `kernelspec` if `kernelspec` cannot be found in the python environment.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ function sortProductsInOrderForInstallation(products: Product[]) {
* @returns {string}
*/
export function getMessageForLibrariesNotInstalled(products: Product[]): string {
// Even though kernelspec cannot be installed, display it so user knows what is missing.
const names = products
// Ignore kernelspec as it not something that can be installed.
.filter(product => product !== Product.kernelspec)
.map(product => ProductNames.get(product))
.filter(name => !!name)
.map(name => name as string);
Expand Down Expand Up @@ -122,15 +121,15 @@ export class JupyterInterpreterDependencyService {
_error?: JupyterInstallError,
token?: CancellationToken
): Promise<JupyterInterpreterDependencyResponse> {
const productsToInstall = await this.getDependenciesNotInstalled(interpreter, token);
const missingProducts = await this.getDependenciesNotInstalled(interpreter, token);
if (Cancellation.isCanceled(token)) {
return JupyterInterpreterDependencyResponse.cancel;
}
if (productsToInstall.length === 0) {
if (missingProducts.length === 0) {
return JupyterInterpreterDependencyResponse.ok;
}

const message = getMessageForLibrariesNotInstalled(productsToInstall);
const message = getMessageForLibrariesNotInstalled(missingProducts);

sendTelemetryEvent(Telemetry.JupyterNotInstalledErrorShown);
const selection = await this.applicationShell.showErrorMessage(
Expand All @@ -147,8 +146,15 @@ export class JupyterInterpreterDependencyService {

switch (selection) {
case DataScience.jupyterInstall(): {
// Ignore kernelspec as it not something that can be installed.
// If kernelspec isn't available, then re-install `Jupyter`.
if (missingProducts.includes(Product.kernelspec) && !missingProducts.includes(Product.jupyter)) {
missingProducts.push(Product.jupyter);
}
const productsToInstall = missingProducts.filter(product => product !== Product.kernelspec);
// Install jupyter, then notebook, then others in that order.
sortProductsInOrderForInstallation(productsToInstall);

let productToInstall = productsToInstall.shift();
const cancellatonPromise = createPromiseFromCancellation({ cancelAction: 'resolve', defaultValue: InstallerResponse.Ignore, token });
while (productToInstall) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Architecture } from '../../../../client/common/utils/platform';
import { JupyterInterpreterDependencyResponse, JupyterInterpreterDependencyService } from '../../../../client/datascience/jupyter/interpreter/jupyterInterpreterDependencyService';
import { InterpreterType, PythonInterpreter } from '../../../../client/interpreter/contracts';

// tslint:disable-next-line: max-func-body-length
suite('Data Science - Jupyter Interpreter Configuration', () => {
let configuration: JupyterInterpreterDependencyService;
let appShell: IApplicationShell;
Expand Down Expand Up @@ -62,6 +63,24 @@ suite('Data Science - Jupyter Interpreter Configuration', () => {
test('Prompt to install if Jupyter is not installed', async () => testPromptIfModuleNotInstalled(false, true));
test('Prompt to install if notebook is not installed', async () => testPromptIfModuleNotInstalled(true, false));
test('Prompt to install if jupyter & notebook is not installed', async () => testPromptIfModuleNotInstalled(false, false));
test('Reinstall Jupyter if jupyter and notebook are installed but kernelspec is not found', async () => {
when(installer.isInstalled(Product.jupyter, pythonInterpreter)).thenResolve(true);
when(installer.isInstalled(Product.notebook, pythonInterpreter)).thenResolve(true);
when(appShell.showErrorMessage(anything(), anything(), anything(), anything())).thenResolve(
// tslint:disable-next-line: no-any
DataScience.jupyterInstall() as any
);
when(pythonExecService.execModule('jupyter', deepEqual(['kernelspec', '--version']), anything())).thenReject(new Error('Not found'));
when(installer.install(anything(), anything(), anything())).thenResolve(InstallerResponse.Installed);

const response = await configuration.installMissingDependencies(pythonInterpreter);

// Jupyter must be installed & not kernelspec or anything else.
verify(installer.install(Product.jupyter, anything(), anything())).once();
verify(installer.install(anything(), anything(), anything())).once();
verify(appShell.showErrorMessage(anything(), DataScience.jupyterInstall(), DataScience.selectDifferentJupyterInterpreter(), anything())).once();
assert.equal(response, JupyterInterpreterDependencyResponse.cancel);
});

async function testInstallationOfJupyter(installerResponse: InstallerResponse, expectedConfigurationReponse: JupyterInterpreterDependencyResponse): Promise<void> {
when(installer.isInstalled(Product.jupyter, pythonInterpreter)).thenResolve(false);
Expand Down