| 249 | } |
| 250 | |
| 251 | export function getDisplayNameOrNameOfKernelConnection(kernelConnection: KernelConnectionMetadata | undefined) { |
| 252 | const oldDisplayName = getOldFormatDisplayNameOrNameOfKernelConnection(kernelConnection); |
| 253 | if (!kernelConnection) { |
| 254 | return oldDisplayName; |
| 255 | } |
| 256 | switch (kernelConnection.kind) { |
| 257 | case 'connectToLiveRemoteKernel': { |
| 258 | const notebookPath = removeNotebookSuffixAddedByExtension( |
| 259 | kernelConnection.kernelModel?.notebook?.path || kernelConnection.kernelModel?.model?.path || '' |
| 260 | ); |
| 261 | return notebookPath ? `${oldDisplayName} (${notebookPath})` : oldDisplayName; |
| 262 | } |
| 263 | case 'startUsingRemoteKernelSpec': |
| 264 | case 'startUsingLocalKernelSpec': { |
| 265 | if ( |
| 266 | kernelConnection.interpreter && |
| 267 | getEnvironmentType(kernelConnection.interpreter) !== EnvironmentType.Unknown |
| 268 | ) { |
| 269 | const envName = getPythonEnvironmentName(kernelConnection.interpreter); |
| 270 | if (kernelConnection.kernelSpec.language === PYTHON_LANGUAGE) { |
| 271 | const pythonVersion = `Python ${ |
| 272 | getTelemetrySafeVersion(getCachedVersion(kernelConnection.interpreter)) || '' |
| 273 | }`.trim(); |
| 274 | return envName ? `${oldDisplayName} (${pythonVersion})` : oldDisplayName; |
| 275 | } else { |
| 276 | // Non-Python kernelspec that launches via python interpreter |
| 277 | return envName ? `${oldDisplayName} (${envName})` : oldDisplayName; |
| 278 | } |
| 279 | } else { |
| 280 | return oldDisplayName; |
| 281 | } |
| 282 | } |
| 283 | case 'startUsingPythonInterpreter': |
| 284 | const pythonVersion = ( |
| 285 | getTelemetrySafeVersion(getCachedVersion(kernelConnection.interpreter)) || '' |
| 286 | ).trim(); |
| 287 | if ( |
| 288 | kernelConnection.interpreter && |
| 289 | getEnvironmentType(kernelConnection.interpreter) !== EnvironmentType.Unknown |
| 290 | ) { |
| 291 | // If user has created a custom kernelspec, then use that. |
| 292 | if ( |
| 293 | kernelConnection.kernelSpec.display_name && |
| 294 | getKernelRegistrationInfo(kernelConnection.kernelSpec) === |
| 295 | 'registeredByNewVersionOfExtForCustomKernelSpec' |
| 296 | ) { |
| 297 | return kernelConnection.kernelSpec.display_name; |
| 298 | } |
| 299 | |
| 300 | return getDisplayNameOrNameOfPythonKernelConnection(kernelConnection.interpreter); |
| 301 | } else { |
| 302 | return `Python ${pythonVersion}`.trim(); |
| 303 | } |
| 304 | case 'startUsingDeepnoteKernel': { |
| 305 | // Display as "Project Title" |
| 306 | if (kernelConnection.projectName) { |
| 307 | return kernelConnection.projectName; |
| 308 | } |