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

Remove known, envPath and envName properties #15249

Merged
merged 6 commits into from
Feb 27, 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
15 changes: 9 additions & 6 deletions src/kernels/errors/kernelErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ import { PackageNotInstalledWindowsLongPathNotEnabledError } from '../../platfor
import { JupyterNotebookNotInstalled } from '../../platform/errors/jupyterNotebookNotInstalled';
import { fileToCommandArgument } from '../../platform/common/helpers';
import {
getCachedEnvironment,
getEnvironmentType,
getPythonEnvDisplayName,
getPythonEnvironmentName,
getSysPrefix,
isCondaEnvironmentWithoutPython
} from '../../platform/interpreter/helpers';
Expand Down Expand Up @@ -167,7 +169,7 @@ export abstract class DataScienceErrorHandler implements IDataScienceErrorHandle
) {
return DataScience.failedToStartKernelDueToMissingPythonEnv(
error.kernelConnectionMetadata.interpreter.displayName ||
error.kernelConnectionMetadata.interpreter.envName ||
getPythonEnvironmentName(error.kernelConnectionMetadata.interpreter) ||
getDisplayPath(error.kernelConnectionMetadata.interpreter.uri)
);
} else if (
Expand Down Expand Up @@ -452,7 +454,7 @@ export abstract class DataScienceErrorHandler implements IDataScienceErrorHandle
.showErrorMessage(
DataScience.failedToStartKernelDueToMissingPythonEnv(
kernelConnection.interpreter.displayName ||
kernelConnection.interpreter.envName ||
getPythonEnvironmentName(kernelConnection.interpreter) ||
getDisplayPath(kernelConnection.interpreter.uri)
)
)
Expand Down Expand Up @@ -617,11 +619,12 @@ function getIPyKernelMissingErrorMessageForCell(kernelConnection: KernelConnecti
getFilePath(kernelConnection.interpreter.uri)
)} -m pip install ${ipyKernelModuleName} -U --force-reinstall`;
if (kernelConnection.interpreter && getEnvironmentType(kernelConnection.interpreter) === EnvironmentType.Conda) {
if (kernelConnection.interpreter?.envName) {
installerCommand = `conda install -n ${kernelConnection.interpreter?.envName} ${ipyKernelModuleName} --update-deps --force-reinstall`;
} else if (kernelConnection.interpreter?.envPath) {
const env = getCachedEnvironment(kernelConnection.interpreter);
if (env?.environment?.name) {
installerCommand = `conda install -n ${env?.environment?.name} ${ipyKernelModuleName} --update-deps --force-reinstall`;
} else if (env?.environment?.folderUri) {
installerCommand = `conda install -p ${getFilePath(
kernelConnection.interpreter?.envPath
env?.environment?.folderUri
)} ${ipyKernelModuleName} --update-deps --force-reinstall`;
}
} else if (
Expand Down
6 changes: 4 additions & 2 deletions src/kernels/errors/kernelErrorHandler.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ Failed to run jupyter as observable with args notebook --no-browser --notebook-d
release: undefined,
sysVersion: '3.12.7'
},
environment: {
name: 'condaEnv1'
},
tools: [EnvironmentType.Conda]
} as any
]);
Expand All @@ -723,8 +726,7 @@ Failed to run jupyter as observable with args notebook --no-browser --notebook-d
new KernelDiedError('Kaboom', 'hello word does not have attribute named abc', undefined, {
...kernelConnection,
interpreter: {
...kernelConnection.interpreter!,
envName: 'condaEnv1'
...kernelConnection.interpreter!
}
}),
'start',
Expand Down
4 changes: 1 addition & 3 deletions src/kernels/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ export function getDisplayNameOrNameOfKernelConnection(kernelConnection: KernelC
const pythonVersion = `Python ${
getTelemetrySafeVersion(getCachedVersion(kernelConnection.interpreter)) || ''
}`.trim();
return kernelConnection.interpreter.envName
? `${oldDisplayName} (${pythonVersion})`
: oldDisplayName;
return envName ? `${oldDisplayName} (${pythonVersion})` : oldDisplayName;
} else {
// Non-Python kernelspec that launches via python interpreter
return envName ? `${oldDisplayName} (${envName})` : oldDisplayName;
Expand Down
37 changes: 18 additions & 19 deletions src/kernels/helpers.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something'
}
})
Expand All @@ -153,7 +152,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something 64-bit'
}
})
Expand All @@ -171,6 +169,9 @@ suite('Kernel Connection Helpers', () => {
release: undefined,
sysVersion: '9.8.7'
},
environment: {
name: '.env'
},
tools: [EnvironmentType.Conda]
} as any
]);
Expand All @@ -186,7 +187,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '.env',
displayName: 'Something'
}
})
Expand All @@ -204,6 +204,9 @@ suite('Kernel Connection Helpers', () => {
release: undefined,
sysVersion: '9.8.7'
},
environment: {
name: '.env'
},
tools: [EnvironmentType.Conda]
} as any
]);
Expand All @@ -219,7 +222,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '.env',
displayName: 'Something 64-bit'
}
})
Expand Down Expand Up @@ -258,7 +260,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '.env',
displayName: 'Something 64-bit'
}
})
Expand All @@ -279,7 +280,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '.env',
displayName: 'Something 64-bit'
}
})
Expand All @@ -300,7 +300,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something'
}
})
Expand All @@ -321,7 +320,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something 64-bit'
}
})
Expand All @@ -342,7 +340,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something 64-bit'
}
})
Expand All @@ -360,6 +357,9 @@ suite('Kernel Connection Helpers', () => {
release: undefined,
sysVersion: '9.8.7.6-pre'
},
environment: {
name: '.env'
},
tools: [EnvironmentType.Conda]
} as any
]);
Expand All @@ -376,7 +376,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '.env',
displayName: 'Something 64-bit'
}
})
Expand All @@ -394,6 +393,9 @@ suite('Kernel Connection Helpers', () => {
release: undefined,
sysVersion: '9.8.7'
},
environment: {
name: '.env'
},
tools: [EnvironmentType.Conda]
} as any
]);
Expand All @@ -410,7 +412,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '.env',
displayName: 'Something 64-bit'
}
})
Expand All @@ -433,7 +434,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something 64-bit'
}
})
Expand All @@ -454,7 +454,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something 64-bit'
}
})
Expand Down Expand Up @@ -488,7 +487,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something 64-bit'
}
})
Expand All @@ -509,7 +507,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something'
}
})
Expand All @@ -530,7 +527,6 @@ suite('Kernel Connection Helpers', () => {
interpreter: {
uri: Uri.file('pyPath'),
id: Uri.file('pyPath').fsPath,
envName: '',
displayName: 'Something 64-bit'
}
})
Expand All @@ -542,7 +538,6 @@ suite('Kernel Connection Helpers', () => {
const interpreter = mock<PythonEnvironment>();
when(kernelSpec.language).thenReturn('python');
when(interpreter.id).thenReturn('xyz');
when(interpreter.envName).thenReturn('');
when(interpreter.displayName).thenReturn('Something 64-bit');
when(environments.known).thenReturn([
{
Expand Down Expand Up @@ -572,7 +567,6 @@ suite('Kernel Connection Helpers', () => {
const interpreter = mock<PythonEnvironment>();
when(kernelSpec.language).thenReturn('python');
when(interpreter.id).thenReturn('xyz');
when(interpreter.envName).thenReturn('.env');
when(interpreter.displayName).thenReturn('Something');
when(environments.known).thenReturn([
{
Expand All @@ -584,6 +578,9 @@ suite('Kernel Connection Helpers', () => {
release: undefined,
sysVersion: '9.8.7.6-pre'
},
environment: {
name: '.env'
},
tools: [EnvironmentType.Venv]
} as any
]);
Expand All @@ -602,7 +599,6 @@ suite('Kernel Connection Helpers', () => {
const interpreter = mock<PythonEnvironment>();
when(kernelSpec.language).thenReturn('python');
when(interpreter.id).thenReturn('xyz');
when(interpreter.envName).thenReturn('.env');
when(interpreter.displayName).thenReturn('Something 64-bit');
when(environments.known).thenReturn([
{
Expand All @@ -614,6 +610,9 @@ suite('Kernel Connection Helpers', () => {
release: undefined,
sysVersion: '9.8.7.6-pre'
},
environment: {
name: '.env'
},
tools: [EnvironmentType.Venv]
} as any
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { ReportableAction } from '../../../platform/progress/types';
import { JupyterInterpreterDependencyResponse } from '../types';
import { IJupyterCommandFactory } from '../types.node';
import { getComparisonKey } from '../../../platform/vscode-path/resources';
import { getEnvironmentType } from '../../../platform/interpreter/helpers';
import {
getCachedEnvironment,
getEnvironmentType,
getPythonEnvDisplayName
} from '../../../platform/interpreter/helpers';

/**
* Sorts the given list of products (in place) in the order in which they need to be installed.
Expand Down Expand Up @@ -57,7 +61,10 @@ function sortProductsInOrderForInstallation(products: Product[]) {
*/
export function getMessageForLibrariesNotInstalled(products: Product[], interpreter: PythonEnvironment): string {
const interpreterName =
interpreter.displayName || interpreter.envName || interpreter.envPath?.fsPath || interpreter.uri.fsPath;
interpreter.displayName ||
getPythonEnvDisplayName(interpreter) ||
getCachedEnvironment(interpreter)?.environment?.folderUri?.fsPath ||
interpreter.uri.fsPath;
// Even though kernelspec cannot be installed, display it so user knows what is missing.
const names = products
.map((product) => ProductNames.get(product))
Expand Down
4 changes: 2 additions & 2 deletions src/kernels/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import type { IAnyMessageArgs } from '@jupyterlab/services/lib/kernel/kernel';
import { getKernelInfo } from './kernelInfo';
import { KernelInterruptTimeoutError } from './errors/kernelInterruptTimeoutError';
import { dispose } from '../platform/common/utils/lifecycle';
import { getCachedVersion, getEnvironmentType } from '../platform/interpreter/helpers';
import { getCachedVersion, getEnvironmentType, getPythonEnvDisplayName } from '../platform/interpreter/helpers';

const widgetVersionOutPrefix = 'e976ee50-99ed-4aba-9b6b-9dcd5634d07d:IPyWidgets:';
/**
Expand Down Expand Up @@ -585,7 +585,7 @@ abstract class BaseKernel implements IBaseKernel {
const info: string[] = [];
info.push(`Python Path: ${getDisplayPath(interpreter.uri)}`);
info.push(interpreter ? getEnvironmentType(interpreter) : '');
info.push(interpreter.envName || '');
info.push(getPythonEnvDisplayName(interpreter) || '');
const version = getCachedVersion(interpreter);
if (version) {
info.push(`${version.major}.${version.minor}.${version.micro}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ import { setPythonApi } from '../../../platform/interpreter/helpers';
id: Uri.file(isWindows ? 'C:/pyenv/envs/temp/scripts/python.exe' : '/users/username/pyenv/envs/temp/python')
.fsPath,
sysPrefix: isWindows ? 'C:/pyenv/envs/temp' : '/users/username/pyenv/envs/temp',
displayName: 'Temporary Python 3.9',
envName: 'temp'
displayName: 'Temporary Python 3.9'
};
const python38VenvEnv: PythonEnvironment & { sysPrefix: string } = {
uri: Uri.file(
Expand All @@ -344,14 +343,12 @@ import { setPythonApi } from '../../../platform/interpreter/helpers';
id: Uri.file(isWindows ? 'C:/temp/venv/.venv/scripts/python.exe' : '/users/username/temp/.venv/bin/python')
.fsPath,
sysPrefix: isWindows ? 'C:/temp/venv/.venv' : '/users/username/temp/.venv',
displayName: 'Virtual Env Python 3.8',
envName: '.venv'
displayName: 'Virtual Env Python 3.8'
};
const condaEnv1: PythonEnvironment & { sysPrefix: string } = {
uri: Uri.file(isWindows ? 'C:/conda/envs/env1/scripts/python.exe' : '/conda/envs/env1/bin/python'),
id: Uri.file(isWindows ? 'C:/conda/envs/env1/scripts/python.exe' : '/conda/envs/env1/bin/python').fsPath,
sysPrefix: isWindows ? 'C:/conda/envs/env1' : '/conda/envs/env1',
envName: 'env1',
displayName: 'Conda Env1 3.6'
};
const javaKernelSpec: KernelSpec.ISpecModel = {
Expand Down Expand Up @@ -411,7 +408,6 @@ import { setPythonApi } from '../../../platform/interpreter/helpers';
metadata: {
interpreter: {
displayName: python38VenvEnv.displayName,
envName: python38VenvEnv.envName,
path: python38VenvEnv.uri.fsPath,
envPath: undefined
}
Expand Down
Loading
Loading