()
| 971 | } |
| 972 | |
| 973 | protected async gatherInternalStartupCode(): Promise<string[]> { |
| 974 | // Gather all of the startup code into a giant string array so we |
| 975 | // can execute it all at once. |
| 976 | const result: string[] = []; |
| 977 | const startupCode = await Promise.all( |
| 978 | this.startupCodeProviders.sort((a, b) => b.priority - a.priority).map((provider) => provider.getCode(this)) |
| 979 | ); |
| 980 | for (let code of startupCode) { |
| 981 | result.push(...code); |
| 982 | } |
| 983 | |
| 984 | // If this is a live kernel, we shouldn't be changing anything by running startup code. |
| 985 | if ( |
| 986 | isPythonKernelConnection(this.kernelConnectionMetadata) && |
| 987 | this.kernelConnectionMetadata.kind !== 'connectToLiveRemoteKernel' |
| 988 | ) { |
| 989 | // Set the ipynb file |
| 990 | const file = getFilePath(this.resourceUri); |
| 991 | if (file) { |
| 992 | result.push(`__vsc_ipynb_file__ = "${file.replace(/\\/g, '\\\\')}"`); |
| 993 | } |
| 994 | if (!this.kernelSettings.enableExtendedPythonKernelCompletions) { |
| 995 | result.push(CodeSnippets.DisableJedi); |
| 996 | } |
| 997 | |
| 998 | // For Python notebook initialize matplotlib |
| 999 | // Wrap this startup code in try except as it might fail |
| 1000 | result.push( |
| 1001 | ...wrapPythonStartupBlock( |
| 1002 | this.getMatplotLibInitializeCode(), |
| 1003 | 'Failed to initialize matplotlib startup code. Matplotlib might be missing.' |
| 1004 | ) |
| 1005 | ); |
| 1006 | |
| 1007 | // If this is a Jupyter Server kernel (not raw, then we need to ensure the cwd is set correctly) |
| 1008 | if ( |
| 1009 | isLocalConnection(this.kernelConnectionMetadata) && |
| 1010 | this.rawKernelSupported?.isSupported === false && |
| 1011 | this.kernelWorkingDirectory |
| 1012 | ) { |
| 1013 | const workingDirectory = await this.kernelWorkingDirectory.computeWorkingDirectory( |
| 1014 | this.kernelConnectionMetadata, |
| 1015 | this.resourceUri, |
| 1016 | this.startCancellation.token |
| 1017 | ); |
| 1018 | |
| 1019 | // eslint-disable-next-line local-rules/dont-use-fspath |
| 1020 | const safeWorkingDirectory = toPythonSafePath(workingDirectory.fsPath); |
| 1021 | const code = ` |
| 1022 | import os as _VSCODE_os |
| 1023 | try: |
| 1024 | _VSCODE_os.chdir(${safeWorkingDirectory}) |
| 1025 | except: |
| 1026 | pass |
| 1027 | |
| 1028 | del _VSCODE_os |
| 1029 | `; |
| 1030 | result.push(code); |
nothing calls this directly
no test coverage detected