Unverified Commit ae6b1fda authored by Vaibhav Sagar's avatar Vaibhav Sagar Committed by GitHub

Install a prebuilt version of `jupyterlab-ihaskell` automatically (#1270)

* ihaskell: automatically install the prebuilt labextension alongside the kernelspec

* README.md: Update to no longer mention installing jupyterlab-ihaskell
parent 98fbdf7e
......@@ -42,13 +42,6 @@ stack install --fast
ihaskell install --stack
```
If you want to use jupyterlab, you need to install the jupyterlab ihaskell
extension to get syntax highlighting with:
```bash
jupyter labextension install jupyterlab-ihaskell
```
Run Jupyter.
```bash
......@@ -203,13 +196,10 @@ Direct IHaskell to register itself as a Jupyter kernel.
stack --docker exec ihaskell -- install --stack
```
Optionally, install JupyterLab and the IHaskell JupyterLab extension for
syntax highlighting. See the
[`jupyterlab-ihaskell/README.md`](jupyterlab-ihaskell/README.md).
Optionally, install JupyterLab.
```bash
stack --docker exec pip3 -- install jupyterlab
stack --docker exec bash -- -c 'cd jupyterlab-ihaskell;npm install;npm run build;jupyter labextension link .'
```
Run the Jupyter notebook, with security disabled for testing, listening on all interfaces.
......
......@@ -45,6 +45,9 @@ cabal-version: 1.16
data-files:
html/kernel.js
html/logo-64x64.svg
jupyterlab-ihaskell/labextension/package.json
jupyterlab-ihaskell/labextension/static/*.js
jupyterlab-ihaskell/labextension/static/*.json
library
hs-source-dirs: src
......
......@@ -56,6 +56,7 @@ ihaskell (Args ConvertLhs args) = showingHelp ConvertLhs args $ convert args
ihaskell (Args InstallKernelSpec args) = showingHelp InstallKernelSpec args $ do
let kernelSpecOpts = parseKernelArgs args
replaceIPythonKernelspec kernelSpecOpts
installLabextension
ihaskell (Args (Kernel (Just filename)) args) = do
let kernelSpecOpts = parseKernelArgs args
runKernel kernelSpecOpts filename
......
......@@ -19,7 +19,7 @@ let
ihaskellSourceFilter = src: name: type: let
relPath = lib.removePrefix (toString src + "/") (toString name);
in cleanSource name type && ( any (lib.flip lib.hasPrefix relPath) [
"src" "main" "html" "Setup.hs" "ihaskell.cabal" "LICENSE"
"src" "main" "html" "jupyterlab-ihaskell" "Setup.hs" "ihaskell.cabal" "LICENSE"
]);
ihaskell-src = filterSource (ihaskellSourceFilter ./.) ./.;
ipython-kernel-src = filterSource cleanSource ./ipython-kernel;
......
......@@ -11,6 +11,7 @@ module IHaskell.IPython (
kernelName,
KernelSpecOptions(..),
defaultKernelSpecOptions,
installLabextension,
) where
import IHaskellPrelude
......@@ -172,6 +173,30 @@ installKernelspec repl opts = void $ do
SH.silently $ SH.run ipython cmd
installLabextension :: IO ()
installLabextension = SH.shelly $ do
-- Find the prebuilt extension directory
ihaskellDataDir <- liftIO $ Paths.getDataDir
let labextensionDataDir = ihaskellDataDir
SH.</> ("jupyterlab-ihaskell" :: SH.FilePath)
SH.</> ("labextension" :: SH.FilePath)
-- Find the $(jupyter --data-dir)/labextensions/jupyterlab-ihaskell directory
jupyter <- locateIPython
jupyterDataDir <- SH.silently $ SH.fromText . T.strip <$> SH.run jupyter ["--data-dir"]
let jupyterlabIHaskellDir = jupyterDataDir
SH.</> ("labextensions" :: SH.FilePath)
SH.</> ("jupyterlab-ihaskell" :: SH.FilePath)
-- Remove the extension directory with extreme prejudice if it already exists
SH.rm_rf jupyterlabIHaskellDir
-- Create an empty 'jupyterlab-ihaskell' directory to install our extension in
SH.mkdir_p jupyterlabIHaskellDir
-- Copy the prebuilt extension files over
extensionContents <- SH.ls labextensionDataDir
forM_ extensionContents $ \entry ->
SH.cp_r entry jupyterlabIHaskellDir
-- | Replace "~" with $HOME if $HOME is defined. Otherwise, do nothing.
subHome :: String -> IO String
subHome path = SH.shelly $ do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment