Skip to content
Snippets Groups Projects
Select Git revision
  • 994e9169a37261b0ac6b58cae20a1a1b99d4886d
  • master default protected
  • tut_ring_allen
  • docs_furo
  • docs_reorder_cable_cell
  • docs_graphviz
  • docs_rtd_dev
  • ebrains_mirror
  • doc_recat
  • docs_spike_source
  • docs_sim_sample_clar
  • docs_pip_warn
  • github_template_updates
  • docs_fix_link
  • cv_default_and_doc_clarification
  • docs_add_numpy_req
  • readme_zenodo_05
  • install_python_fix
  • install_require_numpy
  • typofix_propetries
  • docs_recipe_lookup
  • v0.10.0
  • v0.10.1
  • v0.10.0-rc5
  • v0.10.0-rc4
  • v0.10.0-rc3
  • v0.10.0-rc2
  • v0.10.0-rc
  • v0.9.0
  • v0.9.0-rc
  • v0.8.1
  • v0.8
  • v0.8-rc
  • v0.7
  • v0.6
  • v0.5.2
  • v0.5.1
  • v0.5
  • v0.4
  • v0.3
  • v0.2.2
41 results

event_queue.hpp

Blame
  • create_JupyterLab_kernel.sh 2.68 KiB
    #!/bin/bash
    #title           :create_JupyterLab_kernel.sh
    #description     :Script to create a spackified JupyterLab kernel conf and place it to NFS where it can be loaded by all users.   
    #usage           :./create_JupyterLab_kernel.sh $INSTALLATION_ROOT $ENV $RELEASE_NAME $LAB_KERNEL_PATH
    #==============================================================================
    
    INSTALLATION_ROOT=$1
    SPACKIFIED_ENV=$2
    RELEASE_NAME=$3
    LAB_KERNEL_PATH=$4
    
    # capture the empty env
    cd ~
    env >> /tmp/before.txt
    
    # load spack, spack repos and spack env
    export SPACK_USER_CACHE_PATH=/srv/$INSTALLATION_ROOT/spack/.spack
    export SPACK_USER_CONFIG_PATH=/srv/$INSTALLATION_ROOT/spack/.spack
    source /srv/$INSTALLATION_ROOT/spack/share/spack/setup-env.sh
    # this shouldn't be needed:
    spack repo add /srv/$INSTALLATION_ROOT/ebrains-spack-builds
    # no need to activate as the env is already activated in the context it is used
    #spack env activate $SPACKIFIED_ENV
    
    source /usr/share/modules/init/sh
    module use /srv/$INSTALLATION_ROOT/spack/share/spack/modules/linux-ubuntu20.04-x86_64/
    source /srv/$INSTALLATION_ROOT/spack/var/spack/environments/$SPACKIFIED_ENV/loads
    # add also user's .local python3.8 packages to allow package installation at runtime by the user using pip
    export PYTHONPATH=$PYTHONPATH:/opt/app-root/src/.local/lib/python3.8/site-packages
    export PATH=$PATH:/opt/app-root/src/.local/bin
    # export also python modules installed in the base docker Collab image
    export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.8/dist-packages
    
    # capture the env after spack activation
    cd ~
    env >> /tmp/after.txt
    
    # kernel name is lowercase release name
    LAB_KERNEL_NAME=$(echo "$RELEASE_NAME" | tr '[:upper:]' '[:lower:]')
    # kernel dir is a directory inside LAB_KERNEL_PATH named after the kernel
    LAB_KERNEL_DIR=$LAB_KERNEL_PATH/$LAB_KERNEL_NAME
    
    # prepare the env file required for the JupyterLab kernel
    mkdir -p $LAB_KERNEL_DIR/bin
    
    # start of env creation
    cat <<EOF > $LAB_KERNEL_DIR/bin/env.sh
    #!/usr/bin/env bash
    set -euxo pipefail
    EOF
    
    # append the necessary env variables for spack env and tools
    diff /tmp/before.txt /tmp/after.txt|grep ">"|cut -c 3- |awk '$0="export "$0' >> $LAB_KERNEL_DIR/bin/env.sh
    
    # end of env creation
    cat <<EOF >>$LAB_KERNEL_DIR/bin/env.sh
    python -m ipykernel_launcher -f \$@
    EOF
    chmod +x $LAB_KERNEL_DIR/bin/env.sh
    
    # create the new kernel's configuration file
    mkdir -p $LAB_KERNEL_DIR/$LAB_KERNEL_NAME
    cat <<EOF >$LAB_KERNEL_DIR/$LAB_KERNEL_NAME/kernel.json
    {
     "argv": ["$LAB_KERNEL_DIR/bin/env.sh", "{connection_file}", "--profile=default"],
     "display_name": "RELEASE_NAME",
     "name": "$LAB_KERNEL_NAME",
     "language": "python",
     "env": { "LAB_KERNEL_NAME": "$RELEASE_NAME", "LAB_KERNEL_RELEASE_DATE": "$(date +"%Y-%m-%d")" }
    }
    EOF