Skip to content

Commit 0ec03b4

Browse files
authored
Use more ruff instead of flake8 and pyupgrade (#358)
1 parent 2ed5506 commit 0ec03b4

8 files changed

+38
-46
lines changed

.pre-commit-config.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ repos:
77
additional_dependencies:
88
- tomli
99
exclude_types: [csv, json]
10-
- repo: https://github.com/asottile/pyupgrade
11-
rev: v3.15.0
12-
hooks:
13-
- id: pyupgrade
14-
args: [--py39-plus]
15-
- repo: https://github.com/pycqa/flake8
16-
rev: 6.1.0
17-
hooks:
18-
- id: flake8
19-
files: ^(xknxproject|examples|docs)/.+\.py$
2010
- repo: https://github.com/charliermarsh/ruff-pre-commit
2111
# Ruff version.
2212
rev: 'v0.1.11'

pyproject.toml

+30-14
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,42 @@ output-format = "colorized"
103103
testpaths = "test"
104104

105105
[tool.ruff]
106-
target-version = "py39"
107-
select = [
108-
"C4", # comprehensions
109-
"D", # pydocstyle
110-
"E", # pycodestyle
111-
"F", # pyflakes
112-
"I", # isort
113-
"RUF", # ruff specific
114-
"T20", # print
115-
"UP", # pyupgrade
116-
"W", # pydocstyle warning
106+
lint.select = [
107+
"A", # builtins shadowing
108+
"ASYNC", # async
109+
"B", # bugbear
110+
"C4", # comprehensions
111+
"D", # pydocstyle
112+
"E", # pycodestyle
113+
"F", # pyflakes
114+
"G", # logging
115+
"I", # isort
116+
"LOG", # logging
117+
"PTH", # pathlib
118+
"RUF", # ruff specific
119+
"SLF", # private member access
120+
"SIM", # simplify
121+
"T20", # print
122+
"UP", # pyupgrade
123+
"W", # pydocstyle warning
117124
]
118-
ignore = [
125+
lint.ignore = [
119126
"D202",
120127
"D203",
121128
"D212",
122-
"E501", # line too long
129+
"E501", # line too long
130+
"SIM102", # collapsible-if
131+
"SIM105", #suppressible-exception
123132
]
124133
extend-exclude = ["script"]
125134

126-
[tool.ruff.isort]
135+
[tool.ruff.lint.isort]
127136
force-sort-within-sections = true
128137
combine-as-imports = true
138+
139+
[tool.ruff.lint.per-file-ignores]
140+
"test/*" = [
141+
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
142+
"SLF", # private member access
143+
"SIM117", # multiple-with-statements
144+
]

requirements_testing.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-r requirements_production.txt
22
pre-commit==3.6.0
3-
flake8==7.0.0
43
pylint==3.0.3
54
pytest==8.0.0
65
pytest-cov==4.1.0

setup.cfg

-13
This file was deleted.

test/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ def remove_xknxproject_version(obj: KNXProject) -> KNXProject:
1515
assert len(version_string.split(".")) == 3
1616
return obj
1717

18-
with open(stub_path, encoding="utf-8") as stub_file:
18+
with stub_path.open(encoding="utf-8") as stub_file:
1919
stub = remove_xknxproject_version(json.load(stub_file))
2020
to_be_verified = remove_xknxproject_version(to_be_verified)
2121
for key, value in stub.items():
2222
assert key in to_be_verified, f"`{key}` key missing in generated object"
2323
assert value == to_be_verified[key], f"`{key}` item does not match"
2424

25-
for key in to_be_verified.keys():
25+
for key in to_be_verified:
2626
assert key in stub, f"`{key}` key of generated object missing in stub"

tox.ini

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ wheel_build_env = .pkg
2222
basepython = python3
2323
commands =
2424
pre-commit run codespell {posargs: --all-files}
25-
pre-commit run flake8 {posargs: --all-files}
26-
pre-commit run pyupgrade {posargs: --all-files}
2725
pre-commit run check-json {posargs: --all-files}
2826
pre-commit run trailing-whitespace {posargs: --all-files}
2927

xknxproject/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ def parse_dpt_types(dpt_string: str | None) -> list[DPTType]:
3030
for _dpt in dict.fromkeys(dpt_string.split()):
3131
dpt_parts = _dpt.split("-")
3232
try:
33-
if MAIN_DPT == dpt_parts[0]:
33+
if dpt_parts[0] == MAIN_DPT:
3434
supported_dpts.append(
3535
DPTType(
3636
main=int(dpt_parts[1]),
3737
sub=None,
3838
)
3939
)
40-
if MAIN_AND_SUB_DPT == dpt_parts[0]:
40+
if dpt_parts[0] == MAIN_AND_SUB_DPT:
4141
supported_dpts.append(
4242
DPTType(
4343
main=int(dpt_parts[1]),

xknxproject/zip/extractor.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ def _get_xml_namespace(project_zip: ZipFile) -> str:
152152
namespace = namespace_match.group(1) # type: ignore[union-attr]
153153
except (AttributeError, IndexError, UnicodeDecodeError):
154154
_LOGGER.error("Could not parse XML namespace from %s", line)
155-
raise UnexpectedFileContent("Could not parse XML namespace.")
155+
raise UnexpectedFileContent(
156+
"Could not parse XML namespace."
157+
) from None
156158

157159
_LOGGER.debug("Namespace: %s", namespace)
158160
return namespace
@@ -164,7 +166,7 @@ def _get_schema_version(namespace: str) -> int:
164166
schema_version = int(namespace.split("/")[-1])
165167
except ValueError:
166168
_LOGGER.error("Could not parse schema version from %s", namespace)
167-
raise UnexpectedFileContent("Could not parse schema version.")
169+
raise UnexpectedFileContent("Could not parse schema version.") from None
168170

169171
_LOGGER.debug("Schema version: %s", schema_version)
170172
return schema_version

0 commit comments

Comments
 (0)