mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 11:13:34 +00:00
Speed up and simplify github workflows (#1128)
- Enable parallel tests in the CI with pytest-xdist - Migrate to the official `astral-sh/setup-uv` github action - Call `pre-commit` run as a single job in CI instead of relisting each check - Use `uv` version 0.4.16 - Fix bug with pre-commit cache - Update `publish.yml` to use `astral-sh/setup-uv`
This commit is contained in:
parent
1ab08f454f
commit
038b6993ca
61
.github/actions/setup/action.yaml
vendored
61
.github/actions/setup/action.yaml
vendored
@ -1,12 +1,12 @@
|
||||
---
|
||||
name: Setup Environment
|
||||
description: Install requested pipx dependencies, configure the system python, and install uv and the package dependencies
|
||||
description: Install uv, configure the system python, and the package dependencies
|
||||
|
||||
inputs:
|
||||
uv-install-options:
|
||||
default: ""
|
||||
uv-version:
|
||||
default: 0.4.5
|
||||
default: 0.4.16
|
||||
python-version:
|
||||
required: true
|
||||
cache-pre-commit:
|
||||
@ -17,66 +17,29 @@ inputs:
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- uses: "actions/setup-python@v5"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v3
|
||||
with:
|
||||
enable-cache: true
|
||||
|
||||
- name: "Setup python"
|
||||
uses: "actions/setup-python@v5"
|
||||
id: setup-python
|
||||
with:
|
||||
python-version: "${{ inputs.python-version }}"
|
||||
allow-prereleases: true
|
||||
|
||||
- name: Setup pipx environment Variables
|
||||
id: pipx-env-setup
|
||||
# pipx default home and bin dir are not writable by the cache action
|
||||
# so override them here and add the bin dir to PATH for later steps.
|
||||
# This also ensures the pipx cache only contains uv
|
||||
run: |
|
||||
SEP="${{ !startsWith(runner.os, 'windows') && '/' || '\\' }}"
|
||||
PIPX_CACHE="${{ github.workspace }}${SEP}pipx_cache"
|
||||
echo "pipx-cache-path=${PIPX_CACHE}" >> $GITHUB_OUTPUT
|
||||
echo "pipx-version=$(pipx --version)" >> $GITHUB_OUTPUT
|
||||
echo "PIPX_HOME=${PIPX_CACHE}${SEP}home" >> $GITHUB_ENV
|
||||
echo "PIPX_BIN_DIR=${PIPX_CACHE}${SEP}bin" >> $GITHUB_ENV
|
||||
echo "PIPX_MAN_DIR=${PIPX_CACHE}${SEP}man" >> $GITHUB_ENV
|
||||
echo "${PIPX_CACHE}${SEP}bin" >> $GITHUB_PATH
|
||||
shell: bash
|
||||
|
||||
- name: Pipx cache
|
||||
id: pipx-cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ steps.pipx-env-setup.outputs.pipx-cache-path }}
|
||||
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 }}
|
||||
|
||||
- name: Install uv
|
||||
if: steps.pipx-cache.outputs.cache-hit != 'true'
|
||||
id: install-uv
|
||||
shell: bash
|
||||
run: |-
|
||||
pipx install uv==${{ inputs.uv-version }} --python "${{ steps.setup-python.outputs.python-path }}"
|
||||
|
||||
- name: Read uv cache location
|
||||
id: uv-cache-location
|
||||
shell: bash
|
||||
run: |-
|
||||
echo "uv-cache-location=$(uv cache dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: actions/cache@v4
|
||||
name: uv cache
|
||||
with:
|
||||
path: |
|
||||
${{ steps.uv-cache-location.outputs.uv-cache-location }}
|
||||
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 }}
|
||||
|
||||
- name: "uv install"
|
||||
- name: "Install project"
|
||||
shell: bash
|
||||
run: |
|
||||
uv sync --python "${{ steps.setup-python.outputs.python-path }}" ${{ inputs.uv-install-options }}
|
||||
uv sync ${{ inputs.uv-install-options }}
|
||||
|
||||
- name: Read pre-commit version
|
||||
if: inputs.cache-pre-commit == 'true'
|
||||
id: pre-commit-version
|
||||
shell: bash
|
||||
run: >-
|
||||
echo "pre-commit-version=$(uv run pre-commit -- -V | awk '{print $2}')" >> $GITHUB_OUTPUT
|
||||
echo "pre-commit-version=$(uv run pre-commit -V | awk '{print $2}')" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: actions/cache@v4
|
||||
if: inputs.cache-pre-commit == 'true'
|
||||
|
43
.github/workflows/ci.yml
vendored
43
.github/workflows/ci.yml
vendored
@ -8,7 +8,7 @@ on:
|
||||
workflow_dispatch: # to allow manual re-runs
|
||||
|
||||
env:
|
||||
UV_VERSION: 0.4.5
|
||||
UV_VERSION: 0.4.16
|
||||
|
||||
jobs:
|
||||
linting:
|
||||
@ -20,7 +20,8 @@ jobs:
|
||||
python-version: ["3.12"]
|
||||
|
||||
steps:
|
||||
- uses: "actions/checkout@v4"
|
||||
- name: "Checkout source files"
|
||||
uses: "actions/checkout@v4"
|
||||
- name: Setup environment
|
||||
uses: ./.github/actions/setup
|
||||
with:
|
||||
@ -28,31 +29,10 @@ jobs:
|
||||
cache-pre-commit: true
|
||||
uv-version: ${{ env.UV_VERSION }}
|
||||
uv-install-options: "--all-extras"
|
||||
- name: "Check supported device md files are up to date"
|
||||
|
||||
- name: "Run pre-commit checks"
|
||||
run: |
|
||||
uv run pre-commit run generate-supported --all-files
|
||||
- name: "Linting and code formating (ruff)"
|
||||
run: |
|
||||
uv run pre-commit run ruff --all-files
|
||||
- name: "Typing checks (mypy)"
|
||||
run: |
|
||||
source .venv/bin/activate
|
||||
pre-commit run mypy --all-files
|
||||
- name: "Run trailing-whitespace"
|
||||
run: |
|
||||
uv run pre-commit run trailing-whitespace --all-files
|
||||
- name: "Run end-of-file-fixer"
|
||||
run: |
|
||||
uv run pre-commit run end-of-file-fixer --all-files
|
||||
- name: "Run check-docstring-first"
|
||||
run: |
|
||||
uv run pre-commit run check-docstring-first --all-files
|
||||
- name: "Run debug-statements"
|
||||
run: |
|
||||
uv run pre-commit run debug-statements --all-files
|
||||
- name: "Run check-ast"
|
||||
run: |
|
||||
uv run pre-commit run check-ast --all-files
|
||||
uv run pre-commit run --all-files --verbose
|
||||
|
||||
|
||||
tests:
|
||||
@ -83,6 +63,13 @@ jobs:
|
||||
- os: ubuntu-latest
|
||||
python-version: "3.10"
|
||||
extras: true
|
||||
# Exclude pypy on windows due to significant performance issues
|
||||
# running pytest requires ~12 min instead of 2 min on other platforms
|
||||
- os: windows-latest
|
||||
python-version: "pypy-3.9"
|
||||
- os: windows-latest
|
||||
python-version: "pypy-3.10"
|
||||
|
||||
|
||||
steps:
|
||||
- uses: "actions/checkout@v4"
|
||||
@ -95,11 +82,11 @@ jobs:
|
||||
- name: "Run tests (no coverage)"
|
||||
if: ${{ startsWith(matrix.python-version, 'pypy') }}
|
||||
run: |
|
||||
uv run pytest
|
||||
uv run pytest -n auto
|
||||
- name: "Run tests (with coverage)"
|
||||
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
|
||||
run: |
|
||||
uv run pytest --cov kasa --cov-report xml
|
||||
uv run pytest -n auto --cov kasa --cov-report xml
|
||||
- name: "Upload coverage to Codecov"
|
||||
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
|
||||
uses: "codecov/codecov-action@v4"
|
||||
|
16
.github/workflows/publish.yml
vendored
16
.github/workflows/publish.yml
vendored
@ -4,7 +4,8 @@ on:
|
||||
types: [published]
|
||||
|
||||
env:
|
||||
UV_VERSION: 0.4.5
|
||||
UV_VERSION: 0.4.16
|
||||
PYTHON_VERSION: 3.12
|
||||
|
||||
jobs:
|
||||
build-n-publish:
|
||||
@ -14,16 +15,19 @@ jobs:
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Checkout source files
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v3
|
||||
|
||||
- name: Setup python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.x"
|
||||
python-version: ${{ env.PYTHON_VERSION }}
|
||||
|
||||
- name: Install uv
|
||||
run: |-
|
||||
pipx install uv==${{ env.UV_VERSION }} --python "${{ steps.setup-python.outputs.python-path }}"
|
||||
- name: Build a binary wheel and a source tarball
|
||||
run: uv build
|
||||
|
||||
- name: Publish release on pypi
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
|
@ -2,7 +2,7 @@ repos:
|
||||
|
||||
- repo: https://github.com/astral-sh/uv-pre-commit
|
||||
# uv version.
|
||||
rev: 0.4.5
|
||||
rev: 0.4.16
|
||||
hooks:
|
||||
# Update the uv lockfile
|
||||
- id: uv-lock
|
||||
|
@ -32,7 +32,7 @@ def _get_subclasses(of_class):
|
||||
and module.__package__ != "kasa.interfaces"
|
||||
):
|
||||
subclasses.add((module.__package__ + "." + name, obj))
|
||||
return subclasses
|
||||
return sorted(subclasses)
|
||||
|
||||
|
||||
device_classes = pytest.mark.parametrize(
|
||||
|
@ -481,7 +481,7 @@ def _get_subclasses(of_class):
|
||||
and name != "_deprecated_TPLinkSmartHomeProtocol"
|
||||
):
|
||||
subclasses.add((name, obj))
|
||||
return subclasses
|
||||
return sorted(subclasses)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -55,7 +55,8 @@ dev-dependencies = [
|
||||
"coverage[toml]",
|
||||
"pytest-timeout~=2.0",
|
||||
"pytest-freezer~=0.4",
|
||||
"mypy~=1.0"
|
||||
"mypy~=1.0",
|
||||
"pytest-xdist>=3.6.1",
|
||||
]
|
||||
|
||||
|
||||
@ -105,6 +106,7 @@ markers = [
|
||||
"requires_dummy: test requires dummy data to pass, skipped on real devices",
|
||||
]
|
||||
asyncio_mode = "auto"
|
||||
asyncio_default_fixture_loop_scope = "function"
|
||||
timeout = 10
|
||||
|
||||
[tool.doc8]
|
||||
|
24
uv.lock
24
uv.lock
@ -516,6 +516,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/02/cc/b7e31358aac6ed1ef2bb790a9746ac2c69bcb3c8588b41616914eb106eaf/exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b", size = 16453 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "execnet"
|
||||
version = "2.1.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/bb/ff/b4c0dc78fbe20c3e59c0c7334de0c27eb4001a2b2017999af398bf730817/execnet-2.1.1.tar.gz", hash = "sha256:5189b52c6121c24feae288166ab41b32549c7e2348652736540b9e6e7d4e72e3", size = 166524 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/43/09/2aea36ff60d16dd8879bdb2f5b3ee0ba8d08cbbdcdfe870e695ce3784385/execnet-2.1.1-py3-none-any.whl", hash = "sha256:26dee51f1b80cebd6d0ca8e74dd8745419761d3bef34163928cbebbdc4749fdc", size = 40612 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "filelock"
|
||||
version = "3.16.0"
|
||||
@ -1294,6 +1303,19 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/03/27/14af9ef8321f5edc7527e47def2a21d8118c6f329a9342cc61387a0c0599/pytest_timeout-2.3.1-py3-none-any.whl", hash = "sha256:68188cb703edfc6a18fad98dc25a3c61e9f24d644b0b70f33af545219fc7813e", size = 14148 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pytest-xdist"
|
||||
version = "3.6.1"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "execnet" },
|
||||
{ name = "pytest" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/41/c4/3c310a19bc1f1e9ef50075582652673ef2bfc8cd62afef9585683821902f/pytest_xdist-3.6.1.tar.gz", hash = "sha256:ead156a4db231eec769737f57668ef58a2084a34b2e55c4a8fa20d861107300d", size = 84060 }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/6d/82/1d96bf03ee4c0fdc3c0cbe61470070e659ca78dc0086fb88b66c185e2449/pytest_xdist-3.6.1-py3-none-any.whl", hash = "sha256:9ed4adfb68a016610848639bb7e02c9352d5d9f03d04809919e2dafc3be4cca7", size = 46108 },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "python-dateutil"
|
||||
version = "2.9.0.post0"
|
||||
@ -1349,6 +1371,7 @@ dev = [
|
||||
{ name = "pytest-mock" },
|
||||
{ name = "pytest-sugar" },
|
||||
{ name = "pytest-timeout" },
|
||||
{ name = "pytest-xdist" },
|
||||
{ name = "toml" },
|
||||
{ name = "voluptuous" },
|
||||
{ name = "xdoctest" },
|
||||
@ -1386,6 +1409,7 @@ dev = [
|
||||
{ name = "pytest-mock" },
|
||||
{ name = "pytest-sugar" },
|
||||
{ name = "pytest-timeout", specifier = "~=2.0" },
|
||||
{ name = "pytest-xdist", specifier = ">=3.6.1" },
|
||||
{ name = "toml" },
|
||||
{ name = "voluptuous" },
|
||||
{ name = "xdoctest", specifier = ">=1.2.0" },
|
||||
|
Loading…
Reference in New Issue
Block a user