Skip to content

Commit 096264b

Browse files
rodrigo-sobraletejedor
authored andcommitted
swancustomenvironments: Configure PATH variable in kernel.json
This configuration ensures the jupyter kernel uses the python in the environment under the hood and not the conda one This way, when user does `!pip install` in ATS it actually works. For more information, consult SWAN-416.
1 parent 89f9c6c commit 096264b

File tree

1 file changed

+6
-3
lines changed
  • SwanCustomEnvironments/swancustomenvironments/scripts

1 file changed

+6
-3
lines changed

SwanCustomEnvironments/swancustomenvironments/scripts/makenv.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ JUPYTER_PATH=${ENV_PATH}/share/jupyter python -m ipykernel install --name "${ENV
180180
KERNEL_JSON=${ENV_PATH}/share/jupyter/kernels/${ENV_NAME}/kernel.json
181181
ln -f -s ${KERNEL_JSON} /home/$USER/.local/share/jupyter/kernels/python3/kernel.json
182182

183+
TMP_KERNEL=$(mktemp)
183184
# For NXCALS, configure the environment kernel and terminal with some variables to
184185
# ensure the connection with the cluster works properly.
185186
if [ -n "${USE_NXCALS}" ]; then
@@ -193,21 +194,23 @@ if [ -n "${USE_NXCALS}" ]; then
193194
export PYSPARK_PYTHON="./environment/bin/python"
194195
export SPARK_DRIVER_EXTRA_JAVA_OPTIONS=$(awk '/^spark.driver.extraJavaOptions/ {sub(/^spark.driver.extraJavaOptions /, ""); print}' ${SPARK_HOME}/conf/spark-defaults.conf)
195196

196-
NEW_KERNEL=$(mktemp)
197197
jq --arg SPARK_HOME "${SPARK_HOME}" \
198198
--arg PYSPARK_PYTHON "${PYSPARK_PYTHON}" \
199199
--arg PATH "${PATH}" \
200200
--arg VIRTUAL_ENV "${ENV_PATH}" \
201201
--arg SPARK_DRIVER_EXTRA_JAVA_OPTIONS "${SPARK_DRIVER_EXTRA_JAVA_OPTIONS}" \
202202
'. + {env: {$SPARK_HOME, $PYSPARK_PYTHON, $PATH, $VIRTUAL_ENV, $SPARK_DRIVER_EXTRA_JAVA_OPTIONS}}' \
203-
${KERNEL_JSON} > ${NEW_KERNEL}
204-
mv -f ${NEW_KERNEL} ${KERNEL_JSON} 2>&1
203+
${KERNEL_JSON} > ${TMP_KERNEL}
205204

206205
# Terminal configuration
207206
# Only SPARK_HOME and PYSPARK_PYTHON are needed, since PATH and VIRTUAL_ENV are already
208207
# set when activating the environment in the terminal.
209208
echo -e "export SPARK_HOME=\"${SPARK_HOME}\"\nexport PYSPARK_PYTHON=\"${PYSPARK_PYTHON}\"" >> /home/$USER/.bash_profile
209+
else
210+
# Configure the PATH to point to all the binaries in the environment
211+
jq --arg PATH "${PATH}" '. + {env: {$PATH}}' ${KERNEL_JSON} > ${TMP_KERNEL}
210212
fi
213+
mv -f ${TMP_KERNEL} ${KERNEL_JSON} 2>&1
211214

212215
# Move the repository from /tmp to the $CERNBOX_HOME/SWAN_projects folder
213216
if [ ! -d "${GIT_REPO_PATH}" ]; then

0 commit comments

Comments
 (0)