Skip to content

Commit 3150434

Browse files
authored
Move from flit/pip to uv (#970)
* Use uv with flit-core backend * Run pre-commit CI through uv * Change docs and publishing to uv * Document uv * Update codspeed workflow, cleanup comments * Move development setup to the top of contribution docs * Remove act readme * Install curl/git for codspeed workflow, cache apt dependencies, use python image * Add pre-commit caching, skip mypy in pre-commit as it's run separately, remove restore-keys to avoid stale data
1 parent 16e95b7 commit 3150434

13 files changed

+3278
-239
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "pip" # See documentation for possible values
8+
- package-ecosystem: "uv" # See documentation for possible values
99
directory: "/" # Location of package manifests
1010
schedule:
1111
interval: "weekly"

.github/workflows/README.md

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is used by:
2+
# 1. the cache action to calculate a hash for the cache key
3+
# 2. apt-get install command which filters out any lines starting with a #
4+
curl
5+
git

.github/workflows/gh-pages.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@ on:
33
push:
44
branches:
55
- main
6+
7+
env:
8+
UV_LOCKED: true # Assert that the `uv.lock` will remain unchanged
9+
610
jobs:
711
deploy:
812
runs-on: ubuntu-latest
913
steps:
1014
- uses: actions/checkout@v3
11-
- uses: actions/setup-python@v2
15+
16+
- name: Install uv and set the python version
17+
uses: astral-sh/setup-uv@v5
1218
with:
13-
python-version: 3.x
19+
# It is considered best practice to pin to a specific uv version.
20+
version: "0.7.13"
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install the project
24+
# --no-dev: exclude group 'dev' from [dependency-groups]
25+
# --group docs: include group 'dev' from [dependency-groups]
26+
run: uv sync --no-dev --group docs
1427

15-
- run: pip install flit
16-
- run: flit install --only-deps --deps develop
17-
- run: mkdocs gh-deploy --force
28+
- name: Build and publish docs
29+
run: uv run mkdocs gh-deploy --force

.github/workflows/publish-package.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,31 @@ on:
44
release:
55
types: [created]
66

7+
env:
8+
UV_LOCKED: true # Assert that the `uv.lock` will remain unchanged
9+
710
jobs:
811
deploy:
912
runs-on: ubuntu-latest
1013
steps:
1114
- uses: actions/checkout@v3
12-
- name: Set up Python
13-
uses: actions/setup-python@v2
15+
16+
- name: Install uv and set the python version
17+
uses: astral-sh/setup-uv@v5
1418
with:
15-
python-version: '3.x'
16-
- name: Install dependencies
17-
run: |
18-
python -m pip install --upgrade pip
19-
pip install flit
20-
- name: Build and publish
19+
# It is considered best practice to pin to a specific uv version.
20+
version: "0.7.13"
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Build package
24+
run: uv build
25+
26+
- name: Publish package
27+
run: uv publish
2128
env:
22-
FLIT_USERNAME: ${{ secrets.FLIT_USERNAME }}
23-
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
24-
run: |
25-
flit publish
29+
UV_PUBLISH_USERNAME: ${{ secrets.FLIT_USERNAME }}
30+
UV_PUBLISH_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
31+
32+
# TODO Migrate to trusted publishing with OIDC https://docs.pypi.org/trusted-publishers/
33+
# - name: Publish package distributions to PyPI
34+
# uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/run-codspeed-tests.yml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [ "main" ]
88

9+
env:
10+
UV_LOCKED: true # Assert that the `uv.lock` will remain unchanged
11+
912
jobs:
1013
codspeed:
1114
name: Run benchmarks
@@ -36,20 +39,30 @@ jobs:
3639
--health-timeout 5s
3740
--health-retries 5
3841
steps:
39-
# Downloads a copy of the code in your repository before running CI tests
4042
- name: Check out repository code
4143
uses: actions/checkout@v3
4244

43-
- name: Install dependencies
45+
- name: Install uv
46+
uses: astral-sh/setup-uv@v5
47+
with:
48+
# It is considered best practice to pin to a specific uv version.
49+
version: "0.7.13"
50+
51+
- name: Install the project
52+
# --all-extras: [project.optional-dependencies]
53+
# --dev: group 'dev' from [dependency-groups]
54+
run: uv sync --all-extras --dev
55+
56+
- name: Cache APT packages
57+
uses: actions/cache@v4
58+
with:
59+
path: /var/cache/apt/archives/
60+
key: ${{ runner.os }}-apt-pkgs-${{ hashFiles('**/apt-packages-run-codspeed-tests.txt') }}
61+
62+
- name: Install OS dependencies
4463
run: |
45-
apt update
46-
apt install curl git build-essential libpq-dev libffi-dev -y
47-
python -m pip install --upgrade pip
48-
pip install flit
49-
flit install --deps develop --symlink
50-
echo "GIT_COMMIT_HASH=\"test\"" > orchestrator/version.py
51-
env:
52-
FLIT_ROOT_INSTALL: 1
64+
apt-get update
65+
apt-get install $(grep -vE '^\s*#' .github/workflows/files/apt-packages-run-codspeed-tests.txt | awk NF | tr '\n' ' ') -y
5366
5467
# Prevent error "repository path is not owned by the current user"
5568
- name: Fix git owner
@@ -61,7 +74,7 @@ jobs:
6174

6275
- uses: CodSpeedHQ/action@v3
6376
with:
64-
run: CACHE_URI=redis://redis DATABASE_URI=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB pytest test/unit_tests --codspeed
77+
run: CACHE_URI=redis://redis DATABASE_URI=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB uv run pytest test/unit_tests --codspeed
6578
token: ${{ secrets.CODSPEED_TOKEN }}
6679
env:
6780
POSTGRES_DB: orchestrator-core-test

.github/workflows/run-linting-tests.yml

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
workflow_call:
1010
pull_request:
1111

12+
env:
13+
UV_LOCKED: true # Assert that the `uv.lock` will remain unchanged
14+
1215
jobs:
1316
build:
1417
name: Linting Tests
@@ -20,17 +23,29 @@ jobs:
2023

2124
steps:
2225
- uses: actions/checkout@v3
23-
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v2
26+
27+
- name: Install uv and set the python version
28+
uses: astral-sh/setup-uv@v5
2529
with:
30+
# It is considered best practice to pin to a specific uv version.
31+
version: "0.7.13"
2632
python-version: ${{ matrix.python-version }}
27-
- name: Install dependencies
28-
run: |
29-
python -m pip install --upgrade pip
30-
pip install flit
31-
flit install --deps develop --symlink
33+
34+
- name: Install the project
35+
# --all-extras: [project.optional-dependencies]
36+
# --dev: group 'dev' from [dependency-groups]
37+
run: uv sync --all-extras --dev
38+
3239
- name: Check with mypy
33-
run: |
34-
mypy .
40+
run: uv run mypy .
41+
42+
- name: Cache pre-commit hooks and environments
43+
uses: actions/cache@v4
44+
with:
45+
path: ~/.cache/pre-commit
46+
key: ${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
47+
3548
- name: Run remaining pre-commit hooks
36-
uses: pre-commit/[email protected]
49+
run: uv run pre-commit run --all-files
50+
env:
51+
SKIP: mypy

.github/workflows/run-unit-tests.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
workflow_call:
66
pull_request:
77

8+
env:
9+
UV_LOCKED: true # Assert that the `uv.lock` will remain unchanged
10+
811
jobs:
912
container_job:
1013
name: Unit tests Python (${{ matrix.python-version }}) Postgres (${{ matrix.postgres-version }})
@@ -14,7 +17,7 @@ jobs:
1417
python-version: ['3.11', '3.12', '3.13']
1518
postgres-version: ['15', '16', '17']
1619
fail-fast: false
17-
container: python:${{ matrix.python-version }}-slim
20+
container: ubuntu:latest
1821
services:
1922
postgres:
2023
image: postgres:${{ matrix.postgres-version }}-alpine
@@ -38,28 +41,30 @@ jobs:
3841
--health-timeout 5s
3942
--health-retries 5
4043
steps:
41-
# Downloads a copy of the code in your repository before running CI tests
4244
- name: Check out repository code
4345
uses: actions/checkout@v3
4446

45-
- name: Install dependencies
46-
run: |
47-
apt update
48-
apt install curl git build-essential libpq-dev libffi-dev -y
49-
python -m pip install --upgrade pip
50-
pip install flit
51-
flit install --deps develop --symlink
52-
echo "GIT_COMMIT_HASH=\"test\"" > orchestrator/version.py
53-
env:
54-
FLIT_ROOT_INSTALL: 1
55-
- name: Run Unit tests
56-
run: CACHE_URI=redis://redis DATABASE_URI=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB pytest --cov-branch --cov=orchestrator --cov-report=xml --ignore=test --ignore=orchestrator/devtools --ignore=examples --ignore=docs --ignore=orchestrator/vendor
47+
- name: Install uv and set the python version
48+
uses: astral-sh/setup-uv@v5
49+
with:
50+
# It is considered best practice to pin to a specific uv version.
51+
version: "0.7.13"
52+
python-version: ${{ matrix.python-version }}
53+
54+
- name: Install the project
55+
# --all-extras: [project.optional-dependencies]
56+
# --dev: group 'dev' from [dependency-groups]
57+
run: uv sync --all-extras --dev
58+
59+
- name: Run tests
60+
run: CACHE_URI=redis://redis DATABASE_URI=postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB uv run pytest --cov-branch --cov=orchestrator --cov-report=xml --ignore=test --ignore=orchestrator/devtools --ignore=examples --ignore=docs
5761
env:
5862
POSTGRES_DB: orchestrator-core-test
5963
POSTGRES_USER: nwa
6064
POSTGRES_PASSWORD: nwa
6165
POSTGRES_HOST: postgres
6266
ENVIRONMENT: TESTING
67+
6368
- name: "Upload coverage to Codecov"
6469
uses: codecov/codecov-action@v3
6570
with:

0 commit comments

Comments
 (0)