Skip to content

Commit

Permalink
Trac #25546: Install Jupyter kernel in the correct prefix
Browse files Browse the repository at this point in the history
The Sage Jupyter kernel is unconditionally installed in `sys.prefix`.
However, this should instead be the `install_data` directory. This
defaults to the installation prefix, which in turn defaults to
`sys.prefix`. So the default won't change, but it allows customization.

The reason for choosing `install_data` is to be compatible with other
Jupyter packages, which use the `data_files` option to `setup()` for
installing Jupyter files (see for example https://github.com/jupyter-
widgets/ipywidgets/blob/master/widgetsnbextension/setup.py#L203).
Those files are installed in the `install_data` directory.

URL: https://trac.sagemath.org/25546
Reported by: jdemeyer
Ticket author(s): Jeroen Demeyer
Reviewer(s): Vincent Klein
  • Loading branch information
Release Manager authored and vbraun committed Jun 19, 2018
2 parents 3a67990 + ad0ee29 commit 72167b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/sage/repl/ipython_kernel/install.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion src/setup.py
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 72167b9

Please sign in to comment.