##// END OF EJS Templates
Default to systemwide installation for kernelspecs
Thomas Kluyver -
Show More
@@ -143,16 +143,17 b' class KernelSpecManager(HasTraits):'
143 raise NoSuchKernel(kernel_name)
143 raise NoSuchKernel(kernel_name)
144 return KernelSpec.from_resource_dir(resource_dir)
144 return KernelSpec.from_resource_dir(resource_dir)
145
145
146 def _get_destination_dir(self, kernel_name, system=False):
146 def _get_destination_dir(self, kernel_name, user=False):
147 if system:
147 if user:
148 return os.path.join(self.user_kernel_dir, kernel_name)
149 else:
148 if SYSTEM_KERNEL_DIRS:
150 if SYSTEM_KERNEL_DIRS:
149 return os.path.join(SYSTEM_KERNEL_DIRS[-1], kernel_name)
151 return os.path.join(SYSTEM_KERNEL_DIRS[-1], kernel_name)
150 else:
152 else:
151 raise EnvironmentError("No system kernel directory is available")
153 raise EnvironmentError("No system kernel directory is available")
152 else:
153 return os.path.join(self.user_kernel_dir, kernel_name)
154
154
155 def install_kernel_spec(self, source_dir, kernel_name=None, system=False,
155
156 def install_kernel_spec(self, source_dir, kernel_name=None, user=False,
156 replace=False):
157 replace=False):
157 """Install a kernel spec by copying its directory.
158 """Install a kernel spec by copying its directory.
158
159
@@ -171,14 +172,14 b' class KernelSpecManager(HasTraits):'
171 kernel_name = os.path.basename(source_dir)
172 kernel_name = os.path.basename(source_dir)
172 kernel_name = kernel_name.lower()
173 kernel_name = kernel_name.lower()
173
174
174 destination = self._get_destination_dir(kernel_name, system=system)
175 destination = self._get_destination_dir(kernel_name, user=user)
175
176
176 if replace and os.path.isdir(destination):
177 if replace and os.path.isdir(destination):
177 shutil.rmtree(destination)
178 shutil.rmtree(destination)
178
179
179 shutil.copytree(source_dir, destination)
180 shutil.copytree(source_dir, destination)
180
181
181 def install_native_kernel_spec(self, system=False):
182 def install_native_kernel_spec(self, user=False):
182 """Install the native kernel spec to the filesystem
183 """Install the native kernel spec to the filesystem
183
184
184 This allows a Python 3 frontend to use a Python 2 kernel, or vice versa.
185 This allows a Python 3 frontend to use a Python 2 kernel, or vice versa.
@@ -189,7 +190,7 b' class KernelSpecManager(HasTraits):'
189 kernel registry. If the process does not have appropriate permissions,
190 kernel registry. If the process does not have appropriate permissions,
190 an :exc:`OSError` will be raised.
191 an :exc:`OSError` will be raised.
191 """
192 """
192 path = self._get_destination_dir(NATIVE_KERNEL_NAME, system=system)
193 path = self._get_destination_dir(NATIVE_KERNEL_NAME, user=user)
193 os.makedirs(path, mode=0o755)
194 os.makedirs(path, mode=0o755)
194 with open(pjoin(path, 'kernel.json'), 'w') as f:
195 with open(pjoin(path, 'kernel.json'), 'w') as f:
195 json.dump(self._native_kernel_dict, f, indent=1)
196 json.dump(self._native_kernel_dict, f, indent=1)
@@ -209,13 +210,13 b' def get_kernel_spec(kernel_name):'
209 """
210 """
210 return KernelSpecManager().get_kernel_spec(kernel_name)
211 return KernelSpecManager().get_kernel_spec(kernel_name)
211
212
212 def install_kernel_spec(source_dir, kernel_name=None, system=False, replace=False):
213 def install_kernel_spec(source_dir, kernel_name=None, user=False, replace=False):
213 return KernelSpecManager().install_kernel_spec(source_dir, kernel_name,
214 return KernelSpecManager().install_kernel_spec(source_dir, kernel_name,
214 system, replace)
215 user, replace)
215
216
216 install_kernel_spec.__doc__ = KernelSpecManager.install_kernel_spec.__doc__
217 install_kernel_spec.__doc__ = KernelSpecManager.install_kernel_spec.__doc__
217
218
218 def install_native_kernel_spec(self, system=False):
219 def install_native_kernel_spec(user=False):
219 return KernelSpecManager().install_native_kernel_spec(system=system)
220 return KernelSpecManager().install_native_kernel_spec(user=user)
220
221
221 install_native_kernel_spec.__doc__ = KernelSpecManager.install_native_kernel_spec.__doc__
222 install_native_kernel_spec.__doc__ = KernelSpecManager.install_native_kernel_spec.__doc__
General Comments 0
You need to be logged in to leave comments. Login now