Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1faa36d
Converted to use uv and hatch over venv and tox
OCopping Apr 4, 2025
4f3290c
Replace tox with tox-uv; Remove hatch.yml
OCopping Apr 9, 2025
e67dd5a
Fix CI when building env
OCopping Apr 10, 2025
738f4fb
Remove hatch run from _test.yml; Bump pre-commit hook versions
OCopping Apr 10, 2025
4aecf11
Fix pytest runner
OCopping Apr 10, 2025
5403646
Update template files for uv
OCopping Apr 10, 2025
be8066a
Tidy pyproject.toml
OCopping Apr 10, 2025
70015df
Revert unintended ci.yml changes
OCopping Apr 14, 2025
7ff792c
Fix actions build, and updates to pyproject.toml
OCopping Apr 23, 2025
5ce9caf
Improvements to template pyproject.toml
OCopping Apr 23, 2025
c71bdfb
Fixes to dev container and tests (but some test cases fail, e.g. runn…
OCopping Apr 30, 2025
50defbc
Revert changes to ci.yml
OCopping May 6, 2025
45c895a
Update pre-commit-config
OCopping May 6, 2025
5bbb867
Revert discussed changes and remove commented out parts
callumforrester May 13, 2025
9e5654e
Move to managing devcontainer environment outside of dockerfile
callumforrester May 16, 2025
99fae79
Add config for using uv
callumforrester May 19, 2025
1933864
Update Dockerfile and devcontainer to use uv
callumforrester May 19, 2025
0822761
Update workflows to use uv
callumforrester May 19, 2025
76d0fe2
Fix Dockerfiles (move UV_VERSION to top of file, and assign new build…
OCopping Jul 1, 2025
063674b
Convert _dist.yml to use uvx over pipx
OCopping Aug 7, 2025
d2dc4c2
Update to use setup-uv@v6
OCopping Aug 7, 2025
b8b3f90
Convert to use dls ubuntu-devcontainer
OCopping Aug 7, 2025
dd1a4ec
fix apt installs in Dockerfile template
gilesknap Aug 8, 2025
581aaba
Add missing if docker jinja tag
OCopping Aug 13, 2025
d55fd3b
Merge remote-tracking branch 'origin/main' into move-to-uv
coretl Sep 18, 2025
cf3f4be
Add in changes from ophyd-async
coretl Sep 18, 2025
3d617c6
Merge remote-tracking branch 'origin/move-to-uv' into move-to-uv
coretl Sep 18, 2025
87224d4
tox-uv tweaks
coretl Sep 22, 2025
328d50a
Disable pep8-naming for the top level
coretl Sep 22, 2025
7073cba
Add docs
coretl Sep 22, 2025
650f006
Update .github/workflows/_tox.yml
coretl Sep 23, 2025
2555a8a
Address review comments
coretl Sep 24, 2025
64dcd6b
Move back to tox TOML format
coretl Sep 24, 2025
f69d899
Don't autoforward ports in devcontainer
coretl Sep 24, 2025
5a6a047
Tidy diff
coretl Sep 24, 2025
07a92bd
Remove pytest version pinning from template pyproject.toml
OCopping Sep 25, 2025
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
40 changes: 31 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}"
"DISPLAY": "${localEnv:DISPLAY}",
// We put venv on a different volume to cache so have to copy
"UV_LINK_MODE": "copy",
// Do the equivalent of "activate" the venv so we don't have to "uv run" everything
"PATH": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin:${containerEnv:PATH}"
},
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python"
"python.defaultInterpreterPath": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": false,
"python.terminal.activateEnvironment": false,
"remote.autoForwardPorts": false
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
Expand All @@ -27,20 +34,35 @@
]
}
},
"features": {
// add in eternal history and other bash features
"ghcr.io/diamondlightsource/devcontainer-features/bash-config:1": {}
},
// Create the config folder for the bash-config feature
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/bash-config",
// Create the config folder for the bash-config feature and uv cache
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config ${localEnv:HOME}/.cache/uv",
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
"--net=host",
// Make sure SELinux does not disable with access to host filesystems like tmp
"--security-opt=label=disable"
],
"mounts": [
// Mount in the user terminal config folder so it can be edited
{
"source": "${localEnv:HOME}/.config/terminal-config",
"target": "/user-terminal-config",
"type": "bind"
},
// Keep a persistent cross container cache for uv
{
"source": "${localEnv:HOME}/.cache/uv",
"target": "/root/.cache/uv",
"type": "bind"
},
// Use a volume mount for the uv venv so it is local to the container
{
"target": "/workspaces/${localWorkspaceFolderBasename}/.venv",
"type": "volume"
}
],
// Mount the parent as /workspaces so we can pip install peers as editable
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// After the container is created, install the python project in editable form
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
"postCreateCommand": "uv sync && uv run pre-commit install --install-hooks"
}
35 changes: 0 additions & 35 deletions .github/actions/install_requirements/action.yml

This file was deleted.

11 changes: 6 additions & 5 deletions .github/workflows/_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ jobs:
# Need this to get version number from last tag
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Build sdist and wheel
run: >
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) &&
pipx run build
uvx --from build pyproject-build

- name: Upload sdist and wheel as artifacts
uses: actions/upload-artifact@v4
Expand All @@ -24,12 +27,10 @@ jobs:
path: dist

- name: Check for packaging errors
run: pipx run twine check --strict dist/*
run: uvx twine check --strict dist/*

- name: Install produced wheel
uses: ./.github/actions/install_requirements
with:
pip-install: dist/*.whl
run: python -m pip install dist/*.whl

- name: Test module --version works using the installed wheel
# If more than one module in src/ replace with module name to test
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
- name: Install system packages
run: sudo apt-get install graphviz

- name: Install python packages
uses: ./.github/actions/install_requirements
- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Build docs
run: tox -e docs
run: uv run --locked tox -e docs

- name: Remove environment.pickle
run: rm build/html/.doctrees/environment.pickle
Expand Down
30 changes: 6 additions & 24 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on:
inputs:
python-version:
type: string
description: The version of python to install
required: true
description: The version of python to install, default is from .python-version file
default: ""
runs-on:
type: string
description: The runner to run this job on
Expand All @@ -16,6 +16,7 @@ on:
env:
# https://github.com/pytest-dev/pytest/issues/2042
PY_IGNORE_IMPORTMISMATCH: "1"
UV_PYTHON: ${{ inputs.python-version }}

jobs:
run:
Expand All @@ -28,30 +29,11 @@ jobs:
# Need this to get version number from last tag
fetch-depth: 0

- if: inputs.python-version == 'dev'
name: Install dev versions of python packages
uses: ./.github/actions/install_requirements

- if: inputs.python-version == 'dev'
name: Write the requirements as an artifact
run: pip freeze --exclude-editable > /tmp/dev-requirements.txt

- if: inputs.python-version == 'dev'
name: Upload dev-requirements.txt
uses: actions/upload-artifact@v4
with:
name: dev-requirements
path: /tmp/dev-requirements.txt

- if: inputs.python-version != 'dev'
name: Install latest versions of python packages
uses: ./.github/actions/install_requirements
with:
python-version: ${{ inputs.python-version }}
pip-install: ".[dev]"
- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run tests
run: tox -e tests
run: uv run --locked tox -e tests

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install python packages
uses: ./.github/actions/install_requirements
- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run tox
run: tox -e ${{ inputs.tox }}
run: uv run --locked tox -e ${{ inputs.tox }}
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
test:
uses: ./.github/workflows/_test.yml
with:
python-version: dev
runs-on: ubuntu-latest
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/periodic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
linkcheck:
uses: ./.github/workflows/_tox.yml
with:
tox: docs build -- -b linkcheck
tox: docs -- -b linkcheck
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ["--maxkb=1000"] # uv.lock is more than 500kB
- id: check-yaml
- id: check-merge-conflict
- id: end-of-file-fixer
Expand All @@ -22,3 +23,10 @@ repos:
entry: ruff format --force-exclude
types: [python]
require_serial: true

- id: uv-sync
name: update uv.lock and venv
pass_filenames: false
language: system
entry: uv sync
files: ^(uv\.lock|pyproject\.toml)$
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
13 changes: 4 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# The devcontainer should use the developer target and run as root with podman
# or docker with user namespaces.
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} AS developer
# The developer stage is used as a devcontainer including dev versions
# of the build dependencies
FROM ghcr.io/diamondlightsource/ubuntu-devcontainer:noble AS developer

# Add any system dependencies for the developer/build environment here
RUN apt-get update && apt-get install -y --no-install-recommends \
graphviz \
&& rm -rf /var/lib/apt/lists/*

# Set up a virtual environment and put it in PATH
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH
&& apt-get dist-clean
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ git init --initial-branch=main /path/to/my-project
copier copy https://github.com/DiamondLightSource/python-copier-template.git $_
```

You can also use it via `pipx run copier` if you have that installed.
You can also use it via `uvx copier` if you have `uv` installed.

<!-- README only content. Anything below this line won't be included in index.md -->

Expand Down
Empty file added __init__.py
Empty file.
23 changes: 23 additions & 0 deletions docs/explanations/decisions/0023-uv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 23. Adopt uv

Date: 2025-09-22

## Status

Accepted

## Context

[`uv`](https://docs.astral.sh/uv/) appears to be gaining a critical mass of adoption, and adopting the project flow would bring some benefits:
- Much faster venv creation times
- A native lockfile implementation
- A single base image that can install multiple pythons
- Which would allow us to make a single devcontainer base with our feature built in, which would speed up the devcontainer creation time

## Decision

We will adopt this flow.

## Consequences

Docs will need to be updated, especially around lockfile support. Commands will need to be updated slightly for the new version of tox. Work on `renovate` will need to follow as `dependabot` does not support the uv lockfile.
8 changes: 4 additions & 4 deletions docs/how-to/build-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ $ firefox build/html/index.html

## Autobuild

You can also run an autobuild process, which will watch your `docs` directory for changes and rebuild whenever it sees changes, reloading any browsers watching the pages:
You can also run an autobuild process, which will watch your `docs` and `src` directories for changes and rebuild whenever it sees changes, reloading any browsers watching the pages:

```
$ tox -e docs autobuild
$ tox -e docs-autobuild
```

You can view the pages at localhost:
Expand All @@ -32,8 +32,8 @@ You can view the pages at localhost:
$ firefox http://localhost:8000
```

If you are making changes to source code too, you can tell it to watch changes in this directory too:
If you want to watch additional directories for changes you can pass these as argument to tox:

```
$ tox -e docs autobuild -- --watch src
$ tox -e docs-autobuild -- --watch tests
```
8 changes: 4 additions & 4 deletions docs/how-to/lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ You can run the above checks on all files with this command:
$ tox -e pre-commit
```

Or you can install a pre-commit hook that will run each time you do a `git commit` on just the files that have changed:
The devcontainer will also install a pre-commit hook that will run each time you do a `git commit` on just the files that have changed.

If you want to commit with a failing pre-commit check then you have to:

```
$ pre-commit install
$ git commit --no-verify
```

It is also possible to [automatically enable pre-commit on cloned repositories](https://pre-commit.com/#automatically-enabling-pre-commit-on-repositories). This will result in pre-commits being enabled on every repo your user clones from now on.

## Fixing issues

The typical workflow is:
Expand Down
Loading