-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix problems with a python kernel not handling json with numbers #12293
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Jupyter can fail to run a kernel if the user's environment contains non string values. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ import { | |
| IKernelDependencyService, | ||
| KernelInterpreterDependencyResponse | ||
| } from '../../types'; | ||
| import { detectDefaultKernelName } from './helpers'; | ||
| import { cleanEnvironment, detectDefaultKernelName } from './helpers'; | ||
| import { JupyterKernelSpec } from './jupyterKernelSpec'; | ||
| import { LiveKernelModel } from './types'; | ||
|
|
||
|
|
@@ -395,14 +395,15 @@ export class KernelService { | |
| forceWrite?: boolean | ||
| ) { | ||
| const specedKernel = kernel as JupyterKernelSpec; | ||
| if (specedKernel.specFile && interpreter) { | ||
| const specModel: ReadWrite<Kernel.ISpecModel> = JSON.parse( | ||
| if (specedKernel.specFile) { | ||
| let specModel: ReadWrite<Kernel.ISpecModel> = JSON.parse( | ||
| await this.fileSystem.readFile(specedKernel.specFile) | ||
| ); | ||
| let shouldUpdate = false; | ||
|
|
||
| // Make sure the specmodel has an interpreter or already in the metadata or we | ||
| // may overwrite a kernel created by the user | ||
| if (specModel.metadata?.interpreter || forceWrite) { | ||
| if (interpreter && (specModel.metadata?.interpreter || forceWrite)) { | ||
| // Ensure we use a fully qualified path to the python interpreter in `argv`. | ||
| if (specModel.argv[0].toLowerCase() === 'conda') { | ||
| // If conda is the first word, its possible its a conda activation command. | ||
|
|
@@ -438,7 +439,19 @@ export class KernelService { | |
| // tslint:disable-next-line: no-any | ||
| specModel.metadata.interpreter = interpreter as any; | ||
|
|
||
| // Update the kernel.json with our new stuff. | ||
| // Indicate we need to write | ||
| shouldUpdate = true; | ||
| } | ||
|
|
||
| // Scrub the environment of the specmodel to make sure it has allowed values (they all must be strings) | ||
| // See this issue here: https://github.com/microsoft/vscode-python/issues/11749 | ||
| if (specModel.env) { | ||
| specModel = cleanEnvironment(specModel); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just pass the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore the above comment, I know now why its required. |
||
| shouldUpdate = true; | ||
| } | ||
|
|
||
| // Update the kernel.json with our new stuff. | ||
| if (shouldUpdate) { | ||
| await this.fileSystem.writeFile(specedKernel.specFile, JSON.stringify(specModel, undefined, 2), { | ||
| flag: 'w', | ||
| encoding: 'utf8' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don' think this check is required.