jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.72k stars 4.96k forks source link

Different kernel name restrictions in different parts of the jupyter stack #853

Open jankatins opened 8 years ago

jankatins commented 8 years ago

All my kernels which have a '-' in the name (aka monte-carlo, julia-0.4 or conda-envname) don't get a logo served (i.e. there is no logo in the upper right corner).

It seems that the specific handler https://github.com/jupyter/notebook/blob/master/notebook/kernelspecs/handlers.py doesn't even see this request (added a few prints and the prints never showed up) so I suspect that there is somwhere a regex which swallows such URLs early?

jankatins commented 8 years ago

Other names which do not work (all tried via the environmental kernel manager): xxx~yyy, xxx|yyy

jankatins commented 8 years ago

Ok, seems that this is already a bit better: https://github.com/jupyter/notebook/commit/c93c6924f6e97b7bbb9ab04fdebe29c15531e6aa -> the new release will support . and -.

The interesting thing still stands: kernels with names like conda~envname can be started (visible in the new notebooks button) but they can't get their logo. E.g. you can rename a kernel in your user kernel dir to dev~34 and it can be started (http://localhost:8888/notebooks/Untitled8.ipynb?kernel_name=dev~34) and it works (kernel executes python code), but the logo is not visible.

IMO the regex for kernel specs should be reworked to accept all chars except / if that's what other parts of the notebook accept as a kernel name.

Also, the part which starts a kernel and lists all kernels should prevent kernels with unsuitable names and not list them (e.g. I can start kernels with / in the name, the only problem is the logo and a not visible parsing error in the UI due to some misnamed IDs, but python code executes).

Carreau commented 8 years ago

We are worry about unicode (and javascript), so we prefer a whitelist approach on name. You can propose ~ as a new accepted char. (Pr welcome). I would likely not allow it at the beginning of kernel name, and having it escape in html in the right places is likely needed.

takluyver commented 8 years ago

The IPEP for this originally specified the same rules as Python 2 identifiers - ascii letters, numbers and underscore, and can't start with a number. It doesn't look like that got translated into docs or code, though.

The current regex will match any Unicode word character on Python 3, as well as _-/.. I think we should make that more specific to ascii characters ([a-zA-Z0-9_\-\.]), to avoid any potential confusion relating to filesystem encoding. I don't particularly mind which bits of punctuation we support, but it should all be ascii, and I'd rather avoid anything that has significance in URLs, like ? or %.

jankatins commented 8 years ago

If the solution is to restrict the kernel names, then the regex needs to be applied at all places which register and start kernels. At least the kernel spec manager should not allow for kernels with different names registered and loaded and such errors should be displayed at the right place:

e.g. the following works:

jupyter qtconsole --kernel=dev~34
takluyver commented 8 years ago

Yep, we should definitely be consistent in what names are allowed. PRs welcome, and whoever gets to the PRs first gets first crack at choosing what punctuation is allowed (aka the initial proposal for the bikeshed colour ;-).

jchevreau commented 8 years ago

Hi,

I am starting to learn ipython using Jupyter and i having that logo issue which i cannot seem to resolve. Please see below:

[W 12:04:40.139 NotebookApp] 404 GET /kernelspecs/Python%20[python2]/logo-64x64.png (::1) 10.31ms referer=http://localhost:8888/notebooks/newEnvTest.ipynb

Additionally, why do my environment (even new ones) always have the prefix "Python [my env name]"?

Thanks

takluyver commented 8 years ago

@jchevreau : The environment name is because of an extension that Anaconda installs. You can revert to the normal implementation by uninstalling conda_nb_kernels. It shouldn't be a problem that it can't find the logo.

jchevreau commented 8 years ago

@takluyver Thank you very much for confirming. I will leave it like that for the moment until i am more comfortable with the tool. I am still looking for learning content before I throw myself in the deep end.

damianavila commented 8 years ago

@jchevreau for more info about the nb_conda_kernles extension and other extensions that Anaconda provides by default see here: https://docs.continuum.io/anaconda/jupyter-notebook-extensions

The environment name is because of an extension that Anaconda installs. You can revert to the normal implementation by uninstalling conda_nb_kernels

Just to make it clear, the default jupyter notebook experience does not come with this extensions, these extension is something that Anaconda ships by default. You can uninstall the extensions or create a new environment just with the notebook package to have the naive/normal experience.

Finally, as @takluyver mentioned, the logo issue should not be a problem, and we will fix it soon.