Commit 1811a43b authored by Jens Henrik Goebbert's avatar Jens Henrik Goebbert

fix a bug / add more checks

parent 30f2b968
......@@ -39,17 +39,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"goebbert1_kernel\n"
]
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# INPUT NEEDED:\n",
"KERNEL_NAME=${USER}_kernel\n",
......@@ -58,13 +50,36 @@
"echo ${KERNEL_NAME} # double check"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* List directories where JupyterLab will search for kernels"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# JUPYTER SEARCH PATH (for kernels-directory)\n",
"echo \"jupyter search paths for kernels-directories\"\n",
"if [ -z $JUPYTER_PATH ]; then\n",
" echo \"$HOME/.local/share/jupyter\"\n",
"else\n",
" tr ':' '\\n' <<< \"$JUPYTER_PATH\"\n",
"fi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Set kernel type\n",
" - private kernel = \"\\${HOME}/.local/\" \n",
" - project kernel = \"\\${PROJECT}/.local/\" "
" - project kernel = \"\\${PROJECT}/.local/\" \n",
" - other kernel = \"\\<your-path\\>\" (ensure it is part of $JUPYTER_PATH or your kernel will not be found by JuypterLab)"
]
},
{
......@@ -74,17 +89,23 @@
"outputs": [],
"source": [
"# INPUT NEEDED:\n",
"export KERNEL_TYPE=private # private or project\n",
"export KERNEL_TYPE=private # private, project or other\n",
"export KERNEL_SPECS_PREFIX=/p/home/jusers/$USER/jureca/.local\n",
"\n",
"###################\n",
"# project kernel\n",
"if [ \"${KERNEL_TYPE}\" == \"project\" ]; then\n",
" export KERNEL_SPECS_PREFIX=${PROJECT}/.local\n",
" echo \"project kernel\"\n",
"# private kernel\n",
"if [ \"${KERNEL_TYPE}\" == \"private\" ]; then\n",
"elif [ \"${KERNEL_TYPE}\" == \"private\" ]; then\n",
" export KERNEL_SPECS_PREFIX=${HOME}/.local\n",
" echo \"private kernel\"\n",
"# project kernel\n",
"else\n",
" export KERNEL_SPECS_PREFIX=${PROJECT}/.local\n",
" echo \"project kernel\"\n",
" if [ ! -d \"$KERNEL_SPECS_PREFIX\" ]; then\n",
" echo \"ERROR: please create directory $KERNEL_SPECS_PREFIX\"\n",
" fi\n",
" echo \"other kernel\"\n",
"fi\n",
"export KERNEL_SPECS_DIR=${KERNEL_SPECS_PREFIX}/share/jupyter/kernels\n",
"\n",
......@@ -116,12 +137,13 @@
"\n",
"###################\n",
"mkdir -p ${KERNEL_VENVS_DIR}\n",
"if [ \"${KERNEL_TYPE}\" != \"private\" ]; then\n",
"if [ \"${KERNEL_TYPE}\" != \"private\" ] && [ \"${KERNEL_TYPE}\" != \"other\" ]; then\n",
" echo \"Please check the permissions and ensure your project partners have read/execute permissions:\"\n",
" namei -l ${KERNEL_VENVS_DIR}\n",
"fi\n",
"\n",
"echo ${KERNEL_VENVS_DIR} # double check"
"echo ${KERNEL_VENVS_DIR} # double check\n",
"ls -lt ${KERNEL_VENVS_DIR}"
]
},
{
......@@ -135,7 +157,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Create/Pimp new virual Python environment"
"## 1. Create/Pimp new virtual Python environment"
]
},
{
......@@ -189,10 +211,15 @@
"metadata": {},
"outputs": [],
"source": [
"python -m venv --system-site-packages ${KERNEL_VENVS_DIR}/${KERNEL_NAME}\n",
"source ${KERNEL_VENVS_DIR}/${KERNEL_NAME}/bin/activate\n",
"export PYTHONPATH=${VIRTUAL_ENV}/lib/python3.6/site-packages:${PYTHONPATH}\n",
"echo ${VIRTUAL_ENV} # double check"
"if [ -d \"${KERNEL_VENVS_DIR}/${KERNEL_NAME}\" ]; then\n",
" echo \"ERROR: Directory for virtual environment already ${KERNEL_VENVS_DIR}/${KERNEL_NAME}\"\n",
" echo \" Rename kernel name or remove directory.\"\n",
"else\n",
" python -m venv --system-site-packages ${KERNEL_VENVS_DIR}/${KERNEL_NAME}\n",
" source ${KERNEL_VENVS_DIR}/${KERNEL_NAME}/bin/activate\n",
" export PYTHONPATH=${VIRTUAL_ENV}/lib/python3.6/site-packages:${PYTHONPATH}\n",
" echo ${VIRTUAL_ENV} # double check\n",
"fi"
]
},
{
......@@ -256,7 +283,7 @@
"metadata": {},
"outputs": [],
"source": [
"echo \"#!/bin/bash\n",
"echo '#!/bin/bash'\"\n",
"\n",
"# Load required modules\n",
"module purge\n",
......@@ -275,7 +302,9 @@
"export PYTHONPATH=${VIRTUAL_ENV}/lib/python3.6/site-packages:\"'${PYTHONPATH}'\"\n",
" \n",
"exec python -m ipykernel \"'$@' > ${VIRTUAL_ENV}/kernel.sh\n",
"chmod +x ${VIRTUAL_ENV}/kernel.sh"
"chmod +x ${VIRTUAL_ENV}/kernel.sh\n",
"\n",
"cat ${VIRTUAL_ENV}/kernel.sh # double check"
]
},
{
......@@ -334,7 +363,9 @@
" ],\n",
" \"display_name\": \"'${KERNEL_NAME}'\",\n",
" \"language\": \"python\"\n",
"}' > ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME}/kernel.json"
"}' > ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME}/kernel.json\n",
"\n",
"cat ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME}/kernel.json # double check"
]
},
{
......@@ -352,6 +383,7 @@
"source": [
"cd ${KERNEL_SPECS_DIR}\n",
"ln -s ${VIRTUAL_ENV_KERNELS}/${KERNEL_NAME} .\n",
"\n",
"ls ${KERNEL_SPECS_DIR} # double check"
]
},
......
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