##// END OF EJS Templates
Default to systemwide installation for kernelspecs
Thomas Kluyver -
Show More
@@ -143,16 +143,17 b' class KernelSpecManager(HasTraits):'
143 143 raise NoSuchKernel(kernel_name)
144 144 return KernelSpec.from_resource_dir(resource_dir)
145 145
146 def _get_destination_dir(self, kernel_name, system=False):
147 if system:
146 def _get_destination_dir(self, kernel_name, user=False):
147 if user:
148 return os.path.join(self.user_kernel_dir, kernel_name)
149 else:
148 150 if SYSTEM_KERNEL_DIRS:
149 151 return os.path.join(SYSTEM_KERNEL_DIRS[-1], kernel_name)
150 152 else:
151 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 157 replace=False):
157 158 """Install a kernel spec by copying its directory.
158 159
@@ -171,14 +172,14 b' class KernelSpecManager(HasTraits):'
171 172 kernel_name = os.path.basename(source_dir)
172 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 177 if replace and os.path.isdir(destination):
177 178 shutil.rmtree(destination)
178 179
179 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 183 """Install the native kernel spec to the filesystem
183 184
184 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 190 kernel registry. If the process does not have appropriate permissions,
190 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 194 os.makedirs(path, mode=0o755)
194 195 with open(pjoin(path, 'kernel.json'), 'w') as f:
195 196 json.dump(self._native_kernel_dict, f, indent=1)
@@ -209,13 +210,13 b' def get_kernel_spec(kernel_name):'
209 210 """
210 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 214 return KernelSpecManager().install_kernel_spec(source_dir, kernel_name,
214 system, replace)
215 user, replace)
215 216
216 217 install_kernel_spec.__doc__ = KernelSpecManager.install_kernel_spec.__doc__
217 218
218 def install_native_kernel_spec(self, system=False):
219 return KernelSpecManager().install_native_kernel_spec(system=system)
219 def install_native_kernel_spec(user=False):
220 return KernelSpecManager().install_native_kernel_spec(user=user)
220 221
221 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