From ad0ee291941aca37c7b7f743cc9f915fee9170b8 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Fri, 8 Jun 2018 19:46:11 +0200 Subject: [PATCH] Install Jupyter kernel in install_data directory --- src/sage/repl/ipython_kernel/install.py | 22 +++++++++++++++------- src/setup.py | 5 ++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/sage/repl/ipython_kernel/install.py b/src/sage/repl/ipython_kernel/install.py index 3912b8cdf52..5f9e99b9670 100644 --- a/src/sage/repl/ipython_kernel/install.py +++ b/src/sage/repl/ipython_kernel/install.py @@ -13,26 +13,34 @@ SAGE_DOC, SAGE_LOCAL, SAGE_EXTCODE, SAGE_VERSION ) -from jupyter_core.paths import ENV_JUPYTER_PATH -JUPYTER_PATH = ENV_JUPYTER_PATH[0] class SageKernelSpec(object): - def __init__(self): + def __init__(self, prefix=None): """ Utility to manage SageMath kernels and extensions + INPUT: + + - ``prefix`` -- (optional, default: ``sys.prefix``) + directory for the installation prefix + EXAMPLES:: sage: from sage.repl.ipython_kernel.install import SageKernelSpec sage: spec = SageKernelSpec() sage: spec._display_name # random output 'SageMath 6.9' + sage: spec.kernel_dir == SageKernelSpec(sys.prefix).kernel_dir + True """ self._display_name = 'SageMath {0}'.format(SAGE_VERSION) - self.nbextensions_dir = os.path.join(JUPYTER_PATH, "nbextensions") - self.kernel_dir = os.path.join(JUPYTER_PATH, "kernels", self.identifier()) + if prefix is None: + from sys import prefix + jupyter_dir = os.path.join(prefix, "share", "jupyter") + self.nbextensions_dir = os.path.join(jupyter_dir, "nbextensions") + self.kernel_dir = os.path.join(jupyter_dir, "kernels", self.identifier()) self._mkdirs() def _mkdirs(self): @@ -236,7 +244,7 @@ def _symlink_resources(self): ) @classmethod - def update(cls): + def update(cls, *args, **kwds): """ Configure the Jupyter notebook for the SageMath kernel @@ -250,7 +258,7 @@ def update(cls): sage: spec = SageKernelSpec() sage: spec.update() # not tested """ - instance = cls() + instance = cls(*args, **kwds) instance.use_local_mathjax() instance.use_local_jsmol() instance.use_local_threejs() diff --git a/src/setup.py b/src/setup.py index d2ee3610e67..68699d6db56 100755 --- a/src/setup.py +++ b/src/setup.py @@ -895,7 +895,10 @@ def install_kernel_spec(self): use ``data_files`` for this. """ from sage.repl.ipython_kernel.install import SageKernelSpec - SageKernelSpec.update() + # Jupyter packages typically use the data_files option to + # setup() to install kernels and nbextensions. So we should use + # the install_data directory for installing our Jupyter files. + SageKernelSpec.update(prefix=self.install_data) def clean_stale_files(self): """