Skip to content

Commit

Permalink
use uv instead of pdm (#83)
Browse files Browse the repository at this point in the history
      * ci: add uv based workflows

* ci: use env namespace

* chore: add uv based Makefile

* ci: remove unused actions

* ci(test): fix python-version

* ci: bump uv to 0.4.18

* ci: do not use hashes from workflow file

* ci: set python 3.9 as minimum version

* ci: also test for python 3.13

* ci: also test for python 3.14-dev

* ci(deps): bump uv to 0.5.1

* ci: use setup-uv action

* ci: bump codecov-action to v5

* chore: update uv export

* chore: fix typo

* chore: fix uv export

* chore: do not emit project

* ci: only cache uv, not .venv

* ci: add --all-packages to uv sync calls

* chore: use uv instead of pdm

* chore: remove old Makefile and CI

* chore: migrate pre-commit-config

* chore: add --all-packages to uv sync calls

* chore: adapt Makefile to project

* ci: adapt CI workflows to project

* ci: bump codecov-action to v5

* ci: use make install-dev where possible

* style: sort some imports
  • Loading branch information
kod-kristoff authored Nov 21, 2024
1 parent 7c6a916 commit aa9c397
Show file tree
Hide file tree
Showing 15 changed files with 1,002 additions and 1,783 deletions.
10 changes: 5 additions & 5 deletions .github/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

In this folder there is configuration for codecoverage, dependabot and ci workflows.

This folder can be merged using a `--allow-unrelated-histories` merge strategy from <https://github.com/spraakbanken/python-pdm-ci-conf> which provides a reasonably sensible base for writing your own ci on. By using this strategy the history of the CI repo is included in your repo, and future updates to the CI can be merged later.
This folder can be merged using a `--allow-unrelated-histories` merge strategy from <https://github.com/spraakbanken/python-uv-ci-conf> which provides a reasonably sensible base for writing your own ci on. By using this strategy the history of the CI repo is included in your repo, and future updates to the CI can be merged later.

The workflows in this folder requires a root Makefile with a couple of targets defined.
As base can the Makefile in <https://github.com/spraakbanken/python-pdm-make-conf> be used.
As base can the Makefile in <https://github.com/spraakbanken/python-uv-make-conf> be used.

## Publish

The `publish`-step in [test.yml](./workflows/test.yml) is configured to use the GitHub environment `release`, create that or change to your preferred environment.
The `publish`-step in [release.yml](./workflows/release.yml) is configured to use the GitHub environment `release`, create that or change to your preferred environment.
To publish to PyPI you must also configure your Pypi-project settings to use Trusted Publisher Management, by setting repo, workflow and environment on PyPI.

To perform this merge run:

```shell
git remote add ci [email protected]:spraakbanken/python-pdm-ci-conf.git
git remote add ci [email protected]:spraakbanken/python-uv-ci-conf.git
git fetch ci
git merge --allow-unrelated-histories ci/main
```

or add the remote as `git remote add ci https://github.com/spraakbanken/python-pdm-ci-conf.git`
or add the remote as `git remote add ci https://github.com/spraakbanken/python-uv-ci-conf.git`

To later merge updates to this repo, just run:

Expand Down
63 changes: 37 additions & 26 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ permissions:

env:
MINIMUM_PYTHON_VERSION: "3.9"
UV_VERSION: "0.5.1"

# If new code is pushed to a PR branch, then cancel in progress workflows for that PR. Ensures that
# we don't waste CI time, and returns results quicker https://github.com/jonhoo/rust-ci-conf/pull/5
Expand All @@ -29,24 +30,26 @@ jobs:
submodules: true

- name: Set up the python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: pdm-project/setup-pdm@v4
uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}

- name: Load cached venv
id: cached-venv
uses: actions/cache@v4

#----------------------------------------------
# ----- setup uv and load cache -----
#----------------------------------------------
- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/pdm.lock') }}-${{ hashFiles('.github/workflows/check.yml') }}
version: ${{ env.UV_VERSION }}
enable-cache: true

- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: make install-dev-orjson

- name: check formatting
run: make check-fmt

lint:
runs-on: ubuntu-latest
name: ubuntu / 3.9 / lint
Expand All @@ -55,21 +58,26 @@ jobs:
with:
submodules: true
- name: Set up the python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: pdm-project/setup-pdm@v4
uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- name: Load cached venv
id: cached-venv
uses: actions/cache@v4

#----------------------------------------------
# ----- setup uv and load cache -----
#----------------------------------------------
- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/pdm.lock') }}-${{ hashFiles('.github/workflows/check.yml') }}
version: ${{ env.UV_VERSION }}
enable-cache: true

- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: make install-dev-orjson

- name: lint code
run: make lint

type-check:
runs-on: ubuntu-latest
name: ubuntu / 3.9 / type-check
Expand All @@ -78,26 +86,30 @@ jobs:
with:
submodules: true
- name: Set up the python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: pdm-project/setup-pdm@v4
uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- name: Load cached venv
id: cached-venv
uses: actions/cache@v4

#----------------------------------------------
# ----- setup uv and load cache -----
#----------------------------------------------
- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/pdm.lock') }}-${{ hashFiles('.github/workflows/check.yml') }}
version: ${{ env.UV_VERSION }}
enable-cache: true

- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: make install-dev-orjson

- name: type-check code
run: make type-check

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check-check:
if: always()
needs:
needs:
- fmt
- lint
- type-check
Expand All @@ -108,4 +120,3 @@ jobs:
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
allowed-failures: upload-coverage
28 changes: 19 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- "v[0-9]+.[0-9]+.[0-9]+"
pull_request:
merge_group:

Expand All @@ -17,6 +17,7 @@ permissions:

env:
MINIMUM_PYTHON_VERSION: "3.9"
UV_VERSION: "0.5.1"

jobs:
build:
Expand All @@ -32,16 +33,25 @@ jobs:
uses: actions/checkout@v4
with:
submodules: true

#----------------------------------------------
# ----- setup python -----
#----------------------------------------------
- name: Set up the environment
uses: pdm-project/setup-pdm@v4
uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}


#----------------------------------------------
# ----- setup uv and load cache -----
#----------------------------------------------
- name: Set up uv
uses: astral-sh/setup-uv@v3
with:
version: ${{ env.UV_VERSION }}
enable-cache: true

#----------------------------------------------
# ----- build distribution -----
#----------------------------------------------
Expand All @@ -66,7 +76,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
os:
- ubuntu
- macos
- windows
Expand All @@ -93,11 +103,11 @@ jobs:
- run: pip install -r tests/requirements-testing.lock
- run: pip install json-arrays --no-index --no-deps --find-links dist --force-reinstall
- run: pytest

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
release-check:
if: always()
needs:
needs:
- build
- test-build
runs-on: ubuntu-latest
Expand All @@ -110,9 +120,9 @@ jobs:
# allowed-failures: coverage

publish:
# This action publishes the built and tested artifact to PyPI, but only on a tag
# This action publishes the built and tested artifact to PyPI, but only on a tag

needs:
needs:
- test-build
if: success() && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
Expand Down
36 changes: 22 additions & 14 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,52 @@ on:
branches: [main]
pull_request:
schedule:
- cron: '7 7 * * *'
- cron: "7 7 * * *"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

name: rolling

jobs:
env:
UV_VERSION: "0.5.1"

jobs:
# https://twitter.com/alcuadrado/status/1571291687837732873
update:
# This action checks that updating the dependencies of this crate to the latest available that
# satisfy the versions in Cargo.toml does not break this crate. This is important as consumers
# satisfy the versions in pyproject.toml does not break this crate. This is important as consumers
# of this crate will generally use the latest available crates. This is subject to the standard
# Cargo semver rules (i.e cargo does not update to a new major version unless explicitly told
# to).
runs-on: ubuntu-latest
name: ubuntu / 3.12 / updates work
# There's no point running this if no Cargo.lock was checked in in the first place, since we'd
# There's no point running this if no uv.lock was checked in in the first place, since we'd
# just redo what happened in the regular test job. Unfortunately, hashFiles only works in if on
# steps, so we repeat it.
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Set up uv
if: hashFiles('uv.lock') != ''
uses: astral-sh/setup-uv@v3
with:
version: ${{ env.UV_VERSION }}
enable-cache: true

- name: Install 3.12
if: hashFiles('pdm.lock') != ''
uses: pdm-project/setup-pdm@v4
if: hashFiles('uv.lock') != ''
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: pdm update
if: hashFiles('pdm.lock') != ''
run: pdm update
- name: pdm sync --dev
if: hashFiles('pdm.lock') != ''
run: pdm sync --dev

- name: uv sync --dev --upgrade
if: hashFiles('uv.lock') != ''
run: uv sync --dev --upgrade --all-packages --all-extras

- name: make test
if: hashFiles('pdm.lock') != ''
if: hashFiles('uv.lock') != ''
run: make test

Loading

0 comments on commit aa9c397

Please sign in to comment.