Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ruff for formatting #1980

Merged
merged 3 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 4 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,17 @@ jobs:
python-version: ["3.12"]

steps:
- uses: "actions/checkout@v3"
- uses: "actions/checkout@v4"
- uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: |
python -m pip install --upgrade pip poetry
poetry install --extras docs
- name: "Run pyupgrade"
- name: "Run pre-commit hooks"
run: |
poetry run pre-commit run pyupgrade --all-files
- name: "Code formating (black)"
run: |
poetry run pre-commit run black --all-files
- name: "Code formating (flake8)"
run: |
poetry run pre-commit run flake8 --all-files
- name: "Order of imports (isort)"
run: |
poetry run pre-commit run isort --all-files
# - name: "Docstring formating (docformatter)"
# run: |
# poetry run pre-commit run docformatter --all-files
- name: "Potential security issues (bandit)"
run: |
poetry run pre-commit run bandit --all-files
- name: "Documentation build (sphinx)"
run: |
poetry run sphinx-build docs/ generated_docs
- name: "Typing checks (mypy)"
run: |
poetry run pre-commit run mypy --all-files
poetry run pre-commit run --all-files --verbose

tests:
name: "Python ${{ matrix.python-version}} on ${{ matrix.os }}"
Expand All @@ -61,14 +40,9 @@ jobs:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9"]
os: [ubuntu-latest, macos-latest, windows-latest]
# Exclude example, in case needed again in the future:
# exclude:
# - python-version: pypy3.8
# os: macos-latest


steps:
- uses: "actions/checkout@v3"
- uses: "actions/checkout@v4"
- uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
Expand Down
13 changes: 9 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ repos:
- id: debug-statements
- id: check-ast

- repo: https://github.com/psf/black
rev: 24.2.0

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.1
hooks:
- id: black
language_version: python3
# Run the linter.
#- id: ruff
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Status](https://github.com/rytilahti/python-miio/actions/workflows/ci.yml/badge.
[![Coverage
Status](https://codecov.io/gh/rytilahti/python-miio/branch/master/graph/badge.svg?token=lYKWubxkLU)](https://codecov.io/gh/rytilahti/python-miio)
[![Documentation status](https://readthedocs.org/projects/python-miio/badge/?version=latest)](https://python-miio.readthedocs.io/en/latest/?badge=latest)
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

This library (and its accompanying cli tool, `miiocli`) can be used to control devices using Xiaomi's
[miIO](https://github.com/OpenMiHome/mihome-binary-protocol/blob/master/doc/PROTOCOL.md)
Expand Down
4 changes: 3 additions & 1 deletion miio/extract_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def decrypt_ztoken(ztoken):
keystring = "00000000000000000000000000000000"
key = bytes.fromhex(keystring)
cipher = Cipher(
algorithms.AES(key), modes.ECB(), backend=default_backend() # nosec
algorithms.AES(key),
modes.ECB(), # nosec
backend=default_backend(),
)
decryptor = cipher.decryptor()
token = decryptor.update(bytes.fromhex(ztoken[:64])) + decryptor.finalize()
Expand Down
4 changes: 2 additions & 2 deletions miio/integrations/lumi/acpartner/airconditioningcompanion.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ def send_ir_code(self, model: str, code: str, slot: int = 0):
command_bytes = (
code_bytes[0:1]
+ model_bytes[2:8]
+ b"\x94\x70\x1F\xFF"
+ b"\x94\x70\x1f\xff"
+ slot_bytes
+ b"\xFF"
+ b"\xff"
+ code_bytes[13:16]
+ b"\x27"
)
Expand Down
2 changes: 1 addition & 1 deletion miio/miioprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def send(
parameters: Optional[Any] = None,
retry_count: int = 3,
*,
extra_parameters: Optional[dict] = None
extra_parameters: Optional[dict] = None,
) -> Any:
"""Build and send the given command. Note that this will implicitly call
:func:`send_handshake` to do a handshake, and will re-try in case of errors
Expand Down
4 changes: 1 addition & 3 deletions miio/push_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@
command = f"{self.server_model}.{info.action}:{source_id}"
key = f"event.{info.source_model}.{info.event}"
message_id = 0
magic_number = randint(
1590161094, 1642025774
) # nosec, min/max taken from packet captures, unknown use
magic_number = randint(1590161094, 1642025774) # nosec, min/max taken from packet captures, unknown use

Check warning on line 256 in miio/push_server/server.py

View check run for this annotation

Codecov / codecov/patch

miio/push_server/server.py#L256

Added line #L256 was not covered by tests

if len(command) > 49:
_LOGGER.error(
Expand Down
Loading