aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Smolyakov <v-asmoliakov@microsoft.com>2023-09-27 21:51:26 +0300
committerGitHub <noreply@github.com>2023-09-27 21:51:26 +0300
commit0d2fc3ad5b9d6bb33a29891c2378a377f0618c9b (patch)
treed955fe79da7e1038a78bfe826c10baa82570dcd6 /src
parente7f7d194d634e86b29ed2b74a35dd3c24fa1f7a5 (diff)
[python] Change the `sudo_if` function to avoid issues with Bash (#694)feature_python_1.2.0
* [python] Updated `sudo_if` function - Remove double quotes to avoid issues with string tokenization * Add test scenario * Revert "Add test scenario" This reverts commit 9e62a3797a8f5eddf5c24a6b5fd30bd2c4be8c54. * Update `jupyterlab git` package name * Bump feature version * Test: Install jupyterlab under root user * Refactor changes * Bump patch version * Address review points
Diffstat (limited to 'src')
-rw-r--r--src/python/devcontainer-feature.json2
-rwxr-xr-xsrc/python/install.sh39
2 files changed, 30 insertions, 11 deletions
diff --git a/src/python/devcontainer-feature.json b/src/python/devcontainer-feature.json
index b4aa21e..638fa60 100644
--- a/src/python/devcontainer-feature.json
+++ b/src/python/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "python",
- "version": "1.1.0",
+ "version": "1.2.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.",
diff --git a/src/python/install.sh b/src/python/install.sh
index 0e2b125..7be5eea 100755
--- a/src/python/install.sh
+++ b/src/python/install.sh
@@ -304,25 +304,31 @@ sudo_if() {
if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
su - "$USERNAME" -c "$COMMAND"
else
- "$COMMAND"
+ $COMMAND
fi
}
install_user_package() {
- PACKAGE="$1"
- sudo_if "${PYTHON_SRC}" -m pip install --user --upgrade --no-cache-dir "$PACKAGE"
+ INSTALL_UNDER_ROOT="$1"
+ PACKAGE="$2"
+
+ if [ "$INSTALL_UNDER_ROOT" = true ]; then
+ sudo_if "${PYTHON_SRC}" -m pip install --upgrade --no-cache-dir "$PACKAGE"
+ else
+ sudo_if "${PYTHON_SRC}" -m pip install --user --upgrade --no-cache-dir "$PACKAGE"
+ fi
}
add_user_jupyter_config() {
- CONFIG_DIR="/home/$USERNAME/.jupyter"
- CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py"
+ CONFIG_DIR="$1"
+ CONFIG_FILE="$2"
# Make sure the config file exists or create it with proper permissions
test -d "$CONFIG_DIR" || sudo_if mkdir "$CONFIG_DIR"
test -f "$CONFIG_FILE" || sudo_if touch "$CONFIG_FILE"
# Don't write the same config more than once
- grep -q "$1" "$CONFIG_FILE" || echo "$1" >> "$CONFIG_FILE"
+ grep -q "$3" "$CONFIG_FILE" || echo "$3" >> "$CONFIG_FILE"
}
install_python() {
@@ -461,13 +467,26 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then
exit 1
fi
- install_user_package jupyterlab
- install_user_package jupyterlab-git
+ INSTALL_UNDER_ROOT=true
+ if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
+ INSTALL_UNDER_ROOT=false
+ fi
+
+ install_user_package $INSTALL_UNDER_ROOT jupyterlab
+ install_user_package $INSTALL_UNDER_ROOT jupyterlab-git
# Configure JupyterLab if needed
if [ -n "${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}" ]; then
- add_user_jupyter_config "c.ServerApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'"
- add_user_jupyter_config "c.NotebookApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'"
+ # Resolve config directory
+ CONFIG_DIR="/root/.jupyter"
+ if [ "$INSTALL_UNDER_ROOT" = false ]; then
+ CONFIG_DIR="/home/$USERNAME/.jupyter"
+ fi
+
+ CONFIG_FILE="$CONFIG_DIR/jupyter_server_config.py"
+
+ add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE "c.ServerApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'"
+ add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE "c.NotebookApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN}'"
fi
fi