Skip to content

Commit d82ca61

Browse files
committed
build: migrate backend dependency management to uv
1 parent 3770107 commit d82ca61

11 files changed

Lines changed: 1247 additions & 2247 deletions

File tree

‎.github/workflows/backend.yml‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,18 @@ jobs:
2121
- name: Checkout
2222
uses: actions/checkout@v5
2323

24-
- name: Setup Python
25-
uses: actions/setup-python@v5
24+
- name: Setup uv
25+
uses: astral-sh/setup-uv@v7
2626
with:
27-
python-version: "3.13"
27+
version: "0.12.19"
28+
29+
- name: Install system dependencies
30+
run: apt-get update && apt-get install -y --no-install-recommends ca-certificates python3-dev libpq-dev gcc
2831

2932
- name: Install dependencies
30-
run: |
31-
apt-get update && apt-get install -y curl python3.13-dev libpq-dev gcc
32-
python -m pip install --upgrade pip
33-
curl -sSL https://install.python-poetry.org | python3 -
34-
export PATH="/github/home/.local/bin:$PATH"
35-
echo "$HOME/.local/bin" >> $GITHUB_PATH # allow poetry to be used in next step
36-
poetry env use python3.13
37-
poetry install --no-interaction --no-root
33+
run: uv sync --locked --no-python-downloads --python /usr/bin/python3
3834
working-directory: ./src/backend
3935

4036
- name: Run tests
41-
run: |
42-
poetry run pytest ./tests
37+
run: uv run --no-sync pytest ./tests
4338
working-directory: ./src/backend

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ __pycache__
22
.idea
33
/.mypy_cache/
44
**/venv
5+
**/.venv
56
.vscode
67
.devcontainer
7-
build/
8+
build/

‎docs/backend/db/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Migrations are handled by `alembic`, with related code being located [here](../.
1515
### Creating a new migration
1616
```bash
1717
$ cd src/backend/app
18-
$ poetry run alembic revision --autogenerate -m "<migration name>"
18+
$ uv run --no-sync alembic revision --autogenerate -m "<migration name>"
1919
```
2020

2121
### Running migrations
2222
```bash
2323
$ cd src/backend/app
24-
$ poetry run alembic upgrade head
24+
$ uv run --no-sync alembic upgrade head
2525
```
2626

2727
## Updating the database schema

‎src/backend/.python-version‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎src/backend/Dockerfile‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@ FROM chargefw2-base:acc
22

33
USER root
44

5-
ENV POETRY_HOME=/opt/poetry
6-
ENV POETRY_VIRTUALENVS_CREATE=false
7-
ENV PATH="/opt/poetry/bin:$PATH"
5+
COPY --from=ghcr.io/astral-sh/uv:0.12.19 /uv /usr/local/bin/uv
6+
7+
ENV UV_PYTHON_DOWNLOADS=never
8+
ENV UV_PROJECT_ENVIRONMENT=/opt/venv
9+
ENV PATH="/opt/venv/bin:$PATH"
810

911
RUN apt-get update && \
1012
apt-get install -y --no-install-recommends \
1113
ca-certificates \
12-
curl \
1314
gcc \
1415
python3-dev \
1516
libpq-dev && \
1617
apt-get clean && rm -rf /var/lib/apt/lists/*
1718

18-
# Install Poetry
19-
RUN curl -sSL https://install.python-poetry.org | python3 - && \
20-
poetry config virtualenvs.create false
21-
22-
2319
WORKDIR /acc
24-
COPY poetry.lock pyproject.toml ./
25-
RUN poetry install --no-interaction --no-ansi --no-root
20+
COPY uv.lock pyproject.toml ./
21+
RUN uv sync --locked --no-cache --python /usr/bin/python3
2622

2723
COPY ./app /acc/app
2824
COPY ./entrypoint.sh /acc/

‎src/backend/README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ $ cmake .. -DCMAKE_INSTALL_PREFIX=<WHERE-TO-INSTALL> -DPYTHON_MODULE=ON
2626
All required environment variables are located in the [.env file](./app/.env) except `OIDC_CLIENT_ID` and `OIDC_CLIENT_SECRET` (required for Life Science auth, can be ignored for local setup). All used environment variables are described in [docs](../../docs/backend/README.md). How to obtain the abovementioned environment variables is also mentioned [here](../../docs/backend/life-science/README.md).
2727

2828
### Installing dependencies
29-
ACC III uses [Poetry](https://python-poetry.org/) for depencency management.
29+
ACC III uses [uv](https://docs.astral.sh/uv/) for dependency management. Docker and CI use uv 0.12.19.
3030

31-
#### Install Poetry
31+
#### Install uv
3232
```bash
33-
$ curl -sSL https://install.python-poetry.org | python3 -
33+
$ curl -LsSf https://astral.sh/uv/0.12.19/install.sh | sh
3434
```
3535

3636
#### Install project dependencies
37-
*Note:* Poetry will automatically create a virtual environment inside the project before the installation. Configured [here](./poetry.toml).
37+
uv creates a `.venv` in the backend directory and installs the versions recorded in `uv.lock`. Use Python 3.13 or newer, matching the Python version used to build your ChargeFW2 bindings. Docker uses Ubuntu's Python and does not download another interpreter.
3838

3939
```bash
40-
$ poetry install
40+
$ uv sync --locked --no-python-downloads --python python3
4141
```
4242

4343
### Startup
@@ -53,13 +53,13 @@ $ cd app
5353

5454
After the database is ready, we need to run migrations:
5555
```bash
56-
$ poetry run alembic upgrade head
56+
$ uv run --no-sync alembic upgrade head
5757
```
5858

5959
API can now be started just by running the main file:
6060

6161
```bash
62-
$ poetry run gunicorn --workers 4 --worker-class uvicorn.workers.UvicornWorker main:web_app
62+
$ uv run --no-sync gunicorn --workers 4 --worker-class uvicorn.workers.UvicornWorker main:web_app
6363
```
6464

6565
API runs by default on `--bind 127.0.0.1:8000`. Documentation (Swagger) is available on `/docs`. Alternatively you can use Redoc available on `/redoc`.

0 commit comments

Comments
 (0)