Skip to content

Commit

Permalink
Migrate from poetry to uv (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinn authored Dec 23, 2024
2 parents f3abcab + fdde405 commit b97775f
Show file tree
Hide file tree
Showing 29 changed files with 1,555 additions and 1,895 deletions.
33 changes: 0 additions & 33 deletions .github/actions/setup-poetry-env/action.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/actions/setup-uv-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "setup-uv-env"
description: "Composite action to setup the Python and uv environment."

inputs:
python-version:
required: false
description: "The python version to use"
default: "3.12"

runs:
using: "composite"
steps:
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ inputs.python-version }}
version: "0.5.11"

- name: Set up python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install dependencies
run: uv sync
shell: bash
23 changes: 10 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-uv-env

- name: Run checks
run: make check
Expand All @@ -35,14 +35,11 @@ jobs:
- name: Check out
uses: actions/checkout@v4

- name: Set up python
uses: actions/setup-python@v5
- name: Set up the environment
uses: ./.github/actions/setup-uv-env
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Load cached venv
uses: actions/cache@v4
with:
Expand All @@ -51,15 +48,15 @@ jobs:

- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
uv add tox-gh-actions
uv tool install tox --with tox-uv
- name: Test with tox
run: tox
run: uv run tox

- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11
- name: Upload coverage reports to Codecov with GitHub Action on Python 3.12
uses: codecov/codecov-action@v4
if: ${{ matrix.python-version == '3.11' }}
if: ${{ matrix.python-version == '3.12' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: martinn/quickapiclient
Expand All @@ -71,7 +68,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-uv-env

- name: Check if documentation can be built
run: poetry run mkdocs build -s
run: make docs-test
14 changes: 6 additions & 8 deletions .github/workflows/on-release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ jobs:
uses: actions/checkout@v4

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
uses: ./.github/actions/setup-uv-env

- name: Export tag
id: vars
run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
# - name: Export tag
# id: vars
# run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT

- name: Build and publish
run: |
source .venv/bin/activate
poetry version $RELEASE_VERSION
make build-and-publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
# RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

deploy-docs:
needs: publish
Expand All @@ -41,4 +39,4 @@ jobs:
uses: ./.github/actions/setup-poetry-env

- name: Deploy documentation
run: poetry run mkdocs gh-deploy --force
run: uv run --group docs mkdocs gh-deploy --force
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.6"
rev: "v0.8.4"
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
Expand Down
34 changes: 15 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,49 @@
.PHONY: install
install: ## Install the poetry environment and install the pre-commit hooks
@echo "🚀 Creating virtual environment using pyenv and poetry"
@poetry install
@ poetry run pre-commit install
@poetry shell
install: ## Install the uv environment and install the pre-commit hooks
@echo "🚀 Creating virtual environment using uv"
@uv sync
@uvx pre-commit install

.PHONY: check
check: ## Run code quality tools.
@echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry lock --check"
@poetry check --lock
@echo "🚀 Checking uv lock file consistency with 'pyproject.toml': Running uv lock --check"
@uv lock --check
@echo "🚀 Linting code: Running pre-commit"
@poetry run pre-commit run -a
@uv run --group dev pre-commit run -a
@echo "🚀 Static type checking: Running mypy"
@poetry run mypy
@uv run --group dev mypy
@echo "🚀 Checking for obsolete dependencies: Running deptry"
@poetry run deptry .
@uv run --group dev deptry .

.PHONY: test
test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
@poetry run pytest --cov --cov-config=pyproject.toml --cov-report=xml
@uv run --group dev pytest --cov --cov-config=pyproject.toml --cov-report=xml

.PHONY: build
build: clean-build ## Build wheel file using poetry
build: clean-build ## Build wheel file using uv
@echo "🚀 Creating wheel file"
@poetry build
@uv build

.PHONY: clean-build
clean-build: ## clean build artifacts
@rm -rf dist

.PHONY: publish
publish: ## publish a release to pypi.
@echo "🚀 Publishing: Dry run."
@poetry config pypi-token.pypi $(PYPI_TOKEN)
@poetry publish --dry-run
@echo "🚀 Publishing."
@poetry publish
@uv publish --token $(PYPI_TOKEN)

.PHONY: build-and-publish
build-and-publish: build publish ## Build and publish.

.PHONY: docs-test
docs-test: ## Test if documentation can be built without warnings or errors
@poetry run mkdocs build -s
@uv run --group docs mkdocs build -s

.PHONY: docs
docs: ## Build and serve the documentation
@poetry run mkdocs serve
@uv run --group docs mkdocs serve

.PHONY: help
help:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ pip install quickapiclient[attrs,pydantic,msgspec,requests]
# Or if using poetry
poetry add quickapiclient
poetry add quickapiclient[attrs,pydantic,msgspec,requests]
# Or if using uv
uv add quickapiclient
uv add quickapiclient[attrs,pydantic,msgspec,requests]
```

## More examples
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ site_name: quickapiclient
repo_url: https://github.com/martinn/quickapiclient
site_url: https://martinn.github.io/quickapiclient
site_description: A library for creating fully typed declarative API clients quickly and easily.
site_author: Martin N.
site_author: Martin
edit_uri: edit/main/docs/
repo_name: martinn/quickapiclient

Expand Down
Loading

0 comments on commit b97775f

Please sign in to comment.