From 8e8e14f6fbb1f1c30e7794aff293960caba2945a Mon Sep 17 00:00:00 2001 From: Mathiyarasy <157102811+Mathiyarasy@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:31:43 +0530 Subject: [PATCH] Codespace unable to start in Jupyter using python feature with option "installJupyterLab": true (#1199) * Add path for JupyterLab * Remove unwanted code --- src/python/devcontainer-feature.json | 12 +++++------ src/python/install.sh | 20 +++++++------------ test/python/install_jupyterlab.sh | 4 ++-- .../Dockerfile | 5 ----- .../sudoers.test | 2 -- test/python/scenarios.json | 13 ------------ 6 files changed, 15 insertions(+), 41 deletions(-) delete mode 100644 test/python/install_jupyterlab_existing_sudoers_file/Dockerfile delete mode 100644 test/python/install_jupyterlab_existing_sudoers_file/sudoers.test diff --git a/src/python/devcontainer-feature.json b/src/python/devcontainer-feature.json index 64b02fd34..64976fc63 100644 --- a/src/python/devcontainer-feature.json +++ b/src/python/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "python", - "version": "1.6.5", + "version": "1.7.0", "name": "Python", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/python", "description": "Installs the provided version of Python, as well as PIPX, and other common Python utilities. JupyterLab is conditionally installed with the python feature. Note: May require source code compilation.", @@ -67,7 +67,7 @@ "PYTHON_PATH": "/usr/local/python/current", "PIPX_HOME": "/usr/local/py-utils", "PIPX_BIN_DIR": "/usr/local/py-utils/bin", - "PATH": "/usr/local/python/current/bin:/usr/local/py-utils/bin:${PATH}" + "PATH": "/usr/local/python/current/bin:/usr/local/py-utils/bin:/usr/local/jupyter:${PATH}" }, "customizations": { "vscode": { @@ -78,9 +78,9 @@ ], "settings": { "python.defaultInterpreterPath": "/usr/local/python/current/bin/python", - "[python]": { - "editor.defaultFormatter": "ms-python.autopep8" - } + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + } } } }, @@ -88,4 +88,4 @@ "ghcr.io/devcontainers/features/common-utils", "ghcr.io/devcontainers/features/oryx" ] -} +} \ No newline at end of file diff --git a/src/python/install.sh b/src/python/install.sh index ead55cc8a..b3311c7c6 100755 --- a/src/python/install.sh +++ b/src/python/install.sh @@ -912,21 +912,15 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then install_user_package $INSTALL_UNDER_ROOT jupyterlab install_user_package $INSTALL_UNDER_ROOT jupyterlab-git + # Create a symlink to the JupyterLab binary for non root users if [ "$INSTALL_UNDER_ROOT" = false ]; then - # JupyterLab would have installed into /home/${USERNAME}/.local/bin - # Adding it to default path for Codespaces which use non-login shells - SUDOERS_FILE="/etc/sudoers.d/$USERNAME" - SEARCH_STR="Defaults secure_path=" - REPLACE_STR="Defaults secure_path=/home/${USERNAME}/.local/bin" - - if grep -qs ${SEARCH_STR} ${SUDOERS_FILE}; then - # string found and file is present - sed -i "s|${SEARCH_STR}|${REPLACE_STR}:|g" "${SUDOERS_FILE}" - else - # either string is not found, or file is not present - # In either case take same action, note >> places at end of file - echo "${REPLACE_STR}:${PATH}" >> ${SUDOERS_FILE} + JUPYTER_INPATH=/home/${USERNAME}/.local/bin + if [ ! -d "$JUPYTER_INPATH" ]; then + echo "Error: $JUPYTER_INPATH does not exist." + exit 1 fi + JUPYTER_PATH=/usr/local/jupyter + ln -s "$JUPYTER_INPATH" "$JUPYTER_PATH" fi # Configure JupyterLab if needed diff --git a/test/python/install_jupyterlab.sh b/test/python/install_jupyterlab.sh index 033b44edd..255b4e896 100755 --- a/test/python/install_jupyterlab.sh +++ b/test/python/install_jupyterlab.sh @@ -22,8 +22,8 @@ check "jupyterlab_git" grep jupyterlab_git <<< "$packages" # Check for correct JupyterLab configuration check "config" grep ".*.allow_origin = '*'" /home/vscode/.jupyter/jupyter_server_config.py -# Check for PATH modification -check "default path has jupyterlab" sudo grep "/home/${user}/.local/bin" /etc/sudoers.d/$user +#check "default path has jupyterlab symlink" +check "default path has jupyterlab" test -L "/usr/local/jupyter" # Report result reportResults diff --git a/test/python/install_jupyterlab_existing_sudoers_file/Dockerfile b/test/python/install_jupyterlab_existing_sudoers_file/Dockerfile deleted file mode 100644 index 5acb58a37..000000000 --- a/test/python/install_jupyterlab_existing_sudoers_file/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -# Builds an image with a preconfigured SUDOERS file -# Used to test the install script for JupyterLab which modifies this file -FROM mcr.microsoft.com/devcontainers/base:focal - -COPY --chown=root sudoers.test /etc/sudoers.d/vscode diff --git a/test/python/install_jupyterlab_existing_sudoers_file/sudoers.test b/test/python/install_jupyterlab_existing_sudoers_file/sudoers.test deleted file mode 100644 index 9a26d777b..000000000 --- a/test/python/install_jupyterlab_existing_sudoers_file/sudoers.test +++ /dev/null @@ -1,2 +0,0 @@ -# Sudoers File for testing, after install script runs the Defaults secure_path should be appended to -Defaults secure_path=/original_content_of_sudoers_file \ No newline at end of file diff --git a/test/python/scenarios.json b/test/python/scenarios.json index e4fe0f0cd..be37869df 100644 --- a/test/python/scenarios.json +++ b/test/python/scenarios.json @@ -68,19 +68,6 @@ } } }, - "install_jupyterlab_existing_sudoers_file": { - "build": { - "dockerfile": "Dockerfile" - }, - "remoteUser": "vscode", - "features": { - "python": { - "version": "latest", - "installJupyterlab": true, - "configureJupyterlabAllowOrigin": "*" - } - } - }, "install_jupyterlab_rhel_family": { "image": "almalinux:8", "remoteUser": "vscode",