FROM python:3.11.8-slim

ENV version=2
ENV PYTHONPATH=/app

WORKDIR /app

COPY requirements.txt ./requirements.txt

RUN pip3 install --no-cache-dir -r requirements.txt

# This is *really* bad, but I'd rather get this working rather than forking packages and re-publishing them.
# It'll probably break some day.
RUN sed -i 's/events: List\[Event\] = Field(deserialize_type=List\[_Event\])/events: List\[_Event\] = Field(deserialize_type=List\[_Event\])/' /usr/local/lib/python3.11/site-packages/ossapi/models.py && \
    sed -i 's/self\._conn = sqlite3.connect(str(cache_path))/self._conn = sqlite3.connect(str(cache_path), check_same_thread=False)/' /usr/local/lib/python3.11/site-packages/circleguard/loader.py && \
    sed -i  "64s|.*|        self._db = db = sqlite3.connect(str(path / '.slider.db'), check_same_thread=False)|" /usr/local/lib/python3.11/site-packages/slider/library.py

RUN sed -i '238s|return \[x for x in arr if lower_limit < x < upper_limit\]|arr_without_outliers = [x for x in arr if lower_limit < x < upper_limit]; return arr if not arr_without_outliers else arr_without_outliers|' /usr/local/lib/python3.11/site-packages/circleguard/utils.py

COPY ./src/ ./src/

WORKDIR /app/src

CMD ["python", "main.py"]
