Skip to content

Commit f22f4ab

Browse files
committed
Chore: Format code using Ruff. Phase out Black and isort.
1 parent ff9e8d1 commit f22f4ab

File tree

4 files changed

+64
-58
lines changed

4 files changed

+64
-58
lines changed

pyproject.toml

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ name = "pytest-mqtt"
99
version = "0.4.2"
1010
description = "pytest-mqtt supports testing systems based on MQTT"
1111
readme = "README.rst"
12-
requires-python = ">=3.7"
13-
license = {text = "MIT"}
14-
keywords = ["mqtt", "pytest", "testing", "mosquitto", "paho"]
12+
keywords = [ "mosquitto", "mqtt", "paho", "pytest", "testing" ]
13+
license = { text = "MIT" }
1514
authors = [
16-
{name = "Andreas Motl", email = "andreas.motl@panodata.org"},
17-
{name = "Richard Pobering", email = "richard.pobering@panodata.org"},
15+
{ name = "Andreas Motl", email = "andreas.motl@panodata.org" },
16+
{ name = "Richard Pobering", email = "richard.pobering@panodata.org" },
1817
]
18+
requires-python = ">=3.7"
1919
classifiers = [
2020
"Development Status :: 5 - Production/Stable",
2121
"Environment :: Console",
@@ -33,6 +33,7 @@ classifiers = [
3333
"Operating System :: POSIX :: Linux",
3434
"Operating System :: Unix",
3535
"Programming Language :: Python",
36+
"Programming Language :: Python :: 3 :: Only",
3637
"Programming Language :: Python :: 3.7",
3738
"Programming Language :: Python :: 3.8",
3839
"Programming Language :: Python :: 3.9",
@@ -61,79 +62,79 @@ dependencies = [
6162
"pytest-docker-fixtures<2",
6263
]
6364

64-
[project.entry-points.pytest11]
65-
capmqtt = "pytest_mqtt.capmqtt"
66-
mosquitto = "pytest_mqtt.mosquitto"
67-
68-
[project.optional-dependencies]
69-
test = [
70-
"coverage<8",
71-
"pytest<9",
72-
"pytest-fixture-order<1",
73-
"pytest-ordering<1",
74-
]
75-
develop = [
76-
"isort<6",
77-
"black<25",
65+
optional-dependencies.develop = [
66+
"mypy<1.12",
7867
"poethepoet<1",
68+
"pyproject-fmt<3",
7969
"ruff<0.9",
70+
"validate-pyproject<0.19",
8071
]
81-
release = [
72+
optional-dependencies.release = [
8273
"build<2",
8374
"twine<7",
8475
]
76+
optional-dependencies.test = [
77+
"coverage<8",
78+
"pytest<9",
79+
"pytest-fixture-order<1",
80+
"pytest-ordering<1",
81+
]
82+
urls.changelog = "https://github.com/mqtt-tools/pytest-mqtt/blob/main/CHANGES.rst"
83+
urls.documentation = "https://github.com/mqtt-tools/pytest-mqtt"
84+
urls.homepage = "https://github.com/mqtt-tools/pytest-mqtt"
85+
urls.repository = "https://github.com/mqtt-tools/pytest-mqtt"
86+
entry-points.pytest11.capmqtt = "pytest_mqtt.capmqtt"
87+
entry-points.pytest11.mosquitto = "pytest_mqtt.mosquitto"
8588

8689
[tool.setuptools]
8790
# https://setuptools.pypa.io/en/latest/userguide/package_discovery.html
88-
packages = ["pytest_mqtt"]
89-
90-
[project.urls]
91-
homepage = "https://github.com/mqtt-tools/pytest-mqtt"
92-
documentation = "https://github.com/mqtt-tools/pytest-mqtt"
93-
repository = "https://github.com/mqtt-tools/pytest-mqtt"
94-
changelog = "https://github.com/mqtt-tools/pytest-mqtt/blob/main/CHANGES.rst"
95-
91+
packages = [ "pytest_mqtt" ]
9692

9793
# ==================
9894
# Tool configuration
9995
# ==================
96+
# Configuration snippets for pytest, coverage, and ruff.
10097

101-
# Configuration snippets for Black, isort, pytest, coverage, and ruff.
102-
103-
[tool.black]
98+
[tool.ruff]
10499
line-length = 120
105100

106-
[tool.isort]
107-
profile = "black"
108-
skip_glob = "**/site-packages/**"
109-
skip_gitignore = false
110-
# src_paths = ["pytest_mqtt", "testing"]
111-
112101
[tool.pytest.ini_options]
113102
minversion = "2.0"
114103
addopts = """
115104
-rfEX -p pytester --strict-markers --verbosity=3
116105
"""
117106
log_level = "DEBUG"
118107
log_cli_level = "DEBUG"
119-
testpaths = ["testing"]
108+
testpaths = [ "testing" ]
120109
xfail_strict = true
121110
markers = [
122111
"capmqtt_decode_utf8: Capture MQTT messages as `str`, not `bytes`",
123112
]
124113

125114
[tool.coverage.run]
126115
branch = false
127-
source = ["pytest_mqtt"]
116+
source = [ "pytest_mqtt" ]
128117

129118
[tool.coverage.report]
130119
fail_under = 0
131120
show_missing = true
132121
omit = [
133122
]
134123

135-
[tool.ruff]
136-
line-length = 120
124+
[tool.mypy]
125+
packages = [ "pytest_mqtt" ]
126+
exclude = [
127+
]
128+
ignore_missing_imports = true
129+
check_untyped_defs = false
130+
implicit_optional = true
131+
install_types = true
132+
no_implicit_optional = true
133+
non_interactive = true
134+
show_error_codes = true
135+
strict_equality = true
136+
warn_unused_ignores = true
137+
warn_redundant_casts = true
137138

138139

139140
# ===================
@@ -148,25 +149,30 @@ check = [
148149
]
149150

150151
format = [
151-
{cmd="black ."},
152-
{cmd="isort pytest_mqtt testing"},
152+
{ cmd = "ruff format ." },
153+
# Configure Ruff not to auto-fix (remove!):
154+
# unused imports (F401), unused variables (F841), `print` statements (T201), and commented-out code (ERA001).
155+
{ cmd = "ruff check --fix --ignore=ERA --ignore=F401 --ignore=F841 --ignore=T20 --ignore=ERA001 ." },
156+
{ cmd = "pyproject-fmt --keep-full-version pyproject.toml" },
153157
]
158+
154159
lint = [
155-
{cmd="ruff check ."},
156-
{cmd="black --check ."},
157-
{cmd="isort --check pytest_mqtt testing"},
160+
{ cmd = "ruff format --check ." },
161+
{ cmd = "ruff check ." },
162+
{ cmd = "validate-pyproject pyproject.toml" },
163+
{ cmd = "mypy" },
158164
]
159165

160166
# When testing a pytest plugin, `coverage` needs to be
161167
# started before `pytest`. `pytest-cov` will not work.
162168
# https://stackoverflow.com/a/62224494
163169
test = [
164-
{cmd="coverage run -m pytest"},
165-
{cmd="coverage report"},
166-
{cmd="coverage xml"},
170+
{ cmd = "coverage run -m pytest" },
171+
{ cmd = "coverage report" },
172+
{ cmd = "coverage xml" },
167173
]
168174

169175
release = [
170-
{cmd="python -m build"},
171-
{cmd="twine upload --skip-existing dist/*.tar.gz dist/*.whl"},
176+
{ cmd = "python -m build" },
177+
{ cmd = "twine upload --skip-existing dist/*.tar.gz dist/*.whl" },
172178
]

pytest_mqtt/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
try:
22
from importlib.metadata import PackageNotFoundError, version # noqa
3-
except ImportError: # pragma:nocover
4-
from importlib_metadata import PackageNotFoundError, version # noqa
3+
except ImportError: # pragma: no cover
4+
from importlib_metadata import PackageNotFoundError, version # type: ignore[no-redef] # noqa
55

6-
from .model import MqttMessage # noqa:F401
6+
from .model import MqttMessage # noqa: F401
77

88
try:
99
__version__ = version("pytest-mqtt")

pytest_mqtt/capmqtt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
.. _Paho MQTT Python Client: https://github.com/eclipse/paho.mqtt.python
1515
"""
16+
1617
import logging
1718
import threading
1819
import typing as t
@@ -94,7 +95,7 @@ class MqttCaptureFixture:
9495
def __init__(self, decode_utf8: t.Optional[bool], host: str = "localhost", port: int = 1883) -> None:
9596
"""Creates a new funcarg."""
9697
self._buffer: t.List[MqttMessage] = []
97-
self._decode_utf8: bool = decode_utf8
98+
self._decode_utf8: bool = decode_utf8 or False
9899

99100
self.mqtt_client = MqttClientAdapter(on_message_callback=self.on_message, host=host, port=port)
100101
self.mqtt_client.start()
@@ -124,7 +125,7 @@ def messages(self) -> t.List[MqttMessage]:
124125
return self._buffer
125126

126127
@property
127-
def records(self) -> t.List[t.Tuple[str, t.Union[str, bytes], t.Dict]]:
128+
def records(self) -> t.List[t.Tuple[str, t.Union[str, bytes], t.Union[t.Dict, None]]]:
128129
return [(item.topic, item.payload, item.userdata) for item in self._buffer]
129130

130131
def publish(self, topic: str, payload: str, **kwargs) -> mqtt.MQTTMessageInfo:

pytest_mqtt/mosquitto.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
1515
.. _Mosquitto: https://github.com/eclipse/mosquitto
1616
"""
17+
1718
import os
1819

1920
import docker
@@ -36,7 +37,6 @@
3637

3738

3839
class Mosquitto(BaseImage):
39-
4040
name = "mosquitto"
4141

4242
def __init__(self, host: str = "localhost", port: int = 1883) -> None:
@@ -96,7 +96,6 @@ def mqtt_settings(pytestconfig) -> MqttSettings:
9696

9797
@pytest.fixture(scope="session")
9898
def mosquitto(mqtt_settings: MqttSettings):
99-
10099
host, port = mqtt_settings.host, mqtt_settings.port
101100

102101
# Gracefully skip spinning up the Docker container if Mosquitto is already running.

0 commit comments

Comments
 (0)