Install kernelspec systemwide if not doing a --user install

main
Thomas Kluyver 10 years ago
parent b42e0c68bc
commit da394f3e80

@ -1,7 +1,8 @@
from distutils.core import setup from distutils.core import setup
from distutils.command.install import install from distutils.command.install import install
from distutils import log
import json import json
import os.path import os
import sys import sys
kernel_json = {"argv":[sys.executable,"-m","bash_kernel", "-f", "{connection_file}"], kernel_json = {"argv":[sys.executable,"-m","bash_kernel", "-f", "{connection_file}"],
@ -16,15 +17,17 @@ class install_with_kernelspec(install):
install.run(self) install.run(self)
# Now write the kernelspec # Now write the kernelspec
from IPython.kernel.kernelspec import KernelSpecManager from IPython.kernel.kernelspec import install_kernel_spec
from IPython.utils.path import ensure_dir_exists from IPython.utils.tempdir import TemporaryDirectory
destdir = os.path.join(KernelSpecManager().user_kernel_dir, 'bash') with TemporaryDirectory() as td:
ensure_dir_exists(destdir) os.chmod(td, 0o755) # Starts off as 700, not user readable
with open(os.path.join(destdir, 'kernel.json'), 'w') as f: with open(os.path.join(td, 'kernel.json'), 'w') as f:
json.dump(kernel_json, f, sort_keys=True) json.dump(kernel_json, f, sort_keys=True)
# TODO: Copy resources once they're specified # TODO: Copy resources once they're specified
log.info('Installing IPython kernel spec')
install_kernel_spec(td, 'bash', system=not self.user, replace=True)
with open('README.rst') as f: with open('README.rst') as f:
readme = f.read() readme = f.read()

Loading…
Cancel
Save