##// END OF EJS Templates
Deterministic order for kernels in notebook UI
Thomas Kluyver -
Show More
@@ -7,6 +7,8 b' from tornado import web'
7
7
8 from ...base.handlers import IPythonHandler, json_errors
8 from ...base.handlers import IPythonHandler, json_errors
9
9
10 from IPython.kernel.kernelspec import _pythonfirst
11
10
12
11 class MainKernelSpecHandler(IPythonHandler):
13 class MainKernelSpecHandler(IPythonHandler):
12 SUPPORTED_METHODS = ('GET',)
14 SUPPORTED_METHODS = ('GET',)
@@ -16,7 +18,7 b' class MainKernelSpecHandler(IPythonHandler):'
16 def get(self):
18 def get(self):
17 ksm = self.kernel_spec_manager
19 ksm = self.kernel_spec_manager
18 results = []
20 results = []
19 for kernel_name in ksm.find_kernel_specs():
21 for kernel_name in sorted(ksm.find_kernel_specs(), key=_pythonfirst):
20 d = ksm.get_kernel_spec(kernel_name).to_dict()
22 d = ksm.get_kernel_spec(kernel_name).to_dict()
21 d['name'] = kernel_name
23 d['name'] = kernel_name
22 results.append(d)
24 results.append(d)
@@ -23,6 +23,15 b' else:'
23
23
24 NATIVE_KERNEL_NAME = 'python3' if PY3 else 'python2'
24 NATIVE_KERNEL_NAME = 'python3' if PY3 else 'python2'
25
25
26 def _pythonfirst(s):
27 "Sort key function that will put strings starting with 'python' first."
28 if s == NATIVE_KERNEL_NAME:
29 return ' ' + s # Two spaces to sort this first of all
30 elif s.startswith('python'):
31 # Space is not valid in kernel names, so this should sort first
32 return ' ' + s
33 return s
34
26 class KernelSpec(HasTraits):
35 class KernelSpec(HasTraits):
27 argv = List()
36 argv = List()
28 display_name = Unicode()
37 display_name = Unicode()
@@ -11,14 +11,7 b' from IPython.core.application import ('
11 )
11 )
12 from IPython.utils.traitlets import Instance, Dict, Unicode, Bool
12 from IPython.utils.traitlets import Instance, Dict, Unicode, Bool
13
13
14 from .kernelspec import KernelSpecManager
14 from .kernelspec import KernelSpecManager, _pythonfirst
15
16 def _pythonfirst(s):
17 "Sort key function that will put strings starting with 'python' first."
18 if s.startswith('python'):
19 # Space is not valid in kernel names, so this should sort first
20 return ' ' + s
21 return s
22
15
23 class ListKernelSpecs(BaseIPythonApplication):
16 class ListKernelSpecs(BaseIPythonApplication):
24 description = """List installed kernel specifications."""
17 description = """List installed kernel specifications."""
General Comments 0
You need to be logged in to leave comments. Login now