Skip to content

Commit a788850

Browse files
authored
Merge pull request #65 from NHSDigital/conventions
Update project conventions
2 parents dae2c74 + ff180a6 commit a788850

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+708
-1060
lines changed

.env.example

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
FLASK_APP=mavis_reporting:create_app
1+
FLASK_APP=mavis.reporting:create_app
22
FLASK_ENV=development
33
# Required by Flask - used internally
44
SECRET_KEY=(some random hex string)
5-
# Used as part of the OAuth 2.0 Authorization Code flow
6-
# to identify this application to Mavis when requesting an
5+
# Used as part of the OAuth 2.0 Authorization Code flow
6+
# to identify this application to Mavis when requesting an
77
# authorization code
88
CLIENT_ID=(some random hex string)
99
# Used for signing / decoding-and-verifying-the-signature-of JWTs
1010
CLIENT_SECRET=(some random hex string)
1111
MAVIS_ROOT_URL=http://localhost:4000/
12-
SESSION_TTL_SECONDS=600
12+
SESSION_TTL_SECONDS=600

.github/workflows/ci.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
gitleaks:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v5
10+
with:
11+
fetch-depth: 0 # Full history is needed to scan all commits
12+
- uses: jdx/mise-action@v3
13+
with:
14+
cache: true
15+
- run: gitleaks detect --verbose --redact
16+
17+
pytest:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v5
21+
- uses: jdx/mise-action@v3
22+
with:
23+
cache: true
24+
- env:
25+
SECRET_KEY: "${{ secrets.SECRET_KEY_FOR_TESTS }}"
26+
run: make test
27+
28+
ruff:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v5
32+
- uses: jdx/mise-action@v3
33+
with:
34+
cache: true
35+
- run: make lint
36+
37+
coverage:
38+
needs: [pytest]
39+
runs-on: ubuntu-latest
40+
if: github.ref == 'refs/heads/main'
41+
outputs:
42+
badge_url: ${{ steps.upload-coverage-badge-artifact-step.outputs.artifact-url }}
43+
html_report_url: ${{ steps.upload-html-report-artifact-step.outputs.artifact-url }}
44+
steps:
45+
- uses: actions/checkout@v5
46+
- uses: jdx/mise-action@v3
47+
with:
48+
cache: true
49+
- env:
50+
SECRET_KEY: "${{ secrets.SECRET_KEY_FOR_TESTS }}"
51+
COVERAGE_THRESHOLD: 80
52+
run: make test-coverage
53+
- uses: actions/upload-artifact@v4
54+
id: upload-html-report-artifact-step
55+
if: always()
56+
with:
57+
name: coverage-html
58+
path: htmlcov
59+
retention-days: 10
60+
compression-level: 0
61+
- uses: actions/upload-artifact@v4
62+
id: upload-coverage-badge-artifact-step
63+
if: always()
64+
with:
65+
name: coverage-badge
66+
path: coverage.svg
67+
retention-days: 10
68+
compression-level: 0

.github/workflows/deploy-application.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ on:
3030
required: true
3131
type: string
3232

33-
permissions: { }
33+
permissions: {}
3434

3535
concurrency:
3636
group: deploy-mavis-${{ inputs.environment }}
@@ -95,14 +95,13 @@ jobs:
9595
with:
9696
role-to-assume: ${{ env.aws_role }}
9797
aws-region: eu-west-2
98-
- name: Install poetry
99-
run: pipx install poetry
98+
- name: Install uv
99+
uses: astral-sh/setup-uv@v5
100100
- name: Setup python
101101
uses: actions/setup-python@v5
102102
with:
103103
python-version: 3.13.0
104-
cache: poetry
105-
- run: poetry install
104+
- run: uv sync --dev
106105
- name: Get image digest
107106
id: get-image-digest
108107
run: |
@@ -133,7 +132,7 @@ jobs:
133132
run: mv ${{ steps.create-task-definition.outputs.task-definition }} ${{ runner.temp }}/reporting-task-definition.json
134133
- name: Populate SSM parameters for reporting service
135134
run: |
136-
poetry run scripts/populate_ssm_parameters.py ${{ inputs.environment }} reporting
135+
uv run scripts/populate_ssm_parameters.py ${{ inputs.environment }} reporting
137136
- name: Upload artifact for reporting task definition
138137
uses: actions/upload-artifact@v4
139138
with:
@@ -151,7 +150,7 @@ jobs:
151150
deploy:
152151
name: Deploy reporting service
153152
runs-on: ubuntu-latest
154-
needs: [ prepare-deployment, approve-deployments ]
153+
needs: [prepare-deployment, approve-deployments]
155154
permissions:
156155
id-token: write
157156
steps:

.github/workflows/lint-and-test.yaml

Lines changed: 0 additions & 94 deletions
This file was deleted.

.gitignore

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ __pycache__/
1313
.ruff_cache/
1414
node_modules/
1515
.idea/
16-
mavis_reporting/static/css/*
17-
!mavis_reporting/static/css/.keep
16+
mavis/reporting/static/css/*
17+
!mavis/reporting/static/css/.keep
1818

19-
mavis_reporting/static/js/*
20-
!mavis_reporting/static/js/.keep
19+
mavis/reporting/static/js/*
20+
!mavis/reporting/static/js/.keep
2121

22-
mavis_reporting/static/favicons/*
23-
!mavis_reporting/static/favicons/.keep
22+
mavis/reporting/static/favicons/*
23+
!mavis/reporting/static/favicons/.keep
2424

2525
sentinel
2626

.tool-versions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
python 3.13.0
2-
poetry 2.1.3
3-
gitleaks 8.28.0
1+
gitleaks latest
2+
python 3.13
3+
uv latest

Dockerfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@ FROM python:3.13.7-alpine AS builder
22

33
WORKDIR /app
44

5-
ADD package.json package-lock.json pyproject.toml poetry.lock Makefile /app/
5+
ADD package.json package-lock.json pyproject.toml uv.lock Makefile /app/
66

77
RUN apk add build-base libffi-dev npm bash curl
88

9-
RUN pip install poetry
10-
RUN make install
9+
RUN pip install uv
1110

11+
ADD ./mavis/reporting /app/mavis/reporting
12+
ADD README.md /app/
13+
14+
RUN uv sync --frozen --all-extras
15+
RUN npm install
16+
17+
FROM builder
1218

13-
FROM builder
1419
WORKDIR /app
1520

16-
ADD ./mavis_reporting /app/mavis_reporting
1721
RUN make build-assets
1822

19-
# Create a new group `app` with Group ID `1000`.
2023
RUN addgroup --gid 1000 app
21-
# Create a new user `app`, sets home directory to `/app`, User ID `1000`, in
22-
# the group `app`. The `-DH` option results in a system account.
2324
RUN adduser app -h /app -u 1000 -G app -DH
24-
# Change the user for subsequent commands in Dockerfile to the user with ID
25-
# `1000`.
25+
RUN mkdir -p /app/.cache/uv && chown -R app:app /app/.cache
26+
RUN chown -R app:app /app/.venv
27+
2628
USER 1000
2729

2830
VOLUME ["/tmp", "/var/tmp", "/usr/tmp"]
2931

3032
# pass through additional arguments like --workers=5 via GUNICORN_CMD_ARGS
31-
CMD ["poetry", "run", "gunicorn", "--bind", "0.0.0.0:5000", "mavis_reporting:create_app()"]
33+
CMD ["uv", "run", "gunicorn", "--bind", "0.0.0.0:5000", "mavis.reporting:create_app()"]

Makefile

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ clean:
1111
@rm -rf .venv
1212
@rm -rf __pycache__
1313

14-
sentinel: package.json package-lock.json pyproject.toml poetry.lock
14+
sentinel: package.json package-lock.json pyproject.toml uv.lock
1515
@echo "== Installing dependencies =="
1616
@npm install || (echo "Failed to install npm dependencies"; exit 1)
17-
@poetry config virtualenvs.in-project true
18-
@poetry install || (echo "Failed to install Python dependencies"; exit 1)
17+
@uv sync --all-extras || (echo "Failed to install Python dependencies"; exit 1)
1918

2019
@echo "== Copying NHSUK favicons =="
2120
@make copy-nhsuk-favicons
@@ -31,22 +30,22 @@ install: sentinel
3130

3231
.PHONY: lint
3332
lint: install
34-
poetry run ruff check .
33+
uv run ruff check .
3534

3635
.PHONY: lint-fix
3736
lint-fix: install
38-
poetry run ruff check --fix .
37+
uv run ruff check --fix .
3938

4039
.PHONY: dev
4140
dev: install
4241
@echo "== Starting development servers =="
4342
@echo "Press Ctrl+C to stop all processes"
44-
@poetry run honcho start -f Procfile.dev
43+
@uv run honcho start -f Procfile.dev
4544

4645
.PHONY: copy-nhsuk-favicons
4746
copy-nhsuk-favicons:
48-
mkdir -p mavis_reporting/static/favicons
49-
cp -r node_modules/nhsuk-frontend/dist/nhsuk/assets/images/* mavis_reporting/static/favicons/
47+
mkdir -p mavis/reporting/static/favicons
48+
cp -r node_modules/nhsuk-frontend/dist/nhsuk/assets/images/* mavis/reporting/static/favicons/
5049

5150
build-docker:
5251
docker build -t ${DOCKER_IMAGE} .
@@ -57,13 +56,13 @@ run-docker:
5756

5857
test: install
5958
@echo "Running all tests .."
60-
@poetry run pytest tests --verbose
59+
@uv run pytest tests --verbose
6160

6261
.PHONY: test-coverage
6362
test-coverage: install
6463
@echo "Checking coverage on all tests .."
65-
@poetry run coverage run -m pytest tests --verbose
66-
@poetry run coverage report --fail-under=${COVERAGE_THRESHOLD}
67-
@poetry run coverage html
68-
@poetry run coverage xml coverage.xml
69-
@poetry run coverage-badge -o coverage.svg
64+
@uv run coverage run -m pytest tests --verbose
65+
@uv run coverage report --fail-under=${COVERAGE_THRESHOLD}
66+
@uv run coverage html
67+
@uv run coverage xml coverage.xml
68+
@uv run coverage-badge -o coverage.svg

Procfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
scss: npm run build:scss:dev
22
js: npm run build:js:dev
3-
flask: poetry run flask run --debug -p 5001
3+
flask: uv run flask run --debug -p 5001

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ A Flask-based web application for the commissioner reporting component of Mavis.
2121

2222
2. **Install project dependencies**
2323

24-
This will install the project dependencies using Poetry and NPM.
24+
This will install the project dependencies using uv and NPM.
2525

26-
Note that the Poetry virtual environment will be created in the `.venv` directory to allow IDEs to use the correct Python interpreter.
26+
Note that the uv virtual environment will be created in the `.venv` directory to allow IDEs to use the correct Python interpreter.
2727

2828
```bash
2929
make install

0 commit comments

Comments
 (0)