Skip to content

Commit

Permalink
Migrate from poetry to uv (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
KapJI authored Nov 6, 2024
1 parent 8852430 commit 37f86f6
Show file tree
Hide file tree
Showing 10 changed files with 2,277 additions and 4,077 deletions.
19 changes: 19 additions & 0 deletions .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Common steps to install and cache dependencies"

runs:
using: "composite"
steps:
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Set up Python
shell: bash
run: |
uv python install
echo "PYTHON_VERSION=$(uv run python -c 'import platform; print(platform.python_version())')" >> "$GITHUB_ENV"
- name: Install dependencies with uv
shell: bash
run: uv sync
2 changes: 1 addition & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dependencies:
- any: ["poetry.lock"]
- any: ["uv.lock"]
all: ["!**/*.py"]

documentation:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/home-assistant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
- master
pull_request:

env:
DEFAULT_PYTHON: "3.12"

jobs:
hacs:
runs-on: ubuntu-latest
Expand Down
31 changes: 16 additions & 15 deletions .github/workflows/linting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
- master
pull_request:

env:
PYTHON_VERSION: "3.12"

jobs:
pre-commit:
name: Pre-commit
Expand All @@ -17,23 +14,27 @@ jobs:
- name: Check out the repository
uses: actions/checkout@v4

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Prepare and install deps
uses: ./.github/actions/install-deps

- name: Install Poetry
uses: abatilo/actions-poetry@v3.0.1
- uses: actions/cache@v4
name: Cache pre-commit hooks
with:
poetry-version: 1.3.2

- name: Install dependencies
run: poetry install
path: ~/.cache/pre-commit/
key: >
${{ format('pre-commit-{0}-{1}-{2}',
runner.os,
matrix.python-version,
hashFiles('.pre-commit-config.yaml')
) }}
restore-keys: |
pre-commit-${{ runner.os }}-${{ matrix.python-version }}-
pre-commit-${{ runner.os }}-
- name: Run pre-commit on all files
run: |
poetry run pre-commit run --all-files --show-diff-on-failure --color=always
uvx pre-commit run --all-files --show-diff-on-failure --color=always
- name: Run python-typing-update
run: |
poetry run pre-commit run --hook-stage manual python-typing-update --all-files --show-diff-on-failure --color=always
uvx pre-commit run --hook-stage manual python-typing-update --all-files --show-diff-on-failure --color=always
19 changes: 3 additions & 16 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: Publish new release
on:
workflow_dispatch:

env:
PYTHON_VERSION: "3.12"

jobs:
publish:
name: Update manifest and publish
Expand All @@ -14,21 +11,11 @@ jobs:
- name: Check out the repository
uses: actions/checkout@v4

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

- name: Install Poetry
uses: abatilo/actions-poetry@v3.0.1
with:
poetry-version: 1.3.2

- name: Install dependencies
run: poetry install
- name: Prepare and install deps
uses: ./.github/actions/install-deps

- name: Run script
run: |
poetry run python script/publish_release.py
uv run python script/publish_release.py
env:
GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }}
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ repos:
hooks:
- id: ruff-format
name: ruff format
entry: poetry run ruff format
entry: uv run ruff format
language: system
types: [python]
require_serial: true
- id: ruff-check
name: ruff check
entry: poetry run ruff check --fix
entry: uv run ruff check --fix
language: system
types: [python]
require_serial: true
- id: mypy
name: mypy
entry: poetry run mypy
entry: uv run mypy
language: system
types: [python]
require_serial: true
- id: pylint
name: pylint
entry: poetry run pylint
entry: uv run pylint
language: system
types: [python]
require_serial: true
- id: codespell
name: codespell
entry: poetry run codespell --write-changes
entry: uv run codespell --write-changes
language: system
pass_filenames: false
always_run: true
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ People _love_ thorough bug reports. I'm not even kidding.

## Use a Consistent Coding Style

Install [Poetry](https://python-poetry.org/docs/#installation) to setup the developer environment.
It uses [black](https://github.com/ambv/black) and [prettier](https://prettier.io/)
Install [uv](https://docs.astral.sh/uv/getting-started/installation/) to setup the developer environment.
It uses [ruff](https://docs.astral.sh/ruff/) and [prettier](https://prettier.io/)
to make sure the code follows the style.

`pre-commit` can be used to run all checks with one command (see dedicated section below).
Expand All @@ -74,7 +74,7 @@ When writing unittests please follow the good practises like:

## Pre-commit

With Poetry installed, run `poetry install` in the repo root.
With uv installed, run `uv sync` in the repo root.
It will create a virtualenv with all required packages.

After that you can run [pre-commit](https://pre-commit.com/) with settings included in the
Expand All @@ -83,13 +83,13 @@ repository to have code style and linting checks.
Activate `pre-commit` git hook:

```console
$ poetry run pre-commit install
$ uvx pre-commit install
```

Now the pre-commit tests will be done every time you commit.

You can also run the tests on all repository files manually with this command:

```console
$ poetry run pre-commit run --all-files
$ uvx pre-commit run --all-files
```
Loading

0 comments on commit 37f86f6

Please sign in to comment.