Skip to content

Commit ec3bddd

Browse files
committed
[PPHA-186] Use ruff for linting
In order to allow linting inside the docker container, create a "development" docker stage and run lint and test task via poetry. The same command can be used between CI and local
1 parent 7dffc11 commit ec3bddd

File tree

6 files changed

+71
-10
lines changed

6 files changed

+71
-10
lines changed

Dockerfile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ RUN npm run compile
1111
FROM python:3.13.5-alpine3.21 AS python_base
1212

1313
ENV PYTHONDONTWRITEBYTECODE=1 \
14-
PYTHONUNBUFFERED=1
14+
PYTHONUNBUFFERED=1 \
15+
VIRTUAL_ENV=/app/.venv \
16+
PATH="/app/.venv/bin:$PATH" \
17+
USER=app
18+
19+
RUN addgroup --gid 1000 --system ${USER} \
20+
&& adduser --uid 1000 --system ${USER} --ingroup ${USER}
1521

1622
FROM python_base AS builder
1723

@@ -26,15 +32,16 @@ COPY pyproject.toml poetry.lock ./
2632
RUN pip install poetry
2733
RUN poetry install --without dev --no-root && rm -rf $POETRY_CACHE_DIR
2834

35+
FROM builder AS development
2936

30-
FROM python_base
37+
RUN poetry install
3138

32-
ENV VIRTUAL_ENV=/app/.venv \
33-
PATH="/app/.venv/bin:$PATH" \
34-
USER=app
39+
USER ${USER}
40+
WORKDIR /app
3541

36-
RUN addgroup --gid 1000 --system ${USER} \
37-
&& adduser --uid 1000 --system ${USER} --ingroup ${USER}
42+
COPY --chown=${USER}:${USER} . .
43+
44+
FROM python_base
3845

3946
USER ${USER}
4047
WORKDIR /app

docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
services:
44
web:
5-
build: .
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
target: development
69
command: python manage.py runserver 0.0.0.0:8000
710
ports:
811
- "8000:8000"

poetry.lock

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ dependencies = [
1616
[tool.poetry]
1717
package-mode = false
1818

19+
[tool.poetry.group.dev.dependencies]
20+
ruff = "^0.12.5"
21+
1922
[build-system]
2023
requires = ["poetry-core>=2.0.0,<3.0.0"]
2124
build-backend = "poetry.core.masonry.api"

scripts/tests/lint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
cd "$(git rev-parse --show-toplevel)"
6+
7+
# This file is for you! Edit it to call your unit test suite. Note that the same
8+
# file will be called if you run it locally as if you run it on CI.
9+
10+
# Replace the following line with something like:
11+
#
12+
# rubocop
13+
# python manage.py lint
14+
# npm run lint
15+
#
16+
# or whatever is appropriate to your project. You should *only* run your fast
17+
# tests from here. If you want to run other test suites, see the predefined
18+
# tasks in scripts/lint.mk.
19+
20+
docker compose run --rm web poetry run ruff check lung_cancer_screening

scripts/tests/unit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ cd "$(git rev-parse --show-toplevel)"
1717
# tests from here. If you want to run other test suites, see the predefined
1818
# tasks in scripts/test.mk.
1919

20-
docker compose run web python manage.py test
20+
docker compose run web poetry run python manage.py test

0 commit comments

Comments
 (0)