Skip to content

Commit ed7cc81

Browse files
authored
Merge pull request #263 from plugwise/ruff
Re-instate tooling and align with Core/Python-plugwise approach
2 parents 9247974 + afa96a6 commit ed7cc81

File tree

12 files changed

+531
-243
lines changed

12 files changed

+531
-243
lines changed

.github/workflows/verify.yml

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name: Latest commit
55

66
env:
7-
CACHE_VERSION: 24
7+
CACHE_VERSION: 1
88
DEFAULT_PYTHON: "3.13"
99
PRE_COMMIT_HOME: ~/.cache/pre-commit
1010

@@ -13,7 +13,7 @@ on:
1313
- cron: "2 4 * * 0" # weekly
1414
workflow_dispatch:
1515
push:
16-
pull_request:
16+
#pull_request:
1717

1818
jobs:
1919
# Prepare default python version environment
@@ -48,8 +48,9 @@ jobs:
4848
pip install virtualenv --upgrade
4949
python -m venv venv
5050
. venv/bin/activate
51-
pip install -U pip setuptools wheel
52-
pip install -r requirements_test.txt -r requirements_commit.txt
51+
pip install uv
52+
uv pip install -U pip setuptools wheel
53+
uv pip install -r requirements_test.txt -r requirements_commit.txt
5354
- name: Restore pre-commit environment from cache
5455
id: cache-precommit
5556
uses: actions/cache@v4
@@ -97,20 +98,15 @@ jobs:
9798
- name: Ruff (check)
9899
run: |
99100
. venv/bin/activate
100-
#ruff plugwise_usb/*py tests/*py
101-
echo "***"
102-
echo "***"
103-
echo "Code is not up to par for ruff, skipping"
104-
echo "***"
105-
echo "***"
101+
ruff check plugwise_usb/ tests/
106102
- name: If needed, commit ruff changes to the pull request
107103
if: failure()
108104
run: |
109105
. venv/bin/activate
110-
ruff --fix plugwise_usb/*py tests/*py
106+
ruff format plugwise_usb/ tests/
111107
git config --global user.name 'autoruff'
112108
git config --global user.email '[email protected]'
113-
git remote set-url origin https://x-access-token:${{ secrets.PAT_CT }}@github.com/$GITHUB_REPOSITORY
109+
git remote set-url origin https://x-access-token:${{ secrets.PAT_CT_PYPLUSB }}@github.com/$GITHUB_REPOSITORY
114110
git checkout $GITHUB_HEAD_REF
115111
git commit -am "fixup: ${GITHUB_REF##*/} Python code reformatted using Ruff"
116112
git push origin ${GITHUB_REF##*/}
@@ -161,6 +157,11 @@ jobs:
161157
run: |
162158
. venv/bin/activate
163159
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual pylint
160+
- name: Biome lint
161+
run: |
162+
. venv/bin/activate
163+
mkdir -p ./tmp && curl -sL "https://github.com/biomejs/biome/releases/latest/download/biome-linux-x64" -o ./tmp/biome && chmod +x ./tmp/biome
164+
pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual biome
164165
- name: Lint markdown files
165166
run: |
166167
. venv/bin/activate
@@ -199,11 +200,12 @@ jobs:
199200
run: |
200201
python -m venv venv
201202
. venv/bin/activate
202-
pip install -U pip setuptools wheel
203+
pip install uv
204+
uv pip install -U pip setuptools wheel
203205
#pip install -r requirements_test.txt
204206
# 20220124 Mimic setup_test.sh
205-
pip install --upgrade -r requirements_test.txt -c https://raw.githubusercontent.com/home-assistant/core/dev/homeassistant/package_constraints.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test_pre_commit.txt
206-
pip install --upgrade pytest-asyncio
207+
uv pip install --upgrade -r requirements_test.txt -c https://raw.githubusercontent.com/home-assistant/core/dev/homeassistant/package_constraints.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test.txt -r https://raw.githubusercontent.com/home-assistant/core/dev/requirements_test_pre_commit.txt
208+
uv pip install --upgrade pytest-asyncio
207209
208210
pytest:
209211
runs-on: ubuntu-latest
@@ -279,11 +281,11 @@ jobs:
279281
- name: Run mypy
280282
run: |
281283
. venv/bin/activate
282-
pip list | grep -i mypy
284+
uv pip list | grep -i mypy
283285
#mypy plugwise_usb/
284286
echo "***"
285287
echo "***"
286-
echo "Code is not up to par for mypy, skipping"
288+
echo "Code is not up to par for mypy, skipping - see #171"
287289
echo "***"
288290
echo "***"
289291

.pre-commit-config.yaml

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
# For pre-commit.ci
2-
ci:
3-
# Defer autoupdate to quarterly (there is no 'off' button) to have renovate pick up first
4-
autoupdate_schedule: quarterly
5-
skip: [pylint, markdownlint, testing]
6-
submodules: true
7-
81
default_language_version:
92
# force all unspecified python hooks to run python3
103
python: python3.13
114

125
repos:
136
# Run manually in CI skipping the branch checks
14-
# RUFF disabled, code is not up to par with HA standards
15-
# - repo: https://github.com/astral-sh/ruff-pre-commit
16-
# rev: v0.1.7
17-
# hooks:
18-
# - id: ruff
19-
# args:
20-
# - --fix
21-
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
rev: v0.11.13
9+
hooks:
10+
- id: ruff
11+
name: "Ruff check"
12+
args:
13+
- --fix
14+
- id: ruff-format
15+
name: "Ruff format"
2216
- repo: https://github.com/pre-commit/pre-commit-hooks
2317
rev: v5.0.0
2418
hooks:
2519
- id: check-executables-have-shebangs
20+
name: "Checking executables"
2621
stages: [manual]
2722
- id: no-commit-to-branch
23+
name: "Verifying branch"
2824
args:
2925
- --branch=main
3026
- repo: https://github.com/asottile/pyupgrade
3127
rev: v3.20.0
3228
hooks:
3329
- id: pyupgrade
30+
name: "Checking pyupgrade"
3431
args: [--py39-plus]
35-
# Moved codespell configuration to setup.cfg as per 'all-files' issues not reading args
3632
- repo: https://github.com/codespell-project/codespell
3733
rev: v2.4.1
3834
hooks:
3935
- id: codespell
36+
name: "Check Code Spelling"
37+
args:
38+
- --ignore-words-list=aiport,astroid,checkin,currenty,hass,iif,incomfort,lookin,nam,NotIn # Previous list, remove before merge # - ignore-words-list = additionals,alle,alot,ba,bre,bund,currenty,datas,dof,dur,ether,farenheit,falsy,fo,haa,hass,hist,iam,iff,iif,incomfort,ines,ist,leeg,lightsensor,mut,nam,nd,pres,pullrequests,referer,resset,rime,ser,serie,sur,te,technik,ue,uint,unsecure,visability,wan,wanna,withing,zar
39+
- --skip="./.*,*.csv,*.json,*.ambr"
40+
- --quiet-level=2
4041
exclude_types: [csv, json]
4142
- repo: https://github.com/PyCQA/bandit
4243
rev: 1.8.5
4344
hooks:
4445
- id: bandit
46+
name: "Bandit checking"
4547
args:
4648
- --quiet
4749
- --format=custom
@@ -51,57 +53,73 @@ repos:
5153
rev: v1.37.1
5254
hooks:
5355
- id: yamllint
56+
name: "YAML linting"
5457
- repo: https://github.com/biomejs/pre-commit
5558
rev: v1.9.4
5659
hooks:
5760
- id: biome-lint
58-
additional_dependencies: ["@biomejs/[email protected]"]
5961
name: "Verifying/updating code with biome (improved prettier)"
62+
additional_dependencies: ["@biomejs/[email protected]"]
6063
- repo: https://github.com/cdce8p/python-typing-update
6164
rev: v0.7.2
6265
hooks:
6366
# Run `python-typing-update` hook manually from time to time
6467
# to update python typing syntax.
6568
# Will require manual work, before submitting changes!
6669
- id: python-typing-update
70+
name: "Python typing"
6771
stages: [manual]
6872
args:
6973
- --py39-plus
7074
- --force
7175
- --keep-updates
7276
files: ^(plugwise_usb|tests)/.+\.py$
77+
- repo: https://github.com/shellcheck-py/shellcheck-py
78+
rev: v0.10.0.1
79+
hooks:
80+
- id: shellcheck
81+
name: "Shell checking"
82+
args:
83+
- --external-sources
7384
- repo: local
7485
hooks:
7586
# Run mypy through our wrapper script in order to get the possible
7687
# pyenv and/or virtualenv activated; it may not have been e.g. if
7788
# committing from a GUI tool that was not launched from an activated
7889
# shell.
79-
- id: userdata
80-
name: userdata
81-
entry: scripts/pre-commit.sh
90+
- id: setup
91+
name: "Setup"
92+
entry: /usr/bin/env bash -c 'test -d ./venv || scripts/setup.sh'
93+
language: script
94+
- id: setup_test
95+
name: "Setup (extended for testing"
96+
entry: /usr/bin/env bash -c 'test -f ./tmp/biome || scripts/setup_test.sh pre-commit'
8297
language: script
83-
types: [python]
84-
pass_filenames: false
8598
- id: mypy
86-
name: mypy
99+
name: "Running MyPy"
87100
entry: scripts/run-in-env.sh mypy
88101
language: script
89102
types: [python]
90103
require_serial: true
91104
files: ^plugwise_usb/$
92105
- id: pylint
93-
name: pylint
106+
name: "PyLinting"
94107
entry: scripts/run-in-env.sh pylint -j 0
95108
language: script
96109
types: [python]
97110
files: ^plugwise_usb/.+\.py$
98111
- id: testing
99-
name: "Local Testing - Performing Tests"
112+
name: "Performing Tests"
100113
# yamllint disable-line rule:line-length
101-
entry: /usr/bin/env bash -c 'exec env GITHUB_ACTIONS="1" scripts/tests_and_coverage.sh test_and_coverage'
114+
entry: /usr/bin/env bash -c 'exec env GITHUB_ACTIONS="1" NO_FIXTURES="1" scripts/tests_and_coverage.sh test_and_coverage'
102115
language: script
103116
pass_filenames: false
117+
- id: biome
118+
name: "Biome (prettier)"
119+
entry: ./tmp/biome check plugwise_usb/ tests/ --files-ignore-unknown=true --no-errors-on-unmatched --json-formatter-indent-width=2 --json-formatter-indent-style=space
120+
language: script
104121
- repo: https://github.com/igorshubovych/markdownlint-cli
105122
rev: v0.45.0
106123
hooks:
107124
- id: markdownlint
125+
name: "Markdown linting"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Ongoing
44

55
- PR [#261](https://github.com/plugwise/python-plugwise-usb/pull/261): Sense: bugfix parsing of humidity value as an unsigned int
6+
- Maintenance chores and re-instatement of ruff, deprecate pre-commit cloud runs (just leveraging renovate)
67

78
## v0.44.3 - 2025-06-12
89

0 commit comments

Comments
 (0)