Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 12 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
ARG PYTHON_VERSION=3.14.3
ARG PDM_VERSION=2.26.7
ARG COPIER_VERSION=9.14.1
ARG USER_UID=1000

FROM ghcr.io/astral-sh/uv:0.10.8 AS uv
FROM ghcr.io/casey/just:1.49.0 AS just

FROM python:${PYTHON_VERSION}@sha256:ffebef43892dd36262fa2b042eddd3320d5510a21f8440dce0a650a3c124b51d AS base
ARG USER_UID
RUN addgroup --system abc && \
Expand All @@ -28,41 +30,37 @@ RUN copier copy --defaults . /app/hydrated


FROM base AS template-install
ARG PDM_VERSION
ARG USER_UID
RUN pip install --user --no-cache-dir pdm==${PDM_VERSION}
COPY --from=uv /uv /usr/local/bin/uv
COPY --from=just /just /usr/local/bin/just
COPY --from=template-hydrate --chown=abc:abc /app/hydrated /app/
RUN --mount=type=cache,target=/home/abc/.cache/pdm,uid=${USER_UID} \
pdm install
RUN --mount=type=cache,target=/home/abc/.cache/uv,uid=${USER_UID} \
uv sync

FROM template-install AS template-test
RUN pdm test && pdm coverage
RUN just test && just coverage

FROM template-install AS template-lint
RUN pdm lint && pdm format
RUN just lint && just format

FROM template-install AS template-build
RUN pdm build

FROM template-install AS template-pex-build
RUN pdm pex-build
RUN just build

FROM template-install AS template-clean
RUN pdm clean
RUN just clean

FROM template-install AS template-pre-commit
ARG USER_UID
RUN --mount=type=cache,target=/home/abc/.cache/pre-commit/,uid=${USER_UID} \
git init . && \
git add . && \
pdm run pre-commit run --all-files
uv run pre-commit run --all-files

FROM base AS final
# We do not care about the actual results of each stage, we just need to
# artifically create a dependency with them to make Docker build them
COPY --from=template-test --chown=abc:abc /app/pyproject.toml /app
COPY --from=template-lint --chown=abc:abc /app/pyproject.toml /app
COPY --from=template-build --chown=abc:abc /app/pyproject.toml /app
COPY --from=template-pex-build --chown=abc:abc /app/pyproject.toml /app
COPY --from=template-clean --chown=abc:abc /app/pyproject.toml /app
COPY --from=template-pre-commit --chown=abc:abc /app/pyproject.toml /app
5 changes: 2 additions & 3 deletions python/.github/actions/common/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ runs:
- uses: actions/setup-python@v6
with:
python-version: "3.14"
- run: pip install pdm
shell: bash
- run: pdm sync
- uses: astral-sh/setup-uv@v6
- run: uv sync
shell: bash
5 changes: 4 additions & 1 deletion python/.github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ jobs:
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/common
- run: pdm lint
- run: uv run ruff format --check ./src tests/
- run: uv run ruff check ./src tests/
- run: uv run ty check src tests
- run: uv lock --check
2 changes: 1 addition & 1 deletion python/.github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v5
- uses: ./.github/actions/common
- name: Build the Python dist
run: pdm build
run: uv build
- name: Export the Python dist
uses: actions/upload-artifact@v5
with:
Expand Down
18 changes: 0 additions & 18 deletions python/.github/workflows/pex.yml

This file was deleted.

2 changes: 1 addition & 1 deletion python/.github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
steps:
- uses: actions/checkout@v5
- uses: ./.github/actions/common
- run: pdm test
- run: uv run pytest
25 changes: 4 additions & 21 deletions python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,13 @@ repos:
rev: v2.14.0
hooks:
- id: hadolint
- repo: https://github.com/crate-ci/typos
rev: v1.39.0
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.10.8
hooks:
- id: typos
# Disable auto-fix
args: []
- repo: https://github.com/pdm-project/pdm
rev: 2.26.7
hooks:
- id: pdm-lock-check
- repo: https://github.com/pycqa/isort
rev: 7.0.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 25.12.0
hooks:
- id: black
- id: uv-lock
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.14.14
hooks:
- id: ruff-format
- id: ruff
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.408
hooks:
- id: pyright
46 changes: 16 additions & 30 deletions python/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,41 +1,27 @@
ARG PYTHON_VERSION=3.14.3-slim
ARG PDM_VERSION=2.26.7

FROM python:${PYTHON_VERSION}@sha256:fb83750094b46fd6b8adaa80f66e2302ecbe45d513f6cece637a841e1025b4ca as base
FROM ghcr.io/astral-sh/uv:debian-slim AS builder
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev
COPY ./src /app/src
COPY ./README.md /app/README.md
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-dev


FROM debian:bookworm-slim AS final
RUN addgroup --system abc && \
adduser \
--shell /bin/sh \
--ingroup abc \
--disabled-password \
abc
USER abc
ENV PATH="/home/abc/.local/bin:${PATH}"
WORKDIR /app


FROM base as base-pdm
ARG PDM_VERSION
RUN pip install --user --no-cache-dir pdm==${PDM_VERSION}
COPY --chown=abc:abc ./pyproject.toml /app/
COPY --chown=abc:abc ./pdm.lock /app/



FROM base-pdm as package-builder
COPY --chown=abc:abc ./src /app/src
RUN pdm build --no-sdist



FROM base-pdm as dependencies-installer
RUN pdm sync --production --no-self



FROM base as final
COPY --from=builder --chown=abc:abc /app/.venv /app/.venv
ENV PATH="/app/.venv/bin:${PATH}"
COPY --from=dependencies-installer /app/.venv/ /app/.venv/
COPY --from=package-builder /app/dist/{{ package_name }}*.whl /app/
RUN pip --python "$(which python)" install --no-cache-dir --no-deps ./{{ package_name }}*.whl

ENTRYPOINT [ "{{ package_name }}" ]
52 changes: 52 additions & 0 deletions python/Justfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# List available recipes
default:
@just --list

# Format the codebase
format:
uv run ruff format ./src tests/

# Run all linters
lint:
uv run ruff format --check ./src tests/
uv run ruff check ./src tests/
uv run ty check src tests
uv lock --check

# Run the test suite
test:
uv run pytest

# Run tests and generate coverage reports
coverage:
uv run coverage run -m pytest
uv run coverage combine
uv run coverage report
uv run coverage xml
uv run coverage html

# Install dependencies and pre-commit hooks
setup:
uv sync
uv run pre-commit install

# Update pre-commit hooks and uv lock
dev-update:
uv run pre-commit autoupdate
uv lock --upgrade

# Remove build artifacts, caches, and other debris
clean:
uv run pyclean --debris all -- .

# Build a Docker image of the application
docker-build:
docker build -t {{ package_name }}:dev -t {{ package_name }}:$(uv run python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") .

# Update the project to the latest version of the template
template-update:
uv run copier update --skip-answered

# Build distribution packages
build:
uv build
18 changes: 2 additions & 16 deletions python/README.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
![GitHub](https://img.shields.io/github/license/{{ author_username }}/{{ package_name }})
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/{{ package_name }})
![GitHub tag (with filter)](https://img.shields.io/github/v/tag/{{ author_username }}/{{ package_name }})
![PDM](https://img.shields.io/badge/pdm-managed-blueviolet)
![Black](https://img.shields.io/badge/code_style-black-000000)
![Isort](https://img.shields.io/badge/imports-isort-1674b1?labelColor=ef8336)
![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)
![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)
[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
![ty](https://img.shields.io/badge/type_checked-ty-blue)
![Pre Commit](https://img.shields.io/badge/pre_commit-enabled-brightgreen?logo=pre-commit)

{{ short_description }}

- [Usage](#usage)
- [Installation](#installation)
- [With `pipx`](#with-pipx)
- [With a `.pex` executable](#with-a-pex-executable)
- [With `pip`, from a release version](#with-pip-from-a-release-version)
- [With `pip`, from sources](#with-pip-from-sources)
- [Development Quickstart](#development-quickstart)
Expand Down Expand Up @@ -62,17 +59,6 @@ pipx install {{ package_name }}-${VERSION}.tar.gz

where `$VERSION` is the version of the package you downloaded.

### With a `.pex` executable

[`pex`](https://pex.readthedocs.io/en/latest/) is an executable Python
virtualenv format, that can be executed on any machine that provides a suitable
Python interpreter.

To install the CLI provided by `{{ package_name }}`, download the `.pex` files
of the latest release, and copy them somewhere in your `$PATH` (on Linux,
`~/.local/bin` is often a good idea). The executables will then be available in
your shell.

### With `pip`, from a release version

If you do not wish to use the methods above, you can use `pip` instead. The same
Expand Down
2 changes: 2 additions & 0 deletions python/mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
uv = "latest"
2 changes: 0 additions & 2 deletions python/pdm.toml

This file was deleted.

Loading