Skip to content

Commit ff46761

Browse files
authored
Use ruff for formatting (#1980)
Also, simplify the CI pipeline to use pre-commit instead of individual checks
1 parent 2dc6faf commit ff46761

File tree

7 files changed

+20
-42
lines changed

7 files changed

+20
-42
lines changed

.github/workflows/ci.yml

+4-30
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,17 @@ jobs:
1818
python-version: ["3.12"]
1919

2020
steps:
21-
- uses: "actions/checkout@v3"
21+
- uses: "actions/checkout@v4"
2222
- uses: "actions/setup-python@v4"
2323
with:
2424
python-version: "${{ matrix.python-version }}"
2525
- name: "Install dependencies"
2626
run: |
2727
python -m pip install --upgrade pip poetry
2828
poetry install --extras docs
29-
- name: "Run pyupgrade"
29+
- name: "Run pre-commit hooks"
3030
run: |
31-
poetry run pre-commit run pyupgrade --all-files
32-
- name: "Code formating (black)"
33-
run: |
34-
poetry run pre-commit run black --all-files
35-
- name: "Code formating (flake8)"
36-
run: |
37-
poetry run pre-commit run flake8 --all-files
38-
- name: "Order of imports (isort)"
39-
run: |
40-
poetry run pre-commit run isort --all-files
41-
# - name: "Docstring formating (docformatter)"
42-
# run: |
43-
# poetry run pre-commit run docformatter --all-files
44-
- name: "Potential security issues (bandit)"
45-
run: |
46-
poetry run pre-commit run bandit --all-files
47-
- name: "Documentation build (sphinx)"
48-
run: |
49-
poetry run sphinx-build docs/ generated_docs
50-
- name: "Typing checks (mypy)"
51-
run: |
52-
poetry run pre-commit run mypy --all-files
31+
poetry run pre-commit run --all-files --verbose
5332
5433
tests:
5534
name: "Python ${{ matrix.python-version}} on ${{ matrix.os }}"
@@ -61,14 +40,9 @@ jobs:
6140
matrix:
6241
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9"]
6342
os: [ubuntu-latest, macos-latest, windows-latest]
64-
# Exclude example, in case needed again in the future:
65-
# exclude:
66-
# - python-version: pypy3.8
67-
# os: macos-latest
68-
6943

7044
steps:
71-
- uses: "actions/checkout@v3"
45+
- uses: "actions/checkout@v4"
7246
- uses: "actions/setup-python@v4"
7347
with:
7448
python-version: "${{ matrix.python-version }}"

.pre-commit-config.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ repos:
1111
- id: debug-statements
1212
- id: check-ast
1313

14-
- repo: https://github.com/psf/black
15-
rev: 24.2.0
14+
15+
repos:
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
# Ruff version.
18+
rev: v0.7.1
1619
hooks:
17-
- id: black
18-
language_version: python3
20+
# Run the linter.
21+
#- id: ruff
22+
# Run the formatter.
23+
- id: ruff-format
1924

2025
- repo: https://github.com/pre-commit/mirrors-isort
2126
rev: v5.10.1

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Status](https://github.com/rytilahti/python-miio/actions/workflows/ci.yml/badge.
1010
[![Coverage
1111
Status](https://codecov.io/gh/rytilahti/python-miio/branch/master/graph/badge.svg?token=lYKWubxkLU)](https://codecov.io/gh/rytilahti/python-miio)
1212
[![Documentation status](https://readthedocs.org/projects/python-miio/badge/?version=latest)](https://python-miio.readthedocs.io/en/latest/?badge=latest)
13-
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
1413

1514
This library (and its accompanying cli tool, `miiocli`) can be used to control devices using Xiaomi's
1615
[miIO](https://github.com/OpenMiHome/mihome-binary-protocol/blob/master/doc/PROTOCOL.md)

miio/extract_tokens.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def decrypt_ztoken(ztoken):
8181
keystring = "00000000000000000000000000000000"
8282
key = bytes.fromhex(keystring)
8383
cipher = Cipher(
84-
algorithms.AES(key), modes.ECB(), backend=default_backend() # nosec
84+
algorithms.AES(key),
85+
modes.ECB(), # nosec
86+
backend=default_backend(),
8587
)
8688
decryptor = cipher.decryptor()
8789
token = decryptor.update(bytes.fromhex(ztoken[:64])) + decryptor.finalize()

miio/integrations/lumi/acpartner/airconditioningcompanion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ def send_ir_code(self, model: str, code: str, slot: int = 0):
327327
command_bytes = (
328328
code_bytes[0:1]
329329
+ model_bytes[2:8]
330-
+ b"\x94\x70\x1F\xFF"
330+
+ b"\x94\x70\x1f\xff"
331331
+ slot_bytes
332-
+ b"\xFF"
332+
+ b"\xff"
333333
+ code_bytes[13:16]
334334
+ b"\x27"
335335
)

miio/miioprotocol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def send(
151151
parameters: Optional[Any] = None,
152152
retry_count: int = 3,
153153
*,
154-
extra_parameters: Optional[dict] = None
154+
extra_parameters: Optional[dict] = None,
155155
) -> Any:
156156
"""Build and send the given command. Note that this will implicitly call
157157
:func:`send_handshake` to do a handshake, and will re-try in case of errors

miio/push_server/server.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,7 @@ def _construct_event( # nosec
253253
command = f"{self.server_model}.{info.action}:{source_id}"
254254
key = f"event.{info.source_model}.{info.event}"
255255
message_id = 0
256-
magic_number = randint(
257-
1590161094, 1642025774
258-
) # nosec, min/max taken from packet captures, unknown use
256+
magic_number = randint(1590161094, 1642025774) # nosec, min/max taken from packet captures, unknown use
259257

260258
if len(command) > 49:
261259
_LOGGER.error(

0 commit comments

Comments
 (0)