##// END OF EJS Templates
Put full kernel info in REST API response for all kernels
Thomas Kluyver -
Show More
@@ -19,8 +19,9 b' class MainKernelSpecHandler(IPythonHandler):'
19 ksm = self.kernel_spec_manager
19 ksm = self.kernel_spec_manager
20 results = []
20 results = []
21 for kernel_name in ksm.find_kernel_specs():
21 for kernel_name in ksm.find_kernel_specs():
22 results.append(dict(name=kernel_name,
22 d = ksm.get_kernel_spec(kernel_name).to_dict()
23 display_name=ksm.get_kernel_spec(kernel_name).display_name))
23 d['name'] = kernel_name
24 results.append(d)
24
25
25 self.set_header("Content-Type", 'application/json')
26 self.set_header("Content-Type", 'application/json')
26 self.finish(jsonapi.dumps(results))
27 self.finish(jsonapi.dumps(results))
@@ -68,11 +68,14 b' class APITest(NotebookTestBase):'
68 def test_list_kernelspecs(self):
68 def test_list_kernelspecs(self):
69 specs = self.ks_api.list().json()
69 specs = self.ks_api.list().json()
70 assert isinstance(specs, list)
70 assert isinstance(specs, list)
71
71
72 # 2: the sample kernelspec created in setUp, and the native Python kernel
72 # 2: the sample kernelspec created in setUp, and the native Python kernel
73 self.assertEqual(len(specs), 2)
73 self.assertEqual(len(specs), 2)
74 assert any(s == {'name': 'sample', 'display_name': 'Test kernel'}
74
75 for s in specs), specs
75 def is_sample_kernelspec(s):
76 return s['name'] == 'sample' and s['display_name'] == 'Test kernel'
77
78 assert any(is_sample_kernelspec(s) for s in specs), specs
76
79
77 def test_get_kernelspec(self):
80 def test_get_kernelspec(self):
78 spec = self.ks_api.kernel_spec_info('Sample').json() # Case insensitive
81 spec = self.ks_api.kernel_spec_info('Sample').json() # Case insensitive
@@ -47,14 +47,17 b' class KernelSpec(HasTraits):'
47 with io.open(kernel_file, 'r', encoding='utf-8') as f:
47 with io.open(kernel_file, 'r', encoding='utf-8') as f:
48 kernel_dict = json.load(f)
48 kernel_dict = json.load(f)
49 return cls(resource_dir=resource_dir, **kernel_dict)
49 return cls(resource_dir=resource_dir, **kernel_dict)
50
51 def to_dict(self):
52 return dict(argv=self.argv,
53 env=self.env,
54 display_name=self.display_name,
55 language=self.language,
56 codemirror_mode=self.codemirror_mode,
57 )
50
58
51 def to_json(self):
59 def to_json(self):
52 return json.dumps(dict(argv=self.argv,
60 return json.dumps(self.to_dict())
53 env=self.env,
54 display_name=self.display_name,
55 language=self.language,
56 codemirror_mode=self.codemirror_mode,
57 ))
58
61
59 def _is_kernel_dir(path):
62 def _is_kernel_dir(path):
60 """Is ``path`` a kernel directory?"""
63 """Is ``path`` a kernel directory?"""
General Comments 0
You need to be logged in to leave comments. Login now