Debian Codegraph @

interactive-notebook/stap-jupyter-install.in

raw
1 #!/bin/bash
2 # An install script for isystemtap and its jupyterlab extensions
3 # Copyright (C) 2023 Red Hat Inc.
4 #
5 # This file is part of systemtap, and is free software. You can
6 # redistribute it and/or modify it under the terms of the GNU General
7 # Public License (GPL); either version 2, or (at your option) any
8 # later version.
9
10 set -e
11
12 type python >/dev/null || { echo "python required"; exit 1; }
13 type pip >/dev/null || { echo "pip required"; exit 1; }
14
15 PREFIX=@prefix@
16 # The dir for our local install files
17 jupyter_dir="$HOME/.systemtap/jupyter"
18 # The syntax highlighting jupyterlab extension
19 extenstion="jupyterlab-stap-highlight"
20 # The dir where jupyter stores it's language-server configury
21 jconfig=`jupyter --config`
22 lsp_config=jupyter_stap_lsp.json
23
24 if [ "$1" = '--container-install' ]; then
25 PREFIX=$2
26 if [ ! -e $PREFIX/share/systemtap/interactive-notebook/isystemtap/constants.py ]; then
27 echo "Usage: --container-install $PREFIX is not a valid prefix directory. It must be a parent of interactive-notebook/" 1>&2; exit 1;
28 fi
29 elif [ "$1" = '--remove' ]; then
30 jupyter kernelspec remove isystemtap
31 rm -rf $jupyter_dir
32 jupyter labextension uninstall $extenstion
33 rm "$jconfig/jupyter_server_config.d/$lsp_config"
34 exit 0
35 elif [ -n "$1" ]; then
36 echo "Usage: stap-jupyter-install [--remove | <For Maintainers> --container-install PREFIX]" 1>&2; exit 1;
37 fi
38
39 NOTEBOOK_DIR=$PREFIX/share/systemtap/interactive-notebook
40 START_DIR=`pwd`
41 cd $NOTEBOOK_DIR
42
43 echo "Installing requirements"
44 if command -v mamba &> /dev/null
45 then
46 # The jupyter container images use mamba, so we follow suit
47 mamba install -yc kirill-odc --file requirements.txt
48 mamba clean --all -f -y
49 else
50 # Otherwise just default to pip
51 pip install -U --user --no-cache-dir -r requirements.txt
52 fi
53
54 echo
55 echo "Installing Jupyter kernelspec"
56 jupyter kernelspec install --user isystemtap
57
58 mkdir -p $jupyter_dir
59 echo
60 echo "Installing ISystemtap"
61 # Installs the setup.py from ~/.systemtap/jupyter
62 cp -R isystemtap $jupyter_dir && cp setup.py $jupyter_dir && (cd $jupyter_dir && pip install .)
63
64 echo
65 echo "Checking $extenstion extenstion installation"
66 if jupyter labextension check $extenstion --installed 2> /dev/null; then
67 echo "$extenstion already installed"
68 elif ! type npm >/dev/null; then
69 echo "npm is not installed, skipping $extenstion build"
70 else
71 cp -R codemirror $jupyter_dir && (cd $jupyter_dir/codemirror && npm install && jupyter labextension link --dev-build=False .)
72 echo "$extenstion installed"
73 fi
74
75 echo
76 echo "Setting up language server"
77 mkdir -p "$jconfig/jupyter_server_config.d/"
78 if [ "$1" = '--container-install' ]; then
79 # NB: We add the UNCHANGED config file. At runtime this needs to be updated with the host users stap install dir
80 # see runtime_container_config.sh
81 cp $lsp_config "$jconfig/jupyter_server_config.d/$lsp_config"
82 elif stap --help | grep language-server > /dev/null; then
83 cp -v $lsp_config "$jconfig/jupyter_server_config.d/$lsp_config"
84 else
85 echo "This version of systemtap does not support language-server mode. Skipping"
86 fi
87 cd $START_DIR