Show More
@@ -7,6 +7,8 b' from tornado import web' | |||
|
7 | 7 | |
|
8 | 8 | from ...base.handlers import IPythonHandler, json_errors |
|
9 | 9 | |
|
10 | from IPython.kernel.kernelspec import _pythonfirst | |
|
11 | ||
|
10 | 12 | |
|
11 | 13 | class MainKernelSpecHandler(IPythonHandler): |
|
12 | 14 | SUPPORTED_METHODS = ('GET',) |
@@ -16,7 +18,7 b' class MainKernelSpecHandler(IPythonHandler):' | |||
|
16 | 18 | def get(self): |
|
17 | 19 | ksm = self.kernel_spec_manager |
|
18 | 20 | results = [] |
|
19 | for kernel_name in ksm.find_kernel_specs(): | |
|
21 | for kernel_name in sorted(ksm.find_kernel_specs(), key=_pythonfirst): | |
|
20 | 22 | d = ksm.get_kernel_spec(kernel_name).to_dict() |
|
21 | 23 | d['name'] = kernel_name |
|
22 | 24 | results.append(d) |
@@ -23,6 +23,15 b' else:' | |||
|
23 | 23 | |
|
24 | 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 | 35 | class KernelSpec(HasTraits): |
|
27 | 36 | argv = List() |
|
28 | 37 | display_name = Unicode() |
@@ -11,14 +11,7 b' from IPython.core.application import (' | |||
|
11 | 11 | ) |
|
12 | 12 | from IPython.utils.traitlets import Instance, Dict, Unicode, Bool |
|
13 | 13 | |
|
14 | from .kernelspec import KernelSpecManager | |
|
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 | |
|
14 | from .kernelspec import KernelSpecManager, _pythonfirst | |
|
22 | 15 | |
|
23 | 16 | class ListKernelSpecs(BaseIPythonApplication): |
|
24 | 17 | description = """List installed kernel specifications.""" |
General Comments 0
You need to be logged in to leave comments.
Login now