diff options
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | scilab_kernel.py | 2 | ||||
-rw-r--r-- | setup.py | 26 |
3 files changed, 22 insertions, 8 deletions
@@ -1,6 +1,6 @@ A simple IPython kernel for Scilab -This requires IPython 3, which is not yet released, and `scilab2py <http://pypi.python.org/pypi/scilab2py>`_. +This requires IPython 3+ and `scilab2py <http://pypi.python.org/pypi/scilab2py>`_. To test it, install with ``setup.py``, then:: diff --git a/scilab_kernel.py b/scilab_kernel.py index 4b26423..48286dc 100644 --- a/scilab_kernel.py +++ b/scilab_kernel.py @@ -15,7 +15,7 @@ import base64 from shutil import rmtree from xml.dom import minidom -__version__ = '0.4' +__version__ = '0.5' version_pat = re.compile(r'version "(\d+(\.\d+)+)') @@ -3,6 +3,7 @@ from setuptools.command.install import install import json import os import sys +from distutils import log kernel_json = {"argv": [sys.executable, "-m", "scilab_kernel", "-f", @@ -14,17 +15,30 @@ kernel_json = {"argv": [sys.executable, "-m", "scilab_kernel", "-f", class install_with_kernelspec(install): + def run(self): + user = '--user' in sys.argv # Regular installation install.run(self) # Now write the kernelspec - from IPython.kernel.kernelspec import KernelSpecManager - from IPython.utils.path import ensure_dir_exists - destdir = os.path.join(KernelSpecManager().user_kernel_dir, 'scilab') - ensure_dir_exists(destdir) - with open(os.path.join(destdir, 'kernel.json'), 'w') as f: - json.dump(kernel_json, f, sort_keys=True) + try: + from ipykernel.kerspec import install_kernel_spec + except ImportError: + from IPython.kernel.kernelspec import install_kernel_spec + from IPython.utils.tempdir import TemporaryDirectory + with TemporaryDirectory() as td: + os.chmod(td, 0o755) # Starts off as 700, not user readable + with open(os.path.join(td, 'kernel.json'), 'w') as f: + json.dump(kernel_json, f, sort_keys=True) + log.info('Installing kernel spec') + kernel_name = kernel_json['name'] + try: + install_kernel_spec(td, kernel_name, user=user, + replace=True) + except: + install_kernel_spec(td, kernel_name, user=not user, + replace=True) with open('README.rst') as f: |