Show More
@@ -7,8 +7,6 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 | ||
|
12 | 10 | |
|
13 | 11 | class MainKernelSpecHandler(IPythonHandler): |
|
14 | 12 | SUPPORTED_METHODS = ('GET',) |
@@ -17,18 +15,21 b' class MainKernelSpecHandler(IPythonHandler):' | |||
|
17 | 15 | @json_errors |
|
18 | 16 | def get(self): |
|
19 | 17 | ksm = self.kernel_spec_manager |
|
20 | results = [] | |
|
21 | for kernel_name in sorted(ksm.find_kernel_specs(), key=_pythonfirst): | |
|
18 | km = self.kernel_manager | |
|
19 | model = {} | |
|
20 | model['default'] = km.default_kernel_name | |
|
21 | model['kernelspecs'] = specs = {} | |
|
22 | for kernel_name in ksm.find_kernel_specs(): | |
|
22 | 23 | try: |
|
23 | 24 | d = ksm.get_kernel_spec(kernel_name).to_dict() |
|
24 | 25 | except Exception: |
|
25 | 26 | self.log.error("Failed to load kernel spec: '%s'", kernel_name, exc_info=True) |
|
26 | 27 | continue |
|
27 | 28 | d['name'] = kernel_name |
|
28 | results.append(d) | |
|
29 | specs[kernel_name] = d | |
|
29 | 30 | |
|
30 | 31 | self.set_header("Content-Type", 'application/json') |
|
31 |
self.finish(json.dumps( |
|
|
32 | self.finish(json.dumps(model)) | |
|
32 | 33 | |
|
33 | 34 | |
|
34 | 35 | class KernelSpecHandler(IPythonHandler): |
@@ -78,16 +78,22 b' class APITest(NotebookTestBase):' | |||
|
78 | 78 | with open(pjoin(bad_kernel_dir, 'kernel.json'), 'w') as f: |
|
79 | 79 | f.write("garbage") |
|
80 | 80 | |
|
81 |
|
|
|
82 |
assert isinstance( |
|
|
81 | model = self.ks_api.list().json() | |
|
82 | assert isinstance(model, dict) | |
|
83 | self.assertEqual(model['default'], NATIVE_KERNEL_NAME) | |
|
84 | specs = model['kernelspecs'] | |
|
85 | assert isinstance(specs, dict) | |
|
83 | 86 | # 2: the sample kernelspec created in setUp, and the native Python kernel |
|
84 | 87 | self.assertGreaterEqual(len(specs), 2) |
|
85 | 88 | |
|
86 | 89 | shutil.rmtree(bad_kernel_dir) |
|
87 | 90 | |
|
88 | 91 | def test_list_kernelspecs(self): |
|
89 |
|
|
|
90 |
assert isinstance( |
|
|
92 | model = self.ks_api.list().json() | |
|
93 | assert isinstance(model, dict) | |
|
94 | self.assertEqual(model['default'], NATIVE_KERNEL_NAME) | |
|
95 | specs = model['kernelspecs'] | |
|
96 | assert isinstance(specs, dict) | |
|
91 | 97 | |
|
92 | 98 | # 2: the sample kernelspec created in setUp, and the native Python kernel |
|
93 | 99 | self.assertGreaterEqual(len(specs), 2) |
@@ -98,8 +104,8 b' class APITest(NotebookTestBase):' | |||
|
98 | 104 | def is_default_kernelspec(s): |
|
99 | 105 | return s['name'] == NATIVE_KERNEL_NAME and s['display_name'].startswith("IPython") |
|
100 | 106 | |
|
101 | assert any(is_sample_kernelspec(s) for s in specs), specs | |
|
102 | assert any(is_default_kernelspec(s) for s in specs), specs | |
|
107 | assert any(is_sample_kernelspec(s) for s in specs.values()), specs | |
|
108 | assert any(is_default_kernelspec(s) for s in specs.values()), specs | |
|
103 | 109 | |
|
104 | 110 | def test_get_kernelspec(self): |
|
105 | 111 | spec = self.ks_api.kernel_spec_info('Sample').json() # Case insensitive |
@@ -25,16 +25,27 b' define([' | |||
|
25 | 25 | |
|
26 | 26 | KernelSelector.prototype.request_kernelspecs = function() { |
|
27 | 27 | var url = utils.url_join_encode(this.notebook.base_url, 'api/kernelspecs'); |
|
28 |
|
|
|
28 | utils.promising_ajax(url).then($.proxy(this._got_kernelspecs, this)); | |
|
29 | 29 | }; |
|
30 | 30 | |
|
31 |
KernelSelector.prototype._got_kernelspecs = function(data |
|
|
32 |
this.kernelspecs = |
|
|
31 | KernelSelector.prototype._got_kernelspecs = function(data) { | |
|
32 | this.kernelspecs = data.kernelspecs; | |
|
33 | 33 | var menu = this.element.find("#kernel_selector"); |
|
34 | 34 | var change_kernel_submenu = $("#menu-change-kernel-submenu"); |
|
35 | for (var i = 0; i < data.length; i++) { | |
|
36 | var ks = data[i]; | |
|
37 |
|
|
|
35 | var keys = Object.keys(data.kernelspecs).sort(function (a, b) { | |
|
36 | // sort by display_name | |
|
37 | var da = data.kernelspecs[a].display_name; | |
|
38 | var db = data.kernelspecs[b].display_name; | |
|
39 | if (da === db) { | |
|
40 | return 0; | |
|
41 | } else if (da > db) { | |
|
42 | return 1; | |
|
43 | } else { | |
|
44 | return -1; | |
|
45 | } | |
|
46 | }); | |
|
47 | for (var i = 0; i < keys.length; i++) { | |
|
48 | var ks = this.kernelspecs[keys[i]]; | |
|
38 | 49 | var ksentry = $("<li>").attr("id", "kernel-" +ks.name).append($('<a>') |
|
39 | 50 | .attr('href', '#') |
|
40 | 51 | .click($.proxy(this.change_kernel, this, ks.name)) |
@@ -38,11 +38,21 b' define([' | |||
|
38 | 38 | |
|
39 | 39 | NewNotebookWidget.prototype._load_kernelspecs = function (data) { |
|
40 | 40 | /** load kernelspec list */ |
|
41 |
this.kernelspecs = |
|
|
41 | this.kernelspecs = data.kernelspecs; | |
|
42 | 42 | var menu = this.element.find("#new-notebook-menu"); |
|
43 | for (var i = 0; i < data.length; i++) { | |
|
44 |
var |
|
|
45 |
|
|
|
43 | var keys = Object.keys(data.kernelspecs).sort(function (a, b) { | |
|
44 | var da = data.kernelspecs[a].display_name; | |
|
45 | var db = data.kernelspecs[b].display_name; | |
|
46 | if (da === db) { | |
|
47 | return 0; | |
|
48 | } else if (da > db) { | |
|
49 | return 1; | |
|
50 | } else { | |
|
51 | return -1; | |
|
52 | } | |
|
53 | }); | |
|
54 | for (var i = 0; i < keys.length; i++) { | |
|
55 | var ks = this.kernelspecs[keys[i]]; | |
|
46 | 56 | var li = $("<li>") |
|
47 | 57 | .attr("id", "kernel-" +ks.name) |
|
48 | 58 | .data('kernelspec', ks).append( |
@@ -59,12 +69,12 b' define([' | |||
|
59 | 69 | ); |
|
60 | 70 | menu.append(li); |
|
61 | 71 | } |
|
62 | this._load_default_kernelspec(); | |
|
72 | this._load_default_kernelspec(data['default']); | |
|
63 | 73 | }; |
|
64 | 74 | |
|
65 | NewNotebookWidget.prototype._load_default_kernelspec = function () { | |
|
75 | NewNotebookWidget.prototype._load_default_kernelspec = function (default_name) { | |
|
66 | 76 | /** load default kernelspec name from localStorage, if defined */ |
|
67 | this.select_kernel(localStorage.default_kernel_name); | |
|
77 | this.select_kernel(localStorage.default_kernel_name || default_name); | |
|
68 | 78 | }; |
|
69 | 79 | |
|
70 | 80 | NewNotebookWidget.prototype.select_kernel = function (kernel_name) { |
General Comments 0
You need to be logged in to leave comments.
Login now