8000 Migrate from poetry to uv for dependency and package management (#986) · python-kasa/python-kasa@a967d5c · GitHub
[go: up one dir, main page]

Skip to content

Commit a967d5c

Browse files
authored
Migrate from poetry to uv for dependency and package management (#986)
1 parent 1773f98 commit a967d5c

File tree

12 files changed

+1934
-2507
lines changed

12 files changed

+1934
-2507
lines changed

.github/actions/setup/action.yaml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
---
22
name: Setup Environment
3-
description: Install requested pipx dependencies, configure the system python, and install poetry and the package dependencies
3+
description: Install requested pipx dependencies, configure the system python, and install uv and the package dependencies
44

55
inputs:
6-
poetry-install-options:
6+
uv-install-options:
77
default: ""
8-
poetry-version:
9-
default: 1.8.2
8+
uv-version:
9+
default: 0.4.5
1010
python-version:
1111
required: true
1212
cache-pre-commit:
1313
default: false
14+
cache-version:
15+
default: "v0.1"
1416

1517
runs:
1618
using: composite
@@ -25,7 +27,7 @@ runs:
2527
id: pipx-env-setup
2628
# pipx default home and bin dir are not writable by the cache action
2729
# so override them here and add the bin dir to PATH for later steps.
28-
# This also ensures the pipx cache only contains poetry
30+
# This also ensures the pipx cache only contains uv
2931
run: |
3032
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
3133
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
@@ -42,43 +44,43 @@ runs:
4244
uses: actions/cache@v4
4345
with:
4446
path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
45-
key: ${{ runner.os }}-${{ runner.arch }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-poetry-${{ inputs.poetry-version }}
47+
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-${{ runner.arch }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-pipx-${{ steps.pipx-env-setup.outputs.pipx-version }}-uv-${{ inputs.uv-version }}
4648

47-
- name: Install poetry
49+
- name: Install uv
4850
if: steps.pipx-cache.outputs.cache-hit != 'true'
49-
id: install-poetry
51+
id: install-uv
5052
shell: bash
5153
run: |-
52-
pipx install poetry==${{ inputs.poetry-version }} --python "${{ steps.setup-python.outputs.python-path }}"
54+
pipx install uv==${{ inputs.uv-version }} --python "${{ steps.setup-python.outputs.python-path }}"
5355
54-
- name: Read poetry cache location
55-
id: poetry-cache-location
56+
- name: Read uv cache location
57+
id: uv-cache-location
5658
shell: bash
5759
run: |-
58-
echo "poetry-venv-location=$(poetry config virtualenvs.path)" >> $GITHUB_OUTPUT
60+
echo "uv-cache-location=$(uv cache dir)" >> $GITHUB_OUTPUT
5961
6062
- uses: actions/cache@v4
61-
name: Poetry cache
63+
name: uv cache
6264
with:
6365
path: |
64-
${{ steps.poetry-cache-location.outputs.poetry-venv-location }}
65-
key: ${{ runner.os }}-${{ runner.arch }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}-options-${{ inputs.poetry-install-options }}
66+
${{ steps.uv-cache-location.outputs.uv-cache-location }}
67+
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-${{ runner.arch }}-python-${{ steps.setup-python.outputs.python-version }}-uv-${{ inputs.uv-version }}-${{ hashFiles('uv.lock') }}-options-${{ inputs.uv-install-options }}
6668

67-
- name: "Poetry install"
69+
- name: "uv install"
6870
shell: bash
6971
run: |
70-
poetry install ${{ inputs.poetry-install-options }}
72+
uv sync --python "${{ steps.setup-python.outputs.python-path }}" ${{ inputs.uv-install-options }}
7173
7274
- name: Read pre-commit version
7375
if: inputs.cache-pre-commit == 'true'
7476
id: pre-commit-version
7577
shell: bash
7678
run: >-
77-
echo "pre-commit-version=$(poetry run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT
79+
echo "pre-commit-version=$(uv run pre-commit -- -V | awk '{print $2}')" >> $GITHUB_OUTPUT
7880
7981
- uses: actions/cache@v4
8082
if: inputs.cache-pre-commit == 'true'
8183
name: Pre-commit cache
8284
with:
8385
path: ~/.cache/pre-commit/
84-
key: ${{ runner.os }}-${{ runner.arch }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
86+
key: cache-${{ inputs.cache-version }}-${{ runner.os }}-${{ runner.arch }}-pre-commit-${{ steps.pre-commit-version.outputs.pre-commit-version }}-python-${{ inputs.python-version }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}

.github/workflows/ci.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
workflow_dispatch: # to allow manual re-runs
99

1010
env:
11-
POETRY_VERSION: 1.8.2
11+
UV_VERSION: 0.4.5
1212

1313
jobs:
1414
linting:
@@ -26,32 +26,33 @@ jobs:
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828
cache-pre-commit: true
29-
poetry-version: ${{ env.POETRY_VERSION }}
30-
poetry-install-options: "--all-extras"
29+
uv-version: ${{ env.UV_VERSION }}
30+
uv-install-options: "--all-extras"
3131
- name: "Check supported device md files are up to date"
3232
run: |
33-
poetry run pre-commit run generate-supported --all-files
33+
uv run pre-commit run generate-supported --all-files
3434
- name: "Linting and code formating (ruff)"
3535
run: |
36-
poetry run pre-commit run ruff --all-files
36+
uv run pre-commit run ruff --all-files
3737
- name: "Typing checks (mypy)"
3838
run: |
39-
poetry run pre-commit run mypy --all-files
39+
source .venv/bin/activate
40+
pre-commit run mypy --all-files
4041
- name: "Run trailing-whitespace"
4142
run: |
42-
poetry run pre-commit run trailing-whitespace --all-files
43+
uv run pre-commit run trailing-whitespace --all-files
4344
- name: "Run end-of-file-fixer"
4445
run: |
45-
poetry run pre-commit run end-of-file-fixer --all-files
46+
uv run pre-commit run end-of-file-fixer --all-files
4647
- name: "Run check-docstring-first"
4748
run: |
48-
poetry run pre-commit run check-docstring-first --all-files
49+
uv run pre-commit run check-docstring-first --all-files
4950
- name: "Run debug-statements"
5051
run: |
51-
poetry run pre-commit run debug-statements --all-files
52+
uv run pre-commit run debug-statements --all-files
5253
- name: "Run check-ast"
5354
run: |
54-
poetry run pre-commit run check-ast --all-files
55+
uv run pre-commit run check-ast --all-files
5556
5657
5758
tests:
@@ -89,16 +90,16 @@ jobs:
8990
uses: ./.github/actions/setup
9091
with:
9192
python-version: ${{ matrix.python-version }}
92-
poetry-version: ${{ env.POETRY_VERSION }}
93-
poetry-install-options: ${{ matrix.extras == true && '--all-extras' || '' }}
93+
uv-version: ${{ env.UV_VERSION }}
94+
uv-install-options: ${{ matrix.extras == true && '--all-extras' || '' }}
9495
- name: "Run tests (no coverage)"
9596
if: ${{ startsWith(matrix.python-version, 'pypy') }}
9697
run: |
97-
poetry run pytest
98+
uv run pytest
9899
- name: "Run tests (with coverage)"
99100
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
100101
run: |
101-
poetry run pytest --cov kasa --cov-report xml
102+
uv run pytest --cov kasa --cov-report xml
102103
- name: "Upload coverage to Codecov"
103104
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
104105
uses: "codecov/codecov-action@v4"

.github/workflows/publish.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ on:
33
release:
44
types: [published]
55

6+
env:
7+
UV_VERSION: 0.4.5
8+
69
jobs:
710
build-n-publish:
811
name: Build release packages
@@ -17,19 +20,10 @@ jobs:
1720
with:
1821
python-version: "3.x"
1922

20-
- name: Install pypa/build
21-
run: >-
22-
python -m
23-
pip install
24-
build
25-
--user
23+
- name: Install uv
24+
run: |-
25+
pipx install uv==${{ env.UV_VERSION }} --python "${{ steps.setup-python.outputs.python-path }}"
2626
- name: Build a binary wheel and a source tarball
27-
run: >-
28-
python -m
29-
build
30-
--sdist
31-
--wheel
32-
--outdir dist/
33-
.
27+
run: uv build
3428
- name: Publish release on pypi
3529
uses: pypa/gh-action-pypi-publish@release/v1

.pre-commit-config.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
repos:
2+
3+
- repo: https://github.com/astral-sh/uv-pre-commit
4+
# uv version.
5+
rev: 0.4.5
6+
hooks:
7+
# Update the uv lockfile
8+
- id: uv-lock
9+
210
- repo: https://github.com/pre-commit/pre-commit-hooks
311
rev: v4.6.0
412
hooks:
@@ -28,7 +36,7 @@ repos:
2836
# for more accurate checking than using the pre-commit mypy mirror
2937
- id: mypy
3038
name: mypy
31-
entry: devtools/run-in-env.sh mypy
39+
entry: uv run mypy
3240
language: system
3341
types_or: [python, pyi]
3442
require_serial: true
@@ -39,8 +47,7 @@ repos:
3947
- id: generate-supported
4048
name: Generate supported devices
4149
description: This hook generates the supported device sections of README.md and SUPPORTED.md
42-
entry: devtools/run-in-env.sh ./devtools/generate_supported.py
50+
entry: uv run ./devtools/generate_supported.py
4351
language: system # Required or pre-commit creates a new venv
44-
verbose: true # Show output on success
4552
types: [json]
4653
pass_filenames: false # passing filenames causes the hook to run in batches against all-files

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ You can install the most recent release using pip:
2020
pip install python-kasa
2121
```
2222

23-
Alternatively, you can clone this repository and use poetry to install the development version:
23+
Alternatively, you can clone this repository and use `uv` to install the development version:
2424
```
2525
git clone https://github.com/python-kasa/python-kasa.git
2626
cd python-kasa/
27-
poetry install
27+
uv sync --all-extras
28+
uv run kasa
2829
```
2930

3031
If you have not yet provisioned your device, [you can do so using the cli tool](https://python-kasa.readthedocs.io/en/latest/cli.html#provisioning).

RELEASING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ git checkout -b release/$NEW_RELEASE
3333
### Update the version number
3434

3535
```bash
36-
poetry version $NEW_RELEASE
36+
sed -i "0,/version = /{s/version = .*/version = \"${NEW_RELEASE}\"/}" pyproject.toml
3737
```
3838

3939
### Update dependencies
4040

4141
```bash
42-
poetry install --all-extras --sync
43-
poetry update
42+
uv sync --all-extras
43+
uv lock --upgrade
4444
```
4545

4646
### Run pre-commit and tests
4747

4848
```bash
49-
pre-commit run --all-files
50-
pytest kasa
49+
uv run pre-commit run --all-files
50+
uv run pytest
5151
```
5252

5353
### Create release summary (skip for dev releases)
@@ -215,7 +215,7 @@ git cherry-pick commitSHA2 -S
215215
### Update the version number
216216

217217
```bash
218-
poetry version $NEW_RELEASE
218+
sed -i "0,/version = /{s/version = .*/version = \"${NEW_RELEASE}\"/}" pyproject.toml
219219
```
220220

221221
### Manually edit the changelog

devtools/run-in-env.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

docs/source/contribute.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ This page aims to help you to get started.
1111
## Setting up the development environment
1212

1313
To get started, simply clone this repository and initialize the development environment.
14-
We are using [poetry](https://python-poetry.org) for dependency management, so after cloning the repository simply execute
15-
`poetry install` which will install all necessary packages and create a virtual environment for you.
14+
We are using [uv](https://github.com/astral-sh/uv) for dependency management, so after cloning the repository simply execute
15+
`uv sync` which will install all necessary packages and create a virtual environment for you in `.venv`.
1616

1717
```
1818
$ git clone https://github.com/python-kasa/python-kasa.git
1919
$ cd python-kasa
20-
$ poetry install
20+
$ uv sync --all-extras
2121
```
2222

2323
## Code-style checks
@@ -36,7 +36,7 @@ You can also execute the pre-commit hooks on all files by executing `pre-commit
3636
You can run tests on the library by executing `pytest` in the source directory:
3737

3838
```
39-
$ poetry run pytest kasa
39+
$ uv run pytest kasa
4040
```
4141

4242
This will run the tests against the contributed example responses.
@@ -68,8 +68,8 @@ The easiest way to do that is by doing:
6868
```
6969
$ git clone https://github.com/python-kasa/python-kasa.git
7070
$ cd python-kasa
71-
$ poetry install
72-
$ poetry shell
71+
$ uv sync --all-extras
72+
$ source .venv/bin/activate
7373
$ python -m devtools.dump_devinfo --username <username> --password <password> --host 192.168.1.123
7474
```
7575

@@ -82,5 +82,5 @@ If you choose to do so, it will save the fixture files directly in their correct
8282

8383
```{note}
8484
When adding new fixture files, you should run `pre-commit run -a` to re-generate the list of supported devices.
85-
You may need to adjust `device_fixtures.py` to add a new model into the correct device categories. Verify that test pass by executing `poetry run pytest kasa`.
85+
You may need to adjust `device_fixtures.py` to add a new model into the correct device categories. Verify that test pass by executing `uv run pytest kasa`.
8686
```

0 commit comments

Comments
 (0)
0