##// END OF EJS Templates
Add supporting for making a directory for the native kernel
Thomas Kluyver -
Show More
@@ -1,6 +1,7 b''
1 import io
1 import io
2 import json
2 import json
3 import os
3 import os
4 import sys
4
5
5 pjoin = os.path.join
6 pjoin = os.path.join
6
7
@@ -50,16 +51,34 b' def _is_kernel_dir(path):'
50 def _list_kernels_in(dir):
51 def _list_kernels_in(dir):
51 if dir is None:
52 if dir is None:
52 return {}
53 return {}
54 if not os.path.isdir(dir):
55 os.makedirs(dir, mode=0o644)
53 return {f.lower(): pjoin(dir, f) for f in os.listdir(dir)
56 return {f.lower(): pjoin(dir, f) for f in os.listdir(dir)
54 if _is_kernel_dir(pjoin(dir, f))}
57 if _is_kernel_dir(pjoin(dir, f))}
55
58
59 def _make_native_kernel_dir():
60 path = pjoin(USER_KERNEL_DIR, NATIVE_KERNEL_NAME)
61 os.mkdir(path)
62 with io.open(pjoin(path, 'kernel.json'), 'w', encoding='utf-8') as f:
63 json.dump({'argv':[NATIVE_KERNEL_NAME, '-c',
64 'from IPython.kernel.zmq.kernelapp import main; main()',
65 '-f', '{connection_file}'],
66 'display_name': 'Python 3' if PY3 else 'Python 2',
67 'language': 'python',
68 'codemirror_mode': {'name': 'python',
69 'version': sys.version_info[0]},
70 },
71 f)
72 # TODO: Copy icons into directory
73 return path
74
56 def list_kernel_specs():
75 def list_kernel_specs():
57 """Returns a dict mapping kernels to resource directories."""
76 """Returns a dict mapping kernels to resource directories."""
58 d = _list_kernels_in(SYSTEM_KERNEL_DIR)
77 d = _list_kernels_in(SYSTEM_KERNEL_DIR)
59 d.update(_list_kernels_in(USER_KERNEL_DIR))
78 d.update(_list_kernels_in(USER_KERNEL_DIR))
60
79
61 if NATIVE_KERNEL_NAME not in d:
80 if NATIVE_KERNEL_NAME not in d:
62 d[NATIVE_KERNEL_NAME] = '' # TODO: native kernel resource directory
81 d[NATIVE_KERNEL_NAME] = _make_native_kernel_dir()
63 return d
82 return d
64
83
65 def get_kernel_spec(kernel_name):
84 def get_kernel_spec(kernel_name):
General Comments 0
You need to be logged in to leave comments. Login now