Skip to content
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

Set default values for name and display_name in kernelspec #141

Closed
sp-fm opened this issue Nov 5, 2020 · 5 comments
Closed

Set default values for name and display_name in kernelspec #141

sp-fm opened this issue Nov 5, 2020 · 5 comments

Comments

@sp-fm
Copy link

sp-fm commented Nov 5, 2020

Jupyter Version

$ jupyter --version

jupyter core     : 4.6.3
jupyter-notebook : 6.1.4
qtconsole        : not installed
ipython          : 7.19.0
ipykernel        : 5.3.4
jupyter client   : 6.1.7
jupyter lab      : not installed
nbconvert        : 6.0.7
ipywidgets       : not installed
nbformat         : 5.0.8
traitlets        : 5.0.5

NOTE: The latest version of jupyter changed metadata.kernel_spec to metadata.kernelspec.

Problem

I stripped the kernelspec metadata using the following command:

git config --global filter.nbstripout.extrakeys '
  metadata.kernelspec.name
  metadata.kernelspec.display_name'

On doing so I encountered two problems:

  1. Git cannot render the notebook properly
  2. When I make changes to a code and then do git checkout to undo those changes it removes the kernelspec name and display_name metadata. This is as expected. But when I try to rerun the notebook it throws the following errors:
    a. Kernel not found
    b. Notebook validation failed: 'name' is a required property:
    c. Notebook validation failed: 'display_name' is a required property:

Change Request

Is it possible to set the name and display_name to a default value such as:

{
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 }
}
@vlin02
Copy link

vlin02 commented Jan 29, 2021

Had the same issue. A hacky fix for now is you can go into _util.py manually, insert:

nb.metadata['kernelspec']['name'] = 'python3'
nb.metadata['kernelspec']['display_name'] = 'Python 3'

inside strip_output()

@ESKYoung
Copy link

ESKYoung commented Mar 4, 2021

When I make changes to a code and then do git checkout to undo those changes it removes the kernelspec name and display_name metadata. This is as expected. But when I try to rerun the notebook it throws the following errors:
a. Kernel not found
b. Notebook validation failed: 'name' is a required property:
c. Notebook validation failed: 'display_name' is a required property:

Hope this helps, but I've found that deleting the entire kernelspec (i.e. the extra key is: metadata.kernelspec) doesn't throw the notebook errors, at least when set up as a pre-commit hook. Booting the notebook then defaults to Python 3 kernel.

@kynan
Copy link
Owner

kynan commented Apr 11, 2021

I can confirm the behavior @sp-fm is seeing and the suggestion from @ESKYoung works for me. Seems GitHub renders notebooks without kernelspec metadata fine too.

I've added a note to the README. Let me know if that's satisfactory for you.

@kynan kynan added type:documentation state:waiting Waiting for response for reporter labels Apr 11, 2021
@kynan kynan self-assigned this Apr 11, 2021
@kynan kynan added this to the 0.4.0 milestone Apr 11, 2021
@ESKYoung
Copy link

Looks good to me @kynan, thanks!

@kynan
Copy link
Owner

kynan commented Apr 12, 2021

Thanks. I'll close this. Please reopen if the proposed solution doesn't work for someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants