Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/behave.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
path: django/coverage.xml

- name: Display Coverage Metrics
if: matrix.python-version == '3.12'
uses: 5monkeys/cobertura-action@v14
with:
minimum_coverage: "50"
report_name: "Django Pytest/Behave Coverage"
path: django/coverage.xml


- name: Check Docker state (post-test)
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,26 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install uv pytest-github-actions-annotate-failures
uv pip install --system -r requirements/local.txt --prerelease=allow
uv pip install --system -r django/requirements/local.txt --prerelease=allow

- name: Apply migrations
env:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram_${{ matrix.python-version }}"
run: |
cd django/src
python manage.py makemigrations --noinput
python manage.py migrate --noinput

- name: Check for missing migrations
env:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram_${{ matrix.python-version }}"
run: python manage.py makemigrations --check
run: cd django/src && python manage.py makemigrations --check

- name: Run Pytest
env:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram_${{ matrix.python-version }}"
REDIS_HOST: "localhost"
run: pytest
run: cd django/src && pytest

- name: Install Scheduler Dependencies
run: |
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pytest_next_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install uv
uv pip install --system -r requirements/local.txt --prerelease=allow
uv pip install --system -r django/requirements/local.txt --prerelease=allow
# https://github.com/pytest-dev/pytest-github-actions-annotate-failures/pull/68 isn't yet in a release
uv pip install --system git+https://github.com/pytest-dev/pytest-github-actions-annotate-failures.git@6e66cd895fe05cd09be8bad58f5d79110a20385f

- name: Apply unapplied migrations
env:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram"
run: |
cd django/src
python manage.py makemigrations --noinput || true
python manage.py migrate --fake-initial --noinput -v 2

- name: Check for duplicate migrations
run: |
cd django/src
if python manage.py makemigrations --dry-run | grep "No changes detected"; then
echo "No duplicate migrations detected."
else
Expand All @@ -80,4 +82,4 @@ jobs:
DATABASE_URL: "postgres://scram:@localhost:5432/test_scram"
REDIS_HOST: "localhost"
run: |
pytest || echo "::warning:: Failed on future Python version ${{ matrix.python-version }}."
cd django/src && pytest || echo "::warning:: Failed on future Python version ${{ matrix.python-version }}."
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Django_Debugger.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ fail_fast: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.14
rev: v0.15.12
hooks:
- id: ruff-format
- id: ruff-check
Expand All @@ -26,7 +26,7 @@ repos:
always_run: true

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.10.7
rev: 0.11.8
hooks:
- id: uv-lock
args: [--check]
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"localRoot": "${workspaceFolder}/django",
"remoteRoot": "/app"
}
]
Expand All @@ -29,7 +29,7 @@
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"localRoot": "${workspaceFolder}/django",
"remoteRoot": "/app"
}
]
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ compose.override.yml:
## behave-all: runs behave inside the containers against all of your features
.Phony: behave-all
behave-all: compose.override.yml
@docker compose run --rm django coverage run -a manage.py behave --no-input --simple
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django coverage run -a src/manage.py behave --no-input --simple

## behave: runs behave inside the containers against a specific feature (append FEATURE=feature_name_here)
.Phony: behave
behave: compose.override.yml
@docker compose run --rm django python manage.py behave --no-input --simple -i $(FEATURE)
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django python src/manage.py behave --no-input --simple -i $(FEATURE)

## integration-tests: runs multi-instance system tests against docker compose running containers
.Phony: integration-tests
integration-tests: run
@docker compose exec -T django coverage run -a manage.py behave --no-input --use-existing-database scram/route_manager/tests/integration
@docker compose exec -T -w /app -e PYTHONPATH=/app/src django coverage run -a src/manage.py behave --no-input --use-existing-database src/scram/route_manager/tests/integration

## behave-translator
.Phony: behave-translator
Expand All @@ -52,8 +52,8 @@ build: compose.override.yml

## coverage.xml: generate coverage from test runs
coverage.xml: pytest behave-all integration-tests behave-translator
@docker compose run --rm django coverage report
@docker compose run --rm django coverage xml
@docker compose run --rm -w /app django coverage report
@docker compose run --rm -w /app django coverage xml

## ci-test: runs all tests just like Github CI does
.Phony: ci-test
Expand Down Expand Up @@ -127,7 +127,7 @@ pass-reset: compose.override.yml
## pytest: runs pytest inside the containers
.Phony: pytest
pytest: compose.override.yml
@docker compose run --rm django coverage run -m pytest
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django coverage run -m pytest

## pytest-scheduler: runs scheduler package tests with coverage
.Phony: pytest-scheduler
Expand Down Expand Up @@ -157,7 +157,7 @@ tail-log: compose.override.yml
## type-check: static type checking
.Phony: type-check
type-check: compose.override.yml
@docker compose run --rm django mypy scram
@docker compose run --rm -w /app -e PYTHONPATH=/app/src django mypy src/scram

## docs-build: build the documentation
.Phony: docs-build
Expand Down
4 changes: 2 additions & 2 deletions compose.override.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
dockerfile: ./compose/local/django/Dockerfile
image: scram_local_django
volumes:
- $CI_PROJECT_DIR:/app:z
- $CI_PROJECT_DIR/django:/app:z
- /tmp/profile_data:/tmp/profile_data
env_file:
- ./.envs/.local/.django
Expand All @@ -31,7 +31,7 @@ services:
dockerfile: ./compose/local/django/Dockerfile
image: scram_local_django
volumes:
- $CI_PROJECT_DIR:/app:z
- $CI_PROJECT_DIR/django:/app:z
- /tmp/profile_data:/tmp/profile_data
env_file:
- ./.envs/.local/.django
Expand Down
4 changes: 2 additions & 2 deletions compose.override.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- path: '/etc/vault.d/secrets/kv_root_security.env'
required: false
volumes:
- ./staticfiles:/staticfiles
- ./django/staticfiles:/staticfiles
healthcheck:
test: ["CMD", "curl", "-f", "http://django:5000/process_updates/"]

Expand Down Expand Up @@ -58,7 +58,7 @@ services:
- ./compose/production/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt/live/${HOSTNAME}/fullchain.pem:/etc/ssl/server.crt
- /etc/letsencrypt/live/${HOSTNAME}/privkey.pem:/etc/ssl/server.key
- ./staticfiles:/staticfiles
- ./django/staticfiles:/staticfiles
ports:
- "443:443"
- "80:80"
Expand Down
6 changes: 3 additions & 3 deletions compose/local/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*

# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
COPY ./django/requirements /requirements
RUN pip install uv
RUN uv pip install --system -r /requirements/local.txt --prerelease=allow

Expand All @@ -30,7 +30,7 @@ COPY ./compose/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

ENV PATH="$PATH:/app"
WORKDIR /app
ENV PATH="$PATH:/app/src"
WORKDIR /app/src

ENTRYPOINT ["/entrypoint"]
2 changes: 1 addition & 1 deletion compose/local/docs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN apt-get update \


# Only re-run the pip install if these files have changed
COPY requirements/base.txt requirements/local.txt requirements/production.txt /app/requirements/
COPY django/requirements/base.txt django/requirements/local.txt django/requirements/production.txt /app/requirements/
RUN pip install uv
RUN uv pip install --system -r /app/requirements/local.txt -r /app/requirements/production.txt --prerelease=allow

Expand Down
6 changes: 3 additions & 3 deletions compose/production/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN addgroup --system django \
&& adduser --system --ingroup django django

# Requirements are installed here to ensure they will be cached.
COPY ./requirements/ /requirements
COPY ./django/requirements/ /requirements
RUN pip install uv
RUN uv pip install --system --no-cache-dir -r /requirements/production.txt \
&& rm -rf /requirements
Expand All @@ -34,10 +34,10 @@ COPY --chown=django:django ./compose/production/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

COPY --chown=django:django . /app
COPY --chown=django:django ./django /app

USER django

WORKDIR /app
WORKDIR /app/src

ENTRYPOINT ["/entrypoint"]
4 changes: 2 additions & 2 deletions compose/production/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o pipefail
set -o nounset


python /app/manage.py collectstatic --noinput
python /app/src/manage.py collectstatic --noinput


/usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:5000 --chdir=/app -k uvicorn.workers.UvicornWorker
/usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:5000 --chdir=/app/src -k uvicorn.workers.UvicornWorker
10 changes: 0 additions & 10 deletions config/routing.py

This file was deleted.

File renamed without changes.
83 changes: 83 additions & 0 deletions django/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[project]
name = "scram-django"
version = "1.5.1"

# ==== pytest ====
[tool.pytest.ini_options]
addopts = [
"--ds=config.settings.test",
"--reuse-db",
]
minversion = "6.0"
pythonpath = ["src"]
python_files = [
"tests.py",
"test_*.py",
]

# ==== Coverage ====
[tool.coverage.run]
branch = true
data_file = "coverage.coverage"
include = ["src/scram/*", "src/config/*"]
omit = ["**/migrations/*", "src/scram/contrib/*", "*/tests/*"]
plugins = ["django_coverage_plugin"]

[tool.coverage.report]
exclude_also = [
"if debug:",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
]

# ===== ruff ====
# Base ruff config is inherited from the root pyproject.toml.
[tool.ruff]
exclude = ["migrations"]

[tool.ruff.lint.per-file-ignores]
"src/scram/route_manager/**" = [
"DOC201", # documenting return values
]
"src/scram/users/**" = [
"DOC201", # documenting return values
"FBT001", # minimal issue; don't need to mess with in the User app
"PLR2004", # magic values when checking HTTP status codes
]
"test.py" = [
"S105", # hardcoded password as argument
]

# ==== mypy ====
[tool.mypy]
check_untyped_defs = true
exclude = ["src/scram/route_manager/tests"]
ignore_missing_imports = true
plugins = [
"mypy_django_plugin.main",
# We did used to have mypy_drf_plugin.main but it seems like it never actually worked...
]
python_version = "3.12"
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
# Django migrations should not produce any errors:
ignore_errors = true
module = "*.migrations.*"

[tool.django-stubs]
django_settings_module = "config.settings.test"

# ==== behave ====
[tool.behave]
paths = ["src/scram/route_manager/tests/acceptance"]
stderr_capture = false

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading