jupyter
jupyter copied to clipboard
Skip headers from jupyter kernelspec list.
On certain configurations, juypter kernelspec list has a header with irrelevant information. This causes an error when parsing JSON output and can simply be ignored.
Example header:
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
Do you still get those messages even when applying the fix in #418?
I get this warning with Python 3.11. The fix in #418 (adding --log-level ERROR) does not help:
❯ jupyter kernelspec list --json --log-level ERROR
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
{
"kernelspecs": {
"python3": {
"resource_dir": "/home/lesteve/.local/share/jupyter/kernels/python3",
"spec": {
"argv": [
"python",
"-m",
"ipykernel_launcher",
"-f",
"{connection_file}"
],
"env": {},
"display_name": "Python 3 (ipykernel)",
"language": "python",
"interrupt_mode": "signal",
"metadata": {
"debugger": true
}
}
}
}
}
It seems to me that the best fix is to only consider stdout when executing jupyter commands as was proposed in #388 (which was closed in favour of #418), rather than adding more and more logic to discard unuseful info, which is what #418 did and and this PR proposes.
A compromise could be to add an additional argument to jupyter-command that would allow to ignore stderr. For a command like jupyter kernelspec list --json you know that you need to ignore stderr since otherwise it might not be valid json.