Skip to content

Commit

Permalink
Merge pull request #806 from gchq/feature/uv
Browse files Browse the repository at this point in the history
Migrate to uv
  • Loading branch information
rg936672 authored Oct 18, 2024
2 parents fd334fd + c7c9dcc commit 75a8b41
Show file tree
Hide file tree
Showing 14 changed files with 3,476 additions and 373 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,42 @@ jobs:
percentage: ${{ steps.cov.outputs.percentage }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
- name: Set up base Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
# Note that this is just the version of Python that we use to run `uv` with.
# `uv` manages its own version of Python.
# For speed, we use the same version for both, but in principle these could differ.
python-version: 3.12
- name: Set up uv cache directory location (Linux/Mac)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $GITHUB_ENV
if: runner.os != 'Windows'
- name: Set up uv cache directory location (Windows)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $env:GITHUB_ENV
if: runner.os == 'Windows'
- name: Restore uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}-test
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
- name: Install latest versions of pip and uv
run: python -m pip install --upgrade pip uv
- name: Install test dependencies
run: pip install -e .[test]
run: uv sync --extra test --no-dev --locked
- name: Debug - uv pip freeze
run: uv pip freeze
- name: Assess coverage of unit tests
run: pytest tests/unit --cov
run: uv run pytest tests/unit --cov
- name: Extract total coverage percentage
id: cov
run: echo "percentage=$( coverage report --format=total )" >> $GITHUB_OUTPUT
- name: Minimize UV cache
run: uv cache prune --ci
if: always()
coverage-badge:
name: Update coverage badge
if: github.event_name == 'push'
Expand Down
62 changes: 31 additions & 31 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ on:

jobs:
build:
name: Build documentation with latest dependencies
name: Build documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
- name: Set up base Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install test dependencies
run: pip install -e .[doc]
- name: Build documentation
run: |
python -m sphinx -b html -aE -n -W --keep-going documentation/source documentation/build
- name: Check external links
run: |
python -m sphinx -b linkcheck documentation/source documentation/build
build-pinned:
name: Build documentation with pinned package versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
# Note that this is just the version of Python that we use to run `uv` with.
# `uv` manages its own version of Python.
# For speed, we use the same version for both, but in principle these could differ.
python-version: 3.12
- name: Set up uv cache directory location (Linux/Mac)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $GITHUB_ENV
if: runner.os != 'Windows'
- name: Set up uv cache directory location (Windows)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $env:GITHUB_ENV
if: runner.os == 'Windows'
- name: Restore uv cache
uses: actions/cache@v4
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements-doc.txt
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install test dependencies
run: pip install --no-dependencies -r requirements-doc.txt
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}-test
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
- name: Install latest versions of pip and uv
run: python -m pip install --upgrade pip uv
- name: Install documentation dependencies
run: uv sync --extra doc --no-dev --locked
- name: Debug - uv pip freeze
run: uv pip freeze
- name: Build documentation
run: |
python -m sphinx -b html -aE -n -W --keep-going documentation/source documentation/build
uv run -m sphinx -b html -aE -n -W --keep-going documentation/source documentation/build
- name: Check external links
run: |
python -m sphinx -b linkcheck documentation/source documentation/build
uv run -m sphinx -b linkcheck documentation/source documentation/build
- name: Minimize UV cache
run: uv cache prune --ci
if: always()
41 changes: 31 additions & 10 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@ jobs:
gist_id: 3707a122b3697109068a3e55487de4fc
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
- name: Set up base Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install package and dependencies
run: pip install -e .
# Note that this is just the version of Python that we use to run `uv` with.
# `uv` manages its own version of Python.
# For speed, we use the same version for both, but in principle these could differ.
python-version: 3.12
- name: Set up uv cache directory location (Linux/Mac)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $GITHUB_ENV
if: runner.os != 'Windows'
- name: Set up uv cache directory location (Windows)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $env:GITHUB_ENV
if: runner.os == 'Windows'
- name: Restore uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}-none
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
- name: Install latest versions of pip and uv
run: python -m pip install --upgrade pip uv
- name: Install package dependencies
run: uv sync --no-dev --locked
- name: Debug - uv pip freeze
run: uv pip freeze
- name: Assess performance
run: python tests/performance/run.py --output-file $RUNNER_TEMP/performance.json
run: uv run tests/performance/run.py --output-file $RUNNER_TEMP/performance.json
- name: Download historic performance data
if: github.event_name == 'pull_request'
run: gh gist clone ${{ env.gist_id }} $RUNNER_TEMP/historic
Expand All @@ -39,7 +57,7 @@ jobs:
# save the commit subject to a file in case it contains any shell
# special characters
git log -1 --pretty=%s > $RUNNER_TEMP/commit_subject.txt
python tests/performance/compare.py \
uv run tests/performance/compare.py \
$RUNNER_TEMP/performance.json \
$RUNNER_TEMP/historic \
--commit-short-hash $(git log -1 --pretty=%h) \
Expand Down Expand Up @@ -67,3 +85,6 @@ jobs:
run: |
OUT_NAME="performance-$(date --utc +%Y-%m-%d--%H-%M-%S)--$GITHUB_SHA--v1.json"
gh gist edit ${{ env.gist_id }} -a $OUT_NAME $RUNNER_TEMP/performance.json
- name: Minimize UV cache
run: uv cache prune --ci
if: always()
37 changes: 29 additions & 8 deletions .github/workflows/pre_commit_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,38 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
- name: Set up base Python
uses: actions/setup-python@v5
with:
# Note that this is just the version of Python that we use to run `uv` with.
# `uv` manages its own version of Python.
# For speed, we use the same version for both, but in principle these could differ.
python-version: 3.12
cache: pip
cache-dependency-path: pyproject.toml
- name: Upgrade Pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: pip install -e .[dev]
- name: Set up uv cache directory location (Linux/Mac)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $GITHUB_ENV
if: runner.os != 'Windows'
- name: Set up uv cache directory location (Windows)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $env:GITHUB_ENV
if: runner.os == 'Windows'
- name: Restore uv cache
uses: actions/cache@v4
with:
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}-dev
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
- name: Install latest versions of pip and uv
run: python -m pip install --upgrade pip uv
- name: Install development dependencies
run: uv sync --dev --locked
- name: Debug - uv pip freeze
run: uv pip freeze
- name: Remove fail_fast from Pre-commit config
run: sed -e "/fail_fast/d" .pre-commit-config.yaml > /tmp/.pre-commit-config-ci.yaml
- name: Run Pre-commit checks
run: SKIP=no-commit-to-branch pre-commit run --all-files --show-diff-on-failure --config /tmp/.pre-commit-config-ci.yaml
run: SKIP=no-commit-to-branch uv run pre-commit run --all-files --show-diff-on-failure --config /tmp/.pre-commit-config-ci.yaml
- name: Minimize UV cache
run: uv cache prune --ci
if: always()
65 changes: 31 additions & 34 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,44 @@ jobs:
include:
- { python-version: "3.9", os: "macos-13" }
runs-on: ${{ matrix.os }}
env:
# Set the Python version that `uv` will use for its virtual environment.
UV_PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
- name: Set up base Python
uses: actions/setup-python@v5
with:
# Note that this is just the version of Python that we use to run `uv` with.
# `uv` manages its own version of Python.
# For speed, we use the same version for both, but in principle these could differ.
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: pyproject.toml
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install test dependencies
run: pip install -e .[test]
- name: Test with pytest
run: pytest --ignore=tests/integration
# Integration tests are slow, so only run if all other tests pass.
- name: Test integration tests
run: pytest tests/integration
tests-pinned:
name: Run tests with pinned package versions
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
- name: Set up uv cache directory location (Linux/Mac)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $GITHUB_ENV
if: runner.os != 'Windows'
- name: Set up uv cache directory location (Windows)
run: echo "UV_CACHE_DIR=${{ runner.temp }}/.uv-cache" >> $env:GITHUB_ENV
if: runner.os == 'Windows'
- name: Restore uv cache
uses: actions/cache@v4
with:
python-version: "3.12"
cache: pip
cache-dependency-path: requirements-test.txt
- name: Upgrade pip
run: python -m pip install --upgrade pip
path: ${{ env.UV_CACHE_DIR }}
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}-test
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}-${{ matrix.python-version }}
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
- name: Install latest versions of pip and uv
run: python -m pip install --upgrade pip uv
- name: Install test dependencies
run: pip install --no-dependencies -r requirements-test.txt
run: uv sync --extra test --no-dev --locked
- name: Debug - uv pip freeze
run: uv pip freeze
- name: Test with pytest
run: pytest --ignore=tests/integration
run: uv run pytest --ignore=tests/integration
# Integration tests are slow, so only run if all other tests pass.
- name: Test integration tests
run: pytest tests/integration
run: uv run pytest tests/integration
- name: Minimize UV cache
run: uv cache prune --ci
if: always()
Loading

0 comments on commit 75a8b41

Please sign in to comment.