From 9f907c3b33372233177bb87c0752827b3d425ad9 Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Thu, 8 May 2025 15:55:52 +0200 Subject: [PATCH 1/3] Move Jupyter configs to system-wide locations - Configure IPython and Jupyter server at system level - Add settings to show hidden files in JupyterLab - Remove ipython_config.py from .gitignore - Dockerfile: copy files in respective locations --- .gitignore | 1 - Dockerfile | 22 +++++++++++++++------- docker/ipython_config.py | 5 +++++ docker/jupyter_server_config.py | 6 ++++++ docker/overrides.json | 5 +++++ 5 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 docker/ipython_config.py create mode 100644 docker/jupyter_server_config.py create mode 100644 docker/overrides.json diff --git a/.gitignore b/.gitignore index c7b06dfe..5e76afbf 100644 --- a/.gitignore +++ b/.gitignore @@ -79,7 +79,6 @@ target/ # IPython profile_default/ -ipython_config.py # pyenv .python-version diff --git a/Dockerfile b/Dockerfile index f9ebfe0b..02b67261 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,11 +26,11 @@ RUN mamba env update -n base -f /tmp/environment.yml && \ pip uninstall -y torch torchvision && \ # Install PyTorch packages without cache - conditionally based on variant if [ "$PYTORCH_VARIANT" = "cpu" ]; then \ - echo "Installing CPU-only PyTorch" && \ - pip install --no-cache-dir --force-reinstall torch torchvision --index-url https://download.pytorch.org/whl/cpu; \ + echo "Installing CPU-only PyTorch" && \ + pip install --no-cache-dir --force-reinstall torch torchvision --index-url https://download.pytorch.org/whl/cpu; \ else \ - echo "Installing CUDA-enabled PyTorch" && \ - pip install --no-cache-dir --force-reinstall torch torchvision; \ + echo "Installing CUDA-enabled PyTorch" && \ + pip install --no-cache-dir --force-reinstall torch torchvision; \ fi && \ # Clean up all package caches to reduce image size mamba clean --all -f -y && \ @@ -63,6 +63,17 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* +# System-wide Jupyter Server config +COPY docker/jupyter_server_config.py /etc/jupyter/ + +# Jupyter Lab settings +RUN mkdir -p /opt/conda/share/jupyter/lab/settings +COPY docker/overrides.json /opt/conda/share/jupyter/lab/settings/ + +# System-wide IPython profile config +RUN mkdir -p /etc/ipython/profile_default +COPY docker/ipython_config.py /etc/ipython/profile_default/ + # Switch back to the default notebook user USER ${NB_UID} @@ -72,9 +83,6 @@ COPY --from=builder ${CONDA_DIR} ${CONDA_DIR} # Copy home directory with configurations COPY --from=builder --chown=${NB_UID}:${NB_GID} /home/${NB_USER} /home/${NB_USER} -# Prepare IPython configuration -COPY --chown=${NB_UID}:${NB_GID} binder/ipython_config.py ${HOME}/.ipython/profile_default/ - # Set the working directory to user's home (repository will be cloned here by Renku) WORKDIR /home/${NB_USER} diff --git a/docker/ipython_config.py b/docker/ipython_config.py new file mode 100644 index 00000000..3c3d81cb --- /dev/null +++ b/docker/ipython_config.py @@ -0,0 +1,5 @@ +# Configuration file for ipython. +c = get_config() # noqa # type: ignore + +# Automatically load testsuite extension +c.InteractiveShellApp.extensions = ["tutorial.tests.testsuite"] diff --git a/docker/jupyter_server_config.py b/docker/jupyter_server_config.py new file mode 100644 index 00000000..b6b30d14 --- /dev/null +++ b/docker/jupyter_server_config.py @@ -0,0 +1,6 @@ +# Configuration file for jupyter server. + +c = get_config() # noqa # type: ignore + +# Allow serving files/folders beginning with a dot +c.ContentsManager.allow_hidden = True diff --git a/docker/overrides.json b/docker/overrides.json new file mode 100644 index 00000000..244ba287 --- /dev/null +++ b/docker/overrides.json @@ -0,0 +1,5 @@ +{ + "@jupyterlab/filebrowser-extension:browser": { + "showHiddenFiles": true + } +} From a862f354606ba0c17fdc92b460e8653962f9d80a Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Thu, 8 May 2025 16:28:06 +0200 Subject: [PATCH 2/3] Use /opt/conda path as system-wide --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02b67261..ed72ac0e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,15 +64,15 @@ RUN apt-get update && \ rm -rf /var/lib/apt/lists/* # System-wide Jupyter Server config -COPY docker/jupyter_server_config.py /etc/jupyter/ +COPY docker/jupyter_server_config.py /opt/conda/etc/jupyter/ # Jupyter Lab settings RUN mkdir -p /opt/conda/share/jupyter/lab/settings COPY docker/overrides.json /opt/conda/share/jupyter/lab/settings/ # System-wide IPython profile config -RUN mkdir -p /etc/ipython/profile_default -COPY docker/ipython_config.py /etc/ipython/profile_default/ +RUN mkdir -p /opt/conda/etc/ipython +COPY docker/ipython_config.py /opt/conda/etc/ipython/ # Switch back to the default notebook user USER ${NB_UID} From 4aab90f4df953d8b849f5f6d9733a8457a68c41e Mon Sep 17 00:00:00 2001 From: Edoardo Baldi Date: Thu, 8 May 2025 16:28:38 +0200 Subject: [PATCH 3/3] Add auto-import statement for IPython --- binder/ipython_config.py | 4 +++- docker/ipython_config.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/binder/ipython_config.py b/binder/ipython_config.py index a1e1b5f2..23616722 100644 --- a/binder/ipython_config.py +++ b/binder/ipython_config.py @@ -34,7 +34,9 @@ ## lines of code to run at IPython startup. # Default: [] -# c.InteractiveShellApp.exec_lines = [] +c.InteractiveShellApp.exec_lines = [ + "from typing import Any, Callable, Dict, List, Optional, Tuple, Union" +] ## A list of dotted module names of IPython extensions to load. # Default: [] diff --git a/docker/ipython_config.py b/docker/ipython_config.py index 3c3d81cb..387c234b 100644 --- a/docker/ipython_config.py +++ b/docker/ipython_config.py @@ -3,3 +3,8 @@ # Automatically load testsuite extension c.InteractiveShellApp.extensions = ["tutorial.tests.testsuite"] + +# Automatically import some modules +c.InteractiveShellApp.exec_lines = [ + "from typing import Any, Callable, Dict, List, Optional, Tuple, Union" +]