# Using Python 3.10.9 to match the development environment
# This specific version is required to avoid "ModuleNotFoundError: No module named 'distutils'"
# and "Cannot import 'setuptools.build_meta'" errors reported by the peer reviewer
FROM python:3.10.9-slim

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Set permissions
RUN chmod -R 777 /app

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies - using specific versions to ensure reproducibility
# This will also install setuptools>=58.0.0 to fix the 'distutils' and 'build_meta' issues
RUN pip install --no-cache-dir -r requirements.txt

# Copy all Python files to root directory
COPY *.py ./

# Copy Sensitivity_Analysis script - avoiding spaces in filenames for compatibility
COPY "Sensitivity_Analysis.py" ./

# Copy data files directly to root directory - all graphml files must be in the root
COPY *.graphml ./

# Set environment variables
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV MPLBACKEND=Agg

# Verify setup
COPY verify_setup.sh .
RUN chmod +x verify_setup.sh
RUN ./verify_setup.sh

# Default command
CMD ["python", "PANARCH.py"]