From 85b66709fddeb54c6f474a35af722e0f2c8cdf7a Mon Sep 17 00:00:00 2001 From: Jan Romaniak Date: Fri, 20 Dec 2024 17:08:00 +0100 Subject: [PATCH] fixes / mypy dont pass --- MANIFEST.in | 19 ++++++++++ docker/Dockerfile | 45 +++++++++-------------- docker/entrypoint.sh | 2 +- pyproject.toml | 17 +++++---- src/hct_mis_api/apps/core/es_analyzers.py | 2 +- 5 files changed, 47 insertions(+), 38 deletions(-) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000..233373482f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,19 @@ +exclude * +exclude __pycache__ +exclude node_modules + +include README.md +include MANIFEST.in +include AUTHORS +include CHANGES.md +include LICENSE.md +include pyproject.toml +include *.py +include uv.lock + + +recursive-include src/hct_mis_api * +recursive-include src/hct_mis_api *.html +recursive-include src/hct_mis_api *.json + +recursive-exclude src/**/node_modules *.* diff --git a/docker/Dockerfile b/docker/Dockerfile index e2fb56466f..bb9c92266d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,5 @@ FROM alpine:3.19.1 as curl RUN apk add curl && mkdir /data - FROM curl as waitforit RUN curl -o /data/waitforit -sSL https://github.com/maxcnunes/waitforit/releases/download/v2.4.1/waitforit-linux_amd64 \ && chmod +x /data/waitforit @@ -10,7 +9,7 @@ RUN curl -o /data/psql-cert.crt -L https://dl.cacerts.digicert.com/DigiCertGloba # Base image FROM python:3.12.7-slim-bookworm as base - +ENV APP_PATH=/app ARG UID=82 RUN apt-get update \ @@ -35,20 +34,14 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* \ && addgroup --system --gid "${UID}" hope \ && adduser --system --uid "${UID}" --disabled-password --home /home/hope --shell /sbin.nologin --group hope --gecos hope \ - && mkdir -p /code /tmp /data \ + && mkdir -p $APP_PATH /tmp /data \ && mkdir -p -m 0700 /run/user/"${UID}" \ - && chown -R hope:hope /code /tmp /data /run/user/"${UID}" - -ENV PDM_PACKAGES=/packages -ENV CODE=/code -ENV PDM_PROJECT=$PDM_PACKAGES -ENV PYPACKAGES=$PDM_PACKAGES/__pypackages__/3.12 -ENV PYTHONPYCACHEPREFIX=/tmp/pycache \ - PYTHONPATH=$PYPACKAGES/lib:$PYTHONPATH \ - PATH=$PYPACKAGES/bin:$PATH \ - XDG_RUNTIME_DIR=/run/user/"${UID}" + && chown -R hope:hope $APP_PATH /tmp /data /run/user/"${UID}" + + +ENV XDG_RUNTIME_DIR=/run/user/"${UID}" ENV DJANGO_SETTINGS_MODULE=hct_mis_api.config.settings -WORKDIR $CODE +WORKDIR $APP_PATH COPY --from=waitforit /data/waitforit /usr/local/bin/waitforit @@ -57,8 +50,7 @@ FROM base as uv RUN pip install --upgrade pip &&\ pip install uv &&\ pip install setuptools==71.1.0 -WORKDIR $PDM_PACKAGES -COPY README.md LICENSE pyproject.toml uv.lock ./ +COPY README.md LICENSE pyproject.toml uv.lock MANIFEST.in ./ @@ -77,19 +69,17 @@ RUN apt-get update \ dbus \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* - -ENV PYTHONPATH=$CODE/src:$CODE/test/:$PYTHONPATH +WORKDIR $APP_PATH +COPY ./src/ ./src/ RUN --mount=type=cache,target=/root/.uv-cache \ uv sync --cache-dir=/root/.uv-cache \ --python=/usr/local/bin/python \ --python-preference=system \ --no-editable --frozen --extra distribution - -WORKDIR $CODE -COPY ./src/ ./src/ COPY ./tests ./tests +COPY ./src/data /app/data COPY ./manage.py ./manage.py -COPY .flake8 pyproject.toml uv.lock ./ +COPY .flake8 pyproject.toml uv.lock MANIFEST.in ./ COPY ./docker/entrypoint.sh /bin/ ENTRYPOINT ["entrypoint.sh"] @@ -106,11 +96,10 @@ RUN NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=4096" yarn build # Dist builder image FROM uv as dist-builder +WORKDIR $APP_PATH COPY ./src/ ./src/ -COPY --chown=hope:hope --from=frontend-builder /fe-build/build $PDM_PACKAGES/src/hct_mis_api/apps/web/static/web -RUN --mount=type=cache,target=/root/.uv-cache \ - uv sync --cache-dir=/root/.uv-cache \ - --python=/usr/local/bin/python \ +COPY --chown=hope:hope --from=frontend-builder /fe-build/build $APP_PATH/src/hct_mis_api/apps/web/static/web +RUN uv sync --python=/usr/local/bin/python \ --python-preference=system \ --no-dev --no-editable --frozen --extra distribution @@ -120,9 +109,9 @@ FROM base AS dist COPY ./src/gunicorn_config.py /conf/gunicorn_config.py -COPY --chown=hope:hope --from=dist-builder $PDM_PACKAGES $PDM_PACKAGES +COPY --chown=hope:hope --from=dist-builder $APP_PATH/.venv $APP_PATH/.venv COPY --chown=hope:hope --from=certs /data/psql-cert.crt /certs/psql-cert.crt - +COPY ./src/data /app/data USER hope COPY ./docker/entrypoint.sh /bin/ diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 8764f5d8fa..07cb0d5d49 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e - +source .venv/bin/activate wait_for_db() { until pg_isready -h $1 -p 5432; do echo "waiting for database ${1}"; sleep 2; done; diff --git a/pyproject.toml b/pyproject.toml index baecfa24ca..7d8cd40af1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ exclude = [ "venv", "snapshots", "__pypackages__", + "build" ] strict = true @@ -126,13 +127,6 @@ dev-dependencies = [ "coverage<8.0.0,>=7.3.2", ] -[build-system] -requires = ["setuptools>=42"] -build-backend = "setuptools.build_meta" - -[tool.pdm.build] -includes = ['src/hct_mis_api', 'src/data'] - [tool.pdm] distribution = true @@ -244,5 +238,12 @@ requires-python = "==3.12.*" readme = "README.md" license = { text = "None" } +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + [tool.setuptools] -py-modules = ["hct_mis_api"] +package-dir = { "" = "src" } + +[tool.setuptools.packages.find] +where = ["src"] diff --git a/src/hct_mis_api/apps/core/es_analyzers.py b/src/hct_mis_api/apps/core/es_analyzers.py index 023900059e..302d9c152e 100644 --- a/src/hct_mis_api/apps/core/es_analyzers.py +++ b/src/hct_mis_api/apps/core/es_analyzers.py @@ -18,7 +18,7 @@ filter=["lowercase", phonetic_filter], ) -with open(os.path.join(settings.PROJECT_ROOT, "../data/synonyms.txt")) as synonyms_file: +with open(os.path.join(settings.PROJECT_ROOT, "/app/data/synonyms.txt")) as synonyms_file: synonyms = synonyms_file.readlines() name_synonym_analyzer_token_filter = token_filter(