(
kernelSpec: IJupyterKernelSpec
)
| 545 | * E.g. a custom kernelspec found in a Python environment (either created by user or as a result of installing some custom kernelspec). |
| 546 | */ |
| 547 | export function getKernelRegistrationInfo( |
| 548 | kernelSpec: IJupyterKernelSpec |
| 549 | ): |
| 550 | | 'registeredByOldVersionOfExt' |
| 551 | | 'registeredByNewVersionOfExt' |
| 552 | | 'registeredByNewVersionOfExtForCustomKernelSpec' |
| 553 | | undefined { |
| 554 | if (kernelSpec.isRegisteredByVSC) { |
| 555 | return kernelSpec.isRegisteredByVSC; |
| 556 | } |
| 557 | if (!kernelSpec.name) { |
| 558 | return; |
| 559 | } |
| 560 | |
| 561 | // The name of the original kernel can be derived from the original spec file path (directory containing the specfile). |
| 562 | const originalSpecFile = kernelSpec.metadata?.vscode?.originalSpecFile || kernelSpec.metadata?.originalSpecFile; |
| 563 | const originalName = originalSpecFile ? path.basename(path.dirname(originalSpecFile)) : kernelSpec.name; |
| 564 | const isUserCreatedOrUserCustomizedKernelSpec = isDefaultKernelSpec({ ...kernelSpec, name: originalName }) |
| 565 | ? // If this is a default kernelspec, and we have env variables, then assume user modified it (effectively a user defined kernelspec). |
| 566 | Object.keys(kernelSpec.env || {}).length > 0 |
| 567 | : // Original kernel spec file paths cannot contain the auto generated identifier. |
| 568 | typeof originalSpecFile === 'string' && !originalSpecFile.includes(autoGeneratedKernelNameIdentifier); |
| 569 | |
| 570 | // Check if this is a kernel we registered in the old days. |
| 571 | // If it is, then no need to display that (selecting kernels registered is done by selecting the corresponding interpreter). |
| 572 | // Hence we can hide such kernels. |
| 573 | // Kernels we create will end with a uuid (with - stripped), & will have interpreter info in the metadata. |
| 574 | // Only do this for raw kernel scenarios |
| 575 | if (kernelSpec.name.includes(autoGeneratedKernelNameIdentifier)) { |
| 576 | return isUserCreatedOrUserCustomizedKernelSpec |
| 577 | ? // This is a kernelspec we created to be able to load custom kernelspecs using Jupyter. |
| 578 | // E.g. user creates a custom kernelspec in a Python env, Jupyter will not be able to load that. |
| 579 | // We need to create a corresponding kernelspec in global location (which would be a copy of the users custom kernelspec). |
| 580 | 'registeredByNewVersionOfExtForCustomKernelSpec' |
| 581 | : // This is a kernelspec we created to be able to load Python environments using Jupyter. |
| 582 | 'registeredByNewVersionOfExt'; |
| 583 | } |
| 584 | const guidRegEx = /[a-f0-9]{32}$/; |
| 585 | if (kernelSpec.metadata?.interpreter && kernelSpec.name.toLowerCase().search(guidRegEx) !== -1) { |
| 586 | return 'registeredByOldVersionOfExt'; |
| 587 | } |
| 588 | return; |
| 589 | } |
| 590 | |
| 591 | export function areKernelConnectionsEqual( |
| 592 | connection1?: KernelConnectionMetadata, |
no test coverage detected