Skip to content

Commit 31a1c0e

Browse files
authored
Merge pull request #327 from kratz00/ruff
ruff: Simplifying Python linter usage
2 parents 3bd21c0 + 414c78c commit 31a1c0e

22 files changed

+131
-164
lines changed

.flake8

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

.lycheeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
http://camera.local/latest.jpg
22
https://github/*
3+
https://megalinter.io/configuration/

.mega-linter.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ DISABLE_LINTERS:
1010
- SPELL_CSPELL
1111
- MARKDOWN_MARKDOWN_LINK_CHECK
1212
- REPOSITORY_CHECKOV
13+
- PYTHON_BLACK
14+
- PYTHON_FLAKE8
15+
- PYTHON_ISORT
1316
- PYTHON_MYPY
1417
- PYTHON_PYRIGHT
1518
- MAKEFILE_CHECKMAKE

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ repos:
3333
- "--fix"
3434
# Run the formatter.
3535
- id: ruff-format
36-
- repo: https://github.com/pycqa/flake8
37-
rev: 7.1.2
38-
hooks:
39-
- id: flake8
4036
- repo: https://github.com/thlorenz/doctoc
4137
rev: v2.2.0
4238
hooks:

.ruff.toml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Exclude a variety of commonly ignored directories.
2+
exclude = [
3+
".bzr",
4+
".direnv",
5+
".eggs",
6+
".git",
7+
".git-rewrite",
8+
".hg",
9+
".ipynb_checkpoints",
10+
".mypy_cache",
11+
".nox",
12+
".pants.d",
13+
".pyenv",
14+
".pytest_cache",
15+
".pytype",
16+
".ruff_cache",
17+
".svn",
18+
".tox",
19+
".venv",
20+
".vscode",
21+
"__pypackages__",
22+
"_build",
23+
"buck-out",
24+
"build",
25+
"dist",
26+
"node_modules",
27+
"site-packages",
28+
"venv",
29+
]
30+
31+
# Same as Black.
32+
line-length = 132
33+
indent-width = 4
34+
35+
# Assume Python 3.10
36+
target-version = "py310"
37+
38+
[lint]
39+
# See https://docs.astral.sh/ruff/rules/
40+
select = [
41+
# flake8-bugbear
42+
"B",
43+
# pycodestyle Error
44+
"E",
45+
# Pyflakes
46+
"F",
47+
# isort
48+
"I",
49+
# flake8-simplify
50+
"SIM",
51+
# pyupgrade
52+
"UP",
53+
# pycodestyle Warning
54+
"W"
55+
]
56+
ignore = ["UP007"]
57+
58+
# Allow fix for all enabled rules (when `--fix`) is provided.
59+
fixable = ["ALL"]
60+
unfixable = []
61+
62+
# Allow unused variables when underscore-prefixed.
63+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
64+
65+
[format]
66+
# Like Black, use double quotes for strings.
67+
quote-style = "double"
68+
69+
# Like Black, indent with spaces, rather than tabs.
70+
indent-style = "space"
71+
72+
# Like Black, respect magic trailing commas.
73+
skip-magic-trailing-comma = false
74+
75+
# Like Black, automatically detect the appropriate line ending.
76+
line-ending = "auto"

ha_mqtt_discoverable/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
import json
1616
import logging
1717
import ssl
18+
from collections.abc import Callable
1819
from importlib import metadata
19-
from typing import Any, Callable, Generic, Optional, TypeVar, Union
20+
from typing import Any, Generic, Optional, TypeVar, Union
2021

2122
import paho.mqtt.client as mqtt
2223
from paho.mqtt.client import MQTTMessageInfo

ha_mqtt_discoverable/sensors.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
import logging
2121
from typing import Any, Optional
2222

23+
from pydantic import Field
24+
2325
from ha_mqtt_discoverable import (
2426
DeviceInfo,
2527
Discoverable,
2628
EntityInfo,
2729
Subscriber,
2830
)
29-
from pydantic import Field
3031

3132
logger = logging.getLogger(__name__)
3233

@@ -315,10 +316,7 @@ def update_state(self, state: bool) -> None:
315316
Args:
316317
state(bool): What state to set the sensor to
317318
"""
318-
if state:
319-
state_message = self._entity.payload_on
320-
else:
321-
state_message = self._entity.payload_off
319+
state_message = self._entity.payload_on if state else self._entity.payload_off
322320
logger.info(f"Setting {self._entity.name} to {state_message} using {self.state_topic}")
323321
self._state_helper(state=state_message)
324322

ha_mqtt_discoverable/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import re
1818

1919
import yaml
20+
2021
from ha_mqtt_discoverable import CONFIGURATION_KEY_NAMES
2122

2223

poetry.lock

Lines changed: 20 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,79 +19,14 @@ packages = [{include = "ha_mqtt_discoverable"}]
1919

2020
[tool.poetry.group.dev.dependencies]
2121
pytest = ">=7.2.2,<9.0.0"
22-
flake8 = ">=6,<8"
2322
pre-commit = "^4.0.1"
24-
ruff = ">=0.6.8,<0.10.0"
23+
ruff = "^0.9.10"
2524

2625

2726
[tool.poetry.group.test.dependencies]
2827
pytest-mock = "^3.10.0"
2928

3029

31-
[tool.ruff]
32-
# Exclude a variety of commonly ignored directories.
33-
exclude = [
34-
".bzr",
35-
".direnv",
36-
".eggs",
37-
".git",
38-
".git-rewrite",
39-
".hg",
40-
".ipynb_checkpoints",
41-
".mypy_cache",
42-
".nox",
43-
".pants.d",
44-
".pyenv",
45-
".pytest_cache",
46-
".pytype",
47-
".ruff_cache",
48-
".svn",
49-
".tox",
50-
".venv",
51-
".vscode",
52-
"__pypackages__",
53-
"_build",
54-
"buck-out",
55-
"build",
56-
"dist",
57-
"node_modules",
58-
"site-packages",
59-
"venv",
60-
]
61-
62-
# Same as Black.
63-
line-length = 132
64-
indent-width = 4
65-
66-
# Assume Python 3.10
67-
target-version = "py310"
68-
69-
[tool.ruff.lint]
70-
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
71-
select = ["E4", "E7", "E9", "F"]
72-
ignore = []
73-
74-
# Allow fix for all enabled rules (when `--fix`) is provided.
75-
fixable = ["ALL"]
76-
unfixable = []
77-
78-
# Allow unused variables when underscore-prefixed.
79-
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
80-
81-
[tool.ruff.format]
82-
# Like Black, use double quotes for strings.
83-
quote-style = "double"
84-
85-
# Like Black, indent with spaces, rather than tabs.
86-
indent-style = "space"
87-
88-
# Like Black, respect magic trailing commas.
89-
skip-magic-trailing-comma = false
90-
91-
# Like Black, automatically detect the appropriate line ending.
92-
line-ending = "auto"
93-
94-
9530
[build-system]
9631
requires = ["poetry-core>=2.0"]
9732
build-backend = "poetry.core.masonry.api"

tests/test_binary_sensor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515
#
1616
import pytest
17+
1718
from ha_mqtt_discoverable import Settings
1819
from ha_mqtt_discoverable.sensors import BinarySensor, BinarySensorInfo
1920

tests/test_button.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515
#
1616
import pytest
17+
1718
from ha_mqtt_discoverable import Settings
1819
from ha_mqtt_discoverable.sensors import Button, ButtonInfo
1920

0 commit comments

Comments
 (0)