Skip to content

Commit

Permalink
chore: migrate from Poetry to uv (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted authored Dec 20, 2024
1 parent 38ce3ae commit 297976b
Show file tree
Hide file tree
Showing 13 changed files with 662 additions and 1,046 deletions.
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,3 @@ updates:
directory: "/"
schedule:
interval: "daily"

# Maintain dependencies for poetry
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
52 changes: 29 additions & 23 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,51 @@ on:
branches: [main]

jobs:
test:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- "3.12"
python-version: ["3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Install Poetry
run: pipx install poetry

- name: Configure Poetry virtualenv
run: poetry config virtualenvs.in-project true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
cache: poetry

- run: poetry env use ${{ matrix.python-version }}

- name: Install dependencies
run: poetry install --no-interaction
version: latest

- name: Check Poetry config and lockfile
run: poetry run pre-commit run poetry-check --all-files
- name: Check uv.lock
run: uv run --frozen pre-commit run uv-lock-check --all-files

- name: Lint (ruff)
run: poetry run ruff check . --config pyproject.toml --output-format=github --no-fix
run: uv run --frozen ruff check . --config pyproject.toml --output-format=github --no-fix

- name: Formatting (ruff)
run: poetry run pre-commit run ruff-format --all-files --show-diff-on-failure
run: uv run --frozen pre-commit run ruff-format --all-files --show-diff-on-failure

- name: Typing (pyright)
run: poetry run pre-commit run pyright --all-files
run: uv run --frozen pre-commit run pyright --all-files

test:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}
version: latest

- name: Test
run: poetry run pytest tests
run: uv run --frozen pytest tests
49 changes: 7 additions & 42 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: "3.12"

- name: Get Python version
id: python-version
run: echo version="$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> "$GITHUB_OUTPUT"

- name: Run Poetry image
uses: abatilo/[email protected]
with:
poetry-version: "1.1.12"

- name: Set Poetry virtualenv
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v4
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.python-version.outputs.version }}-${{ hashFiles('poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
shell: bash
run: timeout 10s python -m poetry run pip --version || rm -rf .venv

- name: Install dependencies
run: poetry install --no-interaction

# - name: Bump version
# env:
# VERSION: ${{ github.event.release.tag_name }}
# run: poetry version $(echo $VERSION | sed -e 's/^v//')
version: latest

- name: Build
run: poetry build
run: uv build

- name: Publish TestPyPI
run: uv publish --trusted-publishing always -r testpypi
env:
POETRY_REPOSITORIES_TESTPYPI_URL: https://test.pypi.org/legacy/
POETRY_HTTP_BASIC_TESTPYPI_USERNAME: __token__
POETRY_HTTP_BASIC_TESTPYPI_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: poetry publish -r testpypi
UV_PUBLISH_URL: https://test.pypi.org/legacy/

- name: Publish PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: poetry publish
run: uv publish --trusted-publishing always
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
repos:
- repo: local
hooks:
- id: poetry-install
name: poetry-install
description: install Poetry dependencies from the lock file
entry: poetry install
- id: uv-sync
name: uv-sync
description: install uv dependencies from the lock file
entry: uv sync
language: python
pass_filenames: false
stages: [post-checkout, post-merge]
always_run: true
- id: poetry-check
name: poetry-check
description: validate Poetry config and dependency lock file
entry: poetry check
- id: uv-lock-check
name: uv-lock-check
description: validate uv dependency lock file
entry: uv lock --check
language: python
pass_filenames: false
files: ^(.*/)?(pyproject\.toml|poetry\.lock)$
files: ^(.*/)?(pyproject\.toml|uv\.lock)$
- id: ruff-lint
name: ruff-lint
entry: poetry run ruff check
entry: uv run ruff check
args:
[
--force-exclude,
Expand All @@ -34,14 +34,14 @@ repos:
require_serial: true # run once for all files
- id: ruff-format
name: ruff-format
entry: poetry run ruff format
entry: uv run ruff format
args: [--force-exclude, --config, pyproject.toml]
language: system
types_or: [python]
require_serial: true # run once for all files
- id: pyright
name: pyright
entry: poetry run pyright
entry: uv run pyright
language: system
types: [python]
require_serial: true # run once for all files
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,10 @@ things.commit(todo)

See [main.py](./main.py).

1. Install dependencies
Pass your Things Cloud credentials as environment examples to run the example

```sh
poetry install
```

2. Pass your Things Cloud credentials as environment examples to run the example

```sh
[email protected] THINGS_PASSWORD=your-password python main.py
[email protected] THINGS_PASSWORD=your-password uv run main.py
```

### Progress
Expand Down
Loading

0 comments on commit 297976b

Please sign in to comment.