Skip to content

Commit

Permalink
Remove environment type property (#15246)
Browse files Browse the repository at this point in the history
* Remove envType property from old Python Env Type

* Drop envType from tests

* remove type
  • Loading branch information
DonJayamanne authored Feb 27, 2024
1 parent 7912e3e commit 924cb5c
Show file tree
Hide file tree
Showing 40 changed files with 408 additions and 227 deletions.
1 change: 0 additions & 1 deletion src/api.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ declare module './api' {
displayName?: string;
uri: Uri;
version?: PythonVersion;
envType?: EnvironmentType;
envName?: string;
envPath?: Uri;
};
Expand Down
14 changes: 9 additions & 5 deletions src/kernels/errors/kernelErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { PackageNotInstalledWindowsLongPathNotEnabledError } from '../../platfor
import { JupyterNotebookNotInstalled } from '../../platform/errors/jupyterNotebookNotInstalled';
import { fileToCommandArgument } from '../../platform/common/helpers';
import {
getEnvironmentType,
getPythonEnvDisplayName,
getSysPrefix,
isCondaEnvironmentWithoutPython
Expand Down Expand Up @@ -424,14 +425,14 @@ export abstract class DataScienceErrorHandler implements IDataScienceErrorHandle
sendKernelTelemetryEvent(resource, Telemetry.KernelStartFailureDueToMissingEnv, undefined, {
envMissingReason: 'Unknown',
isEmptyCondaEnv: isCondaEnvironmentWithoutPython(details),
pythonEnvType: details.envType,
pythonEnvType: getEnvironmentType(details),
fileExists
});
} else {
sendKernelTelemetryEvent(resource, Telemetry.KernelStartFailureDueToMissingEnv, undefined, {
envMissingReason: 'EmptyEnvDetailsFromPython',
isEmptyCondaEnv: isCondaEnvironmentWithoutPython(kernelConnection.interpreter),
pythonEnvType: kernelConnection.interpreter.envType,
pythonEnvType: getEnvironmentType(kernelConnection.interpreter),
fileExists
});
}
Expand All @@ -441,7 +442,7 @@ export abstract class DataScienceErrorHandler implements IDataScienceErrorHandle
sendKernelTelemetryEvent(resource, Telemetry.KernelStartFailureDueToMissingEnv, undefined, {
envMissingReason: 'FailedToGetEnvDetailsFromPython',
isEmptyCondaEnv: isCondaEnvironmentWithoutPython(kernelConnection.interpreter),
pythonEnvType: kernelConnection.interpreter.envType,
pythonEnvType: getEnvironmentType(kernelConnection.interpreter),
fileExists
});
})
Expand Down Expand Up @@ -615,15 +616,18 @@ function getIPyKernelMissingErrorMessageForCell(kernelConnection: KernelConnecti
let installerCommand = `${fileToCommandArgument(
getFilePath(kernelConnection.interpreter.uri)
)} -m pip install ${ipyKernelModuleName} -U --force-reinstall`;
if (kernelConnection.interpreter?.envType === EnvironmentType.Conda) {
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) {
installerCommand = `conda install -p ${getFilePath(
kernelConnection.interpreter?.envPath
)} ${ipyKernelModuleName} --update-deps --force-reinstall`;
}
} else if (kernelConnection.interpreter?.envType === EnvironmentType.Unknown) {
} else if (
kernelConnection.interpreter &&
getEnvironmentType(kernelConnection.interpreter) === EnvironmentType.Unknown
) {
installerCommand = `${fileToCommandArgument(
getFilePath(kernelConnection.interpreter.uri)
)} -m pip install ${ipyKernelModuleName} -U --user --force-reinstall`;
Expand Down
29 changes: 28 additions & 1 deletion src/kernels/errors/kernelErrorHandler.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,25 @@ Failed to run jupyter as observable with args notebook --no-browser --notebook-d
when(dependencyManager.installMissingDependencies(anything())).thenResolve(
JupyterInterpreterDependencyResponse.cancel
);
when(environments.known).thenReturn([
{
id: kernelConnection.interpreter!.id,
version: {
major: 3,
minor: 12,
micro: 7,
release: undefined,
sysVersion: '3.12.7'
},
tools: [EnvironmentType.Conda]
} as any
]);

const result = await dataScienceErrorHandler.getErrorMessageForDisplayInCell(
new KernelDiedError('Kaboom', 'hello word does not have attribute named abc', undefined, {
...kernelConnection,
interpreter: {
...kernelConnection.interpreter!,
envType: EnvironmentType.Conda,
envName: 'condaEnv1'
}
}),
Expand All @@ -733,6 +746,20 @@ Failed to run jupyter as observable with args notebook --no-browser --notebook-d
when(dependencyManager.installMissingDependencies(anything())).thenResolve(
JupyterInterpreterDependencyResponse.cancel
);
when(environments.known).thenReturn([
{
id: kernelConnection.interpreter!.id,
version: {
major: 3,
minor: 12,
micro: 7,
release: undefined,
sysVersion: '3.12.7'
},
tools: [EnvironmentType.Venv]
} as any
]);

const result = await dataScienceErrorHandler.getErrorMessageForDisplayInCell(
new KernelDiedError(
'Kaboom',
Expand Down
8 changes: 3 additions & 5 deletions src/kernels/execution/helpers.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { assert } from 'chai';
import { Uri } from 'vscode';
import { cellOutputToVSCCellOutput, getNotebookCellOutputMetadata, updateNotebookMetadata } from './helpers';
import { IJupyterKernelSpec, PythonKernelConnectionMetadata } from '../types';
import { EnvironmentType, PythonEnvironment } from '../../platform/pythonEnvironments/info';
import { PythonEnvironment } from '../../platform/pythonEnvironments/info';
import { PythonExtension } from '@vscode/python-extension';
import { instance, mock, when } from 'ts-mockito';
import { resolvableInstance } from '../../test/datascience/helpers';
Expand All @@ -20,8 +20,7 @@ suite(`UpdateNotebookMetadata`, () => {
const python36Global: PythonEnvironment = {
uri: Uri.file('/usr/bin/python36'),
id: Uri.file('/usr/bin/python36').fsPath,
displayName: 'Python 3.6',
envType: EnvironmentType.Unknown
displayName: 'Python 3.6'
};
const pythonDefaultKernelSpec: IJupyterKernelSpec = {
argv: ['python', '-f', '{connection_file}'],
Expand All @@ -32,8 +31,7 @@ suite(`UpdateNotebookMetadata`, () => {
const python37Global: PythonEnvironment = {
uri: Uri.file('/usr/bin/python37'),
id: Uri.file('/usr/bin/python37').fsPath,
displayName: 'Python 3.7',
envType: EnvironmentType.Unknown
displayName: 'Python 3.7'
};
let environments: PythonExtension['environments'];
let disposables: { dispose: () => void }[] = [];
Expand Down
9 changes: 5 additions & 4 deletions src/kernels/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { IPlatformService } from '../platform/common/platform/types';
import { splitLines } from '../platform/common/helpers';
import {
getCachedVersion,
getEnvironmentType,
getPythonEnvironmentName,
isCondaEnvironmentWithoutPython
} from '../platform/interpreter/helpers';
Expand Down Expand Up @@ -259,8 +260,8 @@ export function getDisplayNameOrNameOfKernelConnection(kernelConnection: KernelC
case 'startUsingRemoteKernelSpec':
case 'startUsingLocalKernelSpec': {
if (
kernelConnection.interpreter?.envType &&
kernelConnection.interpreter.envType !== EnvironmentType.Unknown
kernelConnection.interpreter &&
getEnvironmentType(kernelConnection.interpreter) !== EnvironmentType.Unknown
) {
const envName = getPythonEnvironmentName(kernelConnection.interpreter);
if (kernelConnection.kernelSpec.language === PYTHON_LANGUAGE) {
Expand All @@ -283,8 +284,8 @@ export function getDisplayNameOrNameOfKernelConnection(kernelConnection: KernelC
getTelemetrySafeVersion(getCachedVersion(kernelConnection.interpreter)) || ''
).trim();
if (
kernelConnection.interpreter.envType &&
kernelConnection.interpreter.envType !== EnvironmentType.Unknown
kernelConnection.interpreter &&
getEnvironmentType(kernelConnection.interpreter) !== EnvironmentType.Unknown
) {
// If user has created a custom kernelspec, then use that.
if (
Expand Down
Loading

0 comments on commit 924cb5c

Please sign in to comment.