Skip to content

Commit e03219e

Browse files
author
Susan Vanderplas
committed
Mess with python a bit?
1 parent 5793305 commit e03219e

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ jobs:
6666
-v "${HOME}/.cache/pip:/root/.cache/pip" \
6767
-e RENV_PATHS_CACHE=/root/.local/share/renv \
6868
-e PIP_CACHE_DIR=/root/.cache/pip \
69-
-e QUARTO_PYTHON="venv" \
7069
-e NEWSAPI_KEY="${{ secrets.NEWSAPI_KEY }}" \
7170
-e GH_APP_ID="${{ secrets.GH_APP_ID }}" \
7271
-e GH_APP_SECRET="${{ secrets.GH_APP_SECRET }}" \
@@ -96,17 +95,13 @@ jobs:
9695
echo "=== Package count in renv cache after restore ==="
9796
Rscript -e \'cat(length(list.files(Sys.getenv("RENV_PATHS_CACHE"), recursive=TRUE)), "packages in cache\n")\'
9897
99-
# Restore Python packages
98+
# Restore Python packages into baked-in venv
10099
if [ -f "/project/requirements.txt" ]; then
101-
echo "=== Restoring Python packages ==="
102-
python3 -m venv /root/.virtualenvs/venv
103-
/root/.virtualenvs/venv/bin/pip install --upgrade pip
104-
/root/.virtualenvs/venv/bin/pip install --cache-dir ${PIP_CACHE_DIR} -r /project/requirements.txt
105-
export PATH=/root/.virtualenvs/venv/bin:$PATH
106-
source /root/.virtualenvs/venv/bin/activate
100+
echo "=== Restoring Python packages into baked-in venv ==="
101+
/opt/venv/bin/pip install --cache-dir ${PIP_CACHE_DIR} -r /project/requirements.txt
107102
fi
108103
109104
# Render + publish
110105
cd /project
111106
quarto render && quarto publish
112-
' --verbose
107+
' --verbose

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ RUN curl -fsSL https://quarto.org/download/latest/quarto-linux-amd64.deb -o /tmp
4747
# --- Layer 4: TinyTeX
4848
RUN Rscript -e "tinytex::install_tinytex(force=T)"
4949

50+
# --- Layer 5: python
51+
# Install Python and venv support
52+
RUN apt-get update && \
53+
apt-get install -y python3 python3-venv python3-pip && \
54+
apt-get clean && rm -rf /var/lib/apt/lists/*
55+
56+
# Create a dedicated virtual environment
57+
ENV VENV_PATH=/opt/venv
58+
RUN python3 -m venv $VENV_PATH
59+
60+
# Make sure pip is up to date and install common build tools
61+
RUN $VENV_PATH/bin/pip install --upgrade pip setuptools wheel
62+
63+
# Register venv globally for R/reticulate and Quarto
64+
ENV PATH="$VENV_PATH/bin:$PATH"
65+
ENV RETICULATE_PYTHON=$VENV_PATH/bin/python
66+
ENV QUARTO_PYTHON=$VENV_PATH/bin/python
67+
68+
# Pre-install Jupyter kernel so Quarto sees it, and populate with dependencies
69+
RUN $VENV_PATH/bin/pip install ipykernel && \
70+
$VENV_PATH/bin/python -m ipykernel install --prefix=/usr/local --name=venv --display-name "Python (venv)" \
71+
$VENV_PATH/bin/pip install -r /project/requirements.txt
72+
73+
5074
# Ensure cache dirs exist
5175
RUN mkdir -p ${RENV_PATHS_CACHE} ${PIP_CACHE_DIR} /root/.virtualenvs
5276

0 commit comments

Comments
 (0)