Show More
@@ -1,6 +1,7 b'' | |||
|
1 | 1 | import io |
|
2 | 2 | import json |
|
3 | 3 | import os |
|
4 | import sys | |
|
4 | 5 | |
|
5 | 6 | pjoin = os.path.join |
|
6 | 7 | |
@@ -50,16 +51,34 b' def _is_kernel_dir(path):' | |||
|
50 | 51 | def _list_kernels_in(dir): |
|
51 | 52 | if dir is None: |
|
52 | 53 | return {} |
|
54 | if not os.path.isdir(dir): | |
|
55 | os.makedirs(dir, mode=0o644) | |
|
53 | 56 | return {f.lower(): pjoin(dir, f) for f in os.listdir(dir) |
|
54 | 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 | 75 | def list_kernel_specs(): |
|
57 | 76 | """Returns a dict mapping kernels to resource directories.""" |
|
58 | 77 | d = _list_kernels_in(SYSTEM_KERNEL_DIR) |
|
59 | 78 | d.update(_list_kernels_in(USER_KERNEL_DIR)) |
|
60 | 79 | |
|
61 | 80 | if NATIVE_KERNEL_NAME not in d: |
|
62 |
d[NATIVE_KERNEL_NAME] = |
|
|
81 | d[NATIVE_KERNEL_NAME] = _make_native_kernel_dir() | |
|
63 | 82 | return d |
|
64 | 83 | |
|
65 | 84 | def get_kernel_spec(kernel_name): |
General Comments 0
You need to be logged in to leave comments.
Login now