Skip to content

Commit 73a5942

Browse files
authored
Port from Poetry to uv (#255)
1 parent 6743410 commit 73a5942

11 files changed

Lines changed: 1310 additions & 1759 deletions

File tree

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
!src
66
!LICENSE.txt
77
!pyproject.toml
8-
!poetry.lock
8+
!uv.lock
99
!README.md
1010

1111
# Filter unwanted files from included folders.

.github/workflows/pages.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ on:
88
branches: [main]
99

1010
env:
11-
POETRY_VERSION: "2.1.1"
11+
UV_VERSION: "2.1.1"
1212
PYTHON_VERSION: "3.11"
1313

1414
jobs:
1515
deploy:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v4
19-
- name: Install poetry
20-
run: pipx install poetry==${POETRY_VERSION}
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v5
21+
with:
22+
version: ${{ env.UV_VERSION }}
2123
- uses: actions/setup-python@v5
2224
with:
2325
python-version: ${{ env.PYTHON_VERSION }}
24-
cache: poetry
25-
- name: Install Nox and doc dependencies
26-
run: poetry sync --only nox,docs
26+
- name: Install dependencies
27+
run: uv sync --locked
2728
- name: Publish Docs
28-
run: poetry run nox -s docs_github_pages
29+
run: uv run nox -s docs_github_pages

.github/workflows/python.yml

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: python
33
on: [push, pull_request]
44

55
env:
6-
POETRY_VERSION: "2.1.1"
6+
UV_VERSION: "0.6.9"
77
PYTHON_VERSION: "3.11"
88

99
jobs:
@@ -14,49 +14,50 @@ jobs:
1414
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
1515
steps:
1616
- uses: actions/checkout@v4
17-
- name: Install poetry
18-
run: pipx install poetry==${POETRY_VERSION}
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v5
19+
# Caching is enabled by default for GitHub-hosted runners:
20+
# https://github.com/astral-sh/setup-uv?tab=readme-ov-file#enable-caching
21+
with:
22+
version: ${{ env.UV_VERSION }}
1923
- name: Set up Python ${{ matrix.python-version }}
2024
uses: actions/setup-python@v5
2125
with:
2226
python-version: ${{ matrix.python-version }}
23-
# https://github.com/actions/setup-python#caching-packages-dependencies
24-
cache: poetry
2527
- name: Install Nox
26-
run: poetry sync --only nox
28+
run: uv sync --locked --only-group nox
2729
- name: Test with Nox
28-
run: poetry run nox -s test-${{ matrix.python-version }}
30+
run: uv run nox -s test-${{ matrix.python-version }}
2931
quality:
3032
runs-on: ubuntu-24.04
3133
strategy:
3234
matrix:
33-
job:
34-
- { nox-session: lint, poetry-groups: "lint" }
35-
# type_check needs main and test dependencies for inline type annotations.
36-
- { nox-session: type_check, poetry-groups: "type_check,main,test" }
37-
- { nox-session: docs, poetry-groups: "docs" }
35+
nox-session: ["lint", "type_check", "docs"]
3836
steps:
3937
- uses: actions/checkout@v4
40-
- name: Install poetry
41-
run: pipx install poetry==${POETRY_VERSION}
38+
- name: Install uv
39+
uses: astral-sh/setup-uv@v5
40+
with:
41+
version: ${{ env.UV_VERSION }}
4242
- name: Set up Python
4343
uses: actions/setup-python@v5
4444
with:
4545
python-version: ${{ env.PYTHON_VERSION }}
46-
cache: poetry
47-
- name: Install Nox and group dependencies
48-
run: poetry sync --only nox,${{ matrix.job.poetry-groups }}
46+
- name: Install dependencies
47+
run: uv sync --locked
4948
- name: Test with Nox
50-
run: poetry run nox -s ${{ matrix.job.nox-session }}
51-
poetry-check:
49+
run: uv run nox -s ${{ matrix.nox-session }}
50+
lock-check:
5251
runs-on: ubuntu-24.04
5352
steps:
5453
- uses: actions/checkout@v4
55-
- name: Install poetry
56-
run: pipx install poetry==${POETRY_VERSION}
54+
- name: Install uv
55+
uses: astral-sh/setup-uv@v5
56+
with:
57+
version: ${{ env.UV_VERSION }}
5758
- name: Set up Python
5859
uses: actions/setup-python@v5
5960
with:
6061
python-version: ${{ env.PYTHON_VERSION }}
61-
- name: Validate Poetry Configuration and Lockfile Freshness
62-
run: poetry check --lock --strict
62+
- name: Validate Lockfile Up-to-date
63+
run: uv lock --check

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

Dockerfile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
# - Most Python packages that require C code are tested against GLIBC, so there could be
88
# subtle errors when using MUSL.
99
# - These Python packages usually only provide binary wheels for GLIBC, so the packages
10-
# will need to be recompiled fully within the Docker images, increasing build times.
10+
# will need to be recompiled fully within the container images, increasing build times.
1111
FROM python:3.11-slim-bookworm AS python_builder
1212

13-
# Pin Poetry to a specific version to make Docker builds reproducible.
14-
ENV POETRY_VERSION=2.1.1
13+
# Pin uv to a specific version to make container builds reproducible.
14+
ENV UV_VERSION=0.6.9
1515

1616
# Set ENV variables that make Python more friendly to running inside a container.
1717
ENV PYTHONDONTWRITEBYTECODE=1
1818
ENV PYTHONBUFFERED=1
1919

2020
# By default, pip caches copies of downloaded packages from PyPI. These are not useful within
21-
# a Docker image, so disable this to reduce the size of images.
21+
# a contain image, so disable this to reduce the size of images.
2222
ENV PIP_NO_CACHE_DIR=1
2323
ENV WORKDIR=/src
2424

@@ -30,9 +30,8 @@ WORKDIR ${WORKDIR}
3030
# gcc \
3131
# && rm -rf /var/lib/apt/lists/*
3232

33-
# Install Poetry into the global environment to isolate it from the venv. This prevents Poetry
34-
# from uninstalling parts of itself.
35-
RUN pip install "poetry==${POETRY_VERSION}"
33+
# Install uv into the global environment to isolate it from the venv it creates.
34+
RUN pip install "uv==${UV_VERSION}"
3635

3736
# Pre-download/compile wheel dependencies into a virtual environment.
3837
# Doing this in a multi-stage build allows omitting compile dependencies from the final image.
@@ -43,17 +42,17 @@ RUN python -m venv ${VIRTUAL_ENV}
4342
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
4443

4544
# Copy in project dependency specification.
46-
COPY pyproject.toml poetry.lock ./
45+
COPY pyproject.toml uv.lock ./
4746

48-
# Don't install the package itself with Poetry because it will install it as an editable install.
49-
RUN poetry sync --only main --no-root
47+
# Don't install the package itself with uv because it will install it as an editable install.
48+
RUN uv sync --locked --no-default-groups --no-install-project
5049

5150
# Copy in source files.
5251
COPY README.md ./
5352
COPY src src
5453

5554
# Manually build/install the package.
56-
RUN poetry build && \
55+
RUN uv build && \
5756
pip install dist/*.whl
5857

5958
## Final Image
@@ -73,7 +72,7 @@ RUN mkdir -p ${HOME}
7372

7473
# Create the user so the program doesn't run as root. This increases security of the container.
7574
RUN groupadd -r user && \
76-
useradd -r -g user -d ${HOME} -s /sbin/nologin -c "Docker image user" user
75+
useradd -r -g user -d ${HOME} -s /sbin/nologin -c "Container image user" user
7776

7877
# Setup application install directory.
7978
RUN mkdir ${APP_HOME}

0 commit comments

Comments
 (0)