# Base image: Jupyter stack with Conda + JupyterLab pinned to Python 3.13.11.
FROM quay.io/jupyter/minimal-notebook:python-3.13.11

# Use root for package installation and file ownership changes.
USER root

# Copy uv into the image so we can use its fast installer.
COPY --from=ghcr.io/astral-sh/uv:0.9.28 /uv /uvx /bin/

# Tell uv to target the Conda Python used by the Jupyter kernel.
ENV UV_PYTHON=${CONDA_DIR}/bin/python

# Provide a fallback version when git metadata is unavailable in Docker builds.
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_QUANTIFY=0.0.0

# Set the repo root as the working directory for subsequent commands.
WORKDIR ${HOME}

# Copy only the files needed to resolve and install dependencies first.
COPY pyproject.toml README.md LICENSE quantify/ "${HOME}/"

# Install the project in editable mode with Binder extras using uv.
RUN uv pip install --no-cache-dir -e ".[binder]"

# Copy the full repo into the notebook user's home directory.
COPY . "${HOME}"

# Fix ownership so the notebook user can read/write files.
RUN chown -R "${NB_UID}:${NB_GID}" "${HOME}"

# Ensure the repo root is on sys.path even if the kernel cwd differs.
ENV PYTHONPATH="${HOME}:${PYTHONPATH}"

# Drop back to the notebook user for runtime.
USER ${NB_UID}
