Skip to content

Commit 5ca8d8d

Browse files
authored
Customize Jupyter & IPython config (#316)
- Move Jupyter configs to system-wide locations (`/opt/conda`). - Add settings to show hidden files in JupyterLab. - Remove `ipython_config.py` from `.gitignore`. - Add auto-import statement for IPython.
1 parent bf5a5b0 commit 5ca8d8d

File tree

6 files changed

+39
-9
lines changed

6 files changed

+39
-9
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ target/
7979

8080
# IPython
8181
profile_default/
82-
ipython_config.py
8382

8483
# pyenv
8584
.python-version

Dockerfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ RUN mamba env update -n base -f /tmp/environment.yml && \
2626
pip uninstall -y torch torchvision && \
2727
# Install PyTorch packages without cache - conditionally based on variant
2828
if [ "$PYTORCH_VARIANT" = "cpu" ]; then \
29-
echo "Installing CPU-only PyTorch" && \
30-
pip install --no-cache-dir --force-reinstall torch torchvision --index-url https://download.pytorch.org/whl/cpu; \
29+
echo "Installing CPU-only PyTorch" && \
30+
pip install --no-cache-dir --force-reinstall torch torchvision --index-url https://download.pytorch.org/whl/cpu; \
3131
else \
32-
echo "Installing CUDA-enabled PyTorch" && \
33-
pip install --no-cache-dir --force-reinstall torch torchvision; \
32+
echo "Installing CUDA-enabled PyTorch" && \
33+
pip install --no-cache-dir --force-reinstall torch torchvision; \
3434
fi && \
3535
# Clean up all package caches to reduce image size
3636
mamba clean --all -f -y && \
@@ -63,6 +63,17 @@ RUN apt-get update && \
6363
apt-get clean && \
6464
rm -rf /var/lib/apt/lists/*
6565

66+
# System-wide Jupyter Server config
67+
COPY docker/jupyter_server_config.py /opt/conda/etc/jupyter/
68+
69+
# Jupyter Lab settings
70+
RUN mkdir -p /opt/conda/share/jupyter/lab/settings
71+
COPY docker/overrides.json /opt/conda/share/jupyter/lab/settings/
72+
73+
# System-wide IPython profile config
74+
RUN mkdir -p /opt/conda/etc/ipython
75+
COPY docker/ipython_config.py /opt/conda/etc/ipython/
76+
6677
# Switch back to the default notebook user
6778
USER ${NB_UID}
6879

@@ -72,9 +83,6 @@ COPY --from=builder ${CONDA_DIR} ${CONDA_DIR}
7283
# Copy home directory with configurations
7384
COPY --from=builder --chown=${NB_UID}:${NB_GID} /home/${NB_USER} /home/${NB_USER}
7485

75-
# Prepare IPython configuration
76-
COPY --chown=${NB_UID}:${NB_GID} binder/ipython_config.py ${HOME}/.ipython/profile_default/
77-
7886
# Set the working directory to user's home (repository will be cloned here by Renku)
7987
WORKDIR /home/${NB_USER}
8088

binder/ipython_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434

3535
## lines of code to run at IPython startup.
3636
# Default: []
37-
# c.InteractiveShellApp.exec_lines = []
37+
c.InteractiveShellApp.exec_lines = [
38+
"from typing import Any, Callable, Dict, List, Optional, Tuple, Union"
39+
]
3840

3941
## A list of dotted module names of IPython extensions to load.
4042
# Default: []

docker/ipython_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Configuration file for ipython.
2+
c = get_config() # noqa # type: ignore
3+
4+
# Automatically load testsuite extension
5+
c.InteractiveShellApp.extensions = ["tutorial.tests.testsuite"]
6+
7+
# Automatically import some modules
8+
c.InteractiveShellApp.exec_lines = [
9+
"from typing import Any, Callable, Dict, List, Optional, Tuple, Union"
10+
]

docker/jupyter_server_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Configuration file for jupyter server.
2+
3+
c = get_config() # noqa # type: ignore
4+
5+
# Allow serving files/folders beginning with a dot
6+
c.ContentsManager.allow_hidden = True

docker/overrides.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"@jupyterlab/filebrowser-extension:browser": {
3+
"showHiddenFiles": true
4+
}
5+
}

0 commit comments

Comments
 (0)