Skip to content

Commit 8071686

Browse files
committed
chore: switch from poetry to uv
1 parent 8efe3fd commit 8071686

File tree

8 files changed

+417
-663
lines changed

8 files changed

+417
-663
lines changed

.github/workflows/ci.yml

+20-18
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ on:
55
branches:
66
- main
77

8+
env:
9+
UV_VERSION: "0.4.0"
10+
811
concurrency:
912
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
1013
cancel-in-progress: true
1114

1215
jobs:
1316
build:
14-
runs-on: ubuntu-22.04
17+
env:
18+
UV_CACHE_DIR: /tmp/.uv-cache
19+
runs-on: ubuntu-24.04
1520
steps:
1621
- name: Checkout source code
1722
uses: actions/checkout@v4
@@ -20,30 +25,27 @@ jobs:
2025
uses: actions/setup-python@v5
2126
with:
2227
python-version-file: ".python-version"
23-
- name: Install Poetry
24-
uses: snok/[email protected]
25-
with:
26-
version: 1.8.3
27-
virtualenvs-create: true
28-
virtualenvs-in-project: true
29-
- name: Load cached venv
30-
id: cached-poetry-dependencies
28+
- name: Set up uv
29+
run: curl -LsSf https://astral.sh/uv/${{ env.UV_VERSION }}/install.sh | sh
30+
- name: Restore uv cache
3131
uses: actions/cache@v4
3232
with:
33-
path: .venv
34-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
33+
path: /tmp/.uv-cache
34+
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
35+
restore-keys: |
36+
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
37+
uv-${{ runner.os }}
3538
- name: Install dependencies
36-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
37-
run: poetry install --no-interaction --no-root
38-
- name: Install library
39-
run: poetry install --no-interaction
39+
run: uv sync --all-extras --dev --frozen
4040
- name: Run application
41-
run: poetry run myapplication
41+
run: uv run myapplication
4242
- name: Test with pytest
43-
run: poetry run pytest tests --cov=src
43+
run: uv run pytest tests --cov=src
44+
- name: Minimize uv cache
45+
run: uv cache prune --ci
4446

4547
build-image:
46-
runs-on: ubuntu-22.04
48+
runs-on: ubuntu-24.04
4749

4850
steps:
4951
- name: Checkout source code

.github/workflows/codeql.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
analyze:
1111
name: Analyze
12-
runs-on: ubuntu-22.04
12+
runs-on: ubuntu-24.04
1313
permissions:
1414
actions: read
1515
contents: read

.github/workflows/pr.yml

+18-20
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ concurrency:
1111

1212
jobs:
1313
build:
14-
runs-on: ubuntu-22.04
14+
env:
15+
UV_CACHE_DIR: /tmp/.uv-cache
16+
runs-on: ubuntu-24.04
1517
strategy:
1618
matrix:
1719
python-version: ["3.12.0", "3.12.x"]
18-
poetry-version:
19-
["1.2.2", "1.3.2", "1.4.2", "1.5.1", "1.6.1", "1.7.1", "1.8.3"]
20+
uv-version: ["0.3.5", "0.4.0"]
2021
fail-fast: false
2122

2223
steps:
@@ -28,30 +29,27 @@ jobs:
2829
with:
2930
python-version: ${{ matrix.python-version }}
3031
architecture: x64
31-
- name: Install Poetry
32-
uses: snok/[email protected]
33-
with:
34-
version: ${{ matrix.poetry-version }}
35-
virtualenvs-create: true
36-
virtualenvs-in-project: true
37-
- name: Load cached venv
38-
id: cached-poetry-dependencies
32+
- name: Set up uv
33+
run: curl -LsSf https://astral.sh/uv/${{ matrix.uv-version }}/install.sh | sh
34+
- name: Restore uv cache
3935
uses: actions/cache@v4
4036
with:
41-
path: .venv
42-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ matrix.poetry-version }}-${{ hashFiles('**/poetry.lock') }}
37+
path: /tmp/.uv-cache
38+
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
39+
restore-keys: |
40+
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
41+
uv-${{ runner.os }}
4342
- name: Install dependencies
44-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
45-
run: poetry install --no-interaction --no-root
46-
- name: Install library
47-
run: poetry install --no-interaction
43+
run: uv sync --all-extras --dev --frozen
4844
- name: Run application
49-
run: poetry run myapplication
45+
run: uv run myapplication
5046
- name: Test with pytest
51-
run: poetry run pytest tests --cov=src
47+
run: uv run pytest tests --cov=src
48+
- name: Minimize uv cache
49+
run: uv cache prune --ci
5250

5351
build-image:
54-
runs-on: ubuntu-22.04
52+
runs-on: ubuntu-24.04
5553

5654
steps:
5755
- name: Checkout source code

Dockerfile

+8-17
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,33 @@ FROM python:3.12.5-slim-bookworm as python-base
22

33
ENV PYTHONUNBUFFERED=1 \
44
PYTHONDONTWRITEBYTECODE=1 \
5-
POETRY_HOME="/opt/poetry" \
6-
POETRY_VIRTUALENVS_IN_PROJECT=true \
7-
POETRY_NO_INTERACTION=1 \
85
PYSETUP_PATH="/opt/pysetup" \
96
VENV_PATH="/opt/pysetup/.venv"
107

11-
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
8+
ENV PATH="$VENV_PATH/bin:$PATH"
129

1310
FROM python-base as builder-base
14-
RUN apt-get update \
15-
&& apt-get install --no-install-recommends -y \
16-
curl \
17-
build-essential
1811

19-
ENV POETRY_VERSION=1.8.3
20-
RUN curl -sSL https://install.python-poetry.org | python
12+
COPY --from=ghcr.io/astral-sh/uv:0.4.0 /uv /bin/uv
2113

2214
WORKDIR $PYSETUP_PATH
23-
COPY ./poetry.lock ./pyproject.toml ./
24-
RUN poetry install --no-root --no-dev
25-
26-
FROM builder-base as development
27-
28-
RUN poetry install --no-root
2915

3016
COPY . .
3117

32-
RUN poetry install
18+
RUN uv sync --frozen
19+
20+
FROM builder-base as development
3321

3422
CMD ["python","-m", "myapplication.main"]
3523

3624
FROM python-base as production
3725

3826
COPY --from=builder-base $VENV_PATH $VENV_PATH
27+
3928
WORKDIR $PYSETUP_PATH
29+
4030
COPY ./src/ ./
31+
4132
USER 10000
4233

4334
CMD ["python","-m", "myapplication.main"]

README.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
- [Python](https://www.python.org/downloads/) **>=3.12 <3.13** (_tested with 3.12.5_)
3535
- [pre-commit](https://pre-commit.com/#install)
36-
- [poetry](https://python-poetry.org/docs/#installation) **>=1.2.2 <1.9** (_tested with 1.8.3_)
36+
- [uv](https://python-poetry.org/docs/#installation) **>=0.3.3** (_tested with 0.4.0_)
3737
- [docker](https://docs.docker.com/get-docker/) (_optional_)
3838

3939
---
@@ -68,16 +68,15 @@
6868

6969
## What's in the box ?
7070

71-
### Poetry
71+
### uv
7272

73-
[Poetry](https://python-poetry.org/) is a tool for dependency management and packaging in Python. It allows you to
74-
declare the libraries your project depends on and it will manage (install/update) them for you.
73+
[uv](https://github.com/astral-sh/uv) is an extremely fast Python package and project manager, written in Rust.
7574

7675
**pyproject.toml file** ([`pyproject.toml`](pyproject.toml)): orchestrate your project and its dependencies
77-
**poetry.lock file** ([`poetry.lock`](poetry.lock)): ensure that the package versions are consistent for everyone
76+
**uv.lock file** ([`uv.lock`](uv.lock)): ensure that the package versions are consistent for everyone
7877
working on your project
7978

80-
For more configuration options and details, see the [configuration docs](https://python-poetry.org/docs/).
79+
For more configuration options and details, see the [configuration docs](https://docs.astral.sh/uv/).
8180

8281
### pre-commit
8382

@@ -90,11 +89,11 @@ For more configuration options and details, see the [configuration docs](https:/
9089

9190
### ruff
9291

93-
[ruff](https://github.com/charliermarsh/ruff) is an extremely fast Python linter, written in Rust.
92+
[ruff](https://github.com/astral-sh/ruff) is an extremely fast Python linter, written in Rust.
9493

9594
Rules are defined in the [`pyproject.toml`](pyproject.toml).
9695

97-
For more configuration options and details, see the [configuration docs](https://github.com/charliermarsh/ruff#configuration).
96+
For more configuration options and details, see the [configuration docs](https://github.com/astral-sh/ruff#configuration).
9897

9998
### mypy
10099

@@ -129,7 +128,7 @@ We are using [pytest](https://docs.pytest.org/) & [pytest-cov](https://github.co
129128
To run tests:
130129

131130
```bash
132-
poetry run pytest tests
131+
uv run pytest tests
133132
```
134133

135134
<details>
@@ -147,7 +146,7 @@ tests/test_myapplication.py::test_hello_world PASSED
147146
To run tests with coverage:
148147

149148
```bash
150-
poetry run pytest tests --cov=src
149+
uv run pytest tests --cov=src
151150
```
152151

153152
<details>

0 commit comments

Comments
 (0)