Skip to content

Commit 0a99a5d

Browse files
authored
Readd ruff check for scripts, but allow print and missing docstring (#316)
* Reorder lint settings in ruff.toml to match order in HA-pyproject.toml * Also adds the pydocstyle and pytest-style-mark-parentheses = false (both from HA)
1 parent 2545e4b commit 0a99a5d

4 files changed

Lines changed: 32 additions & 25 deletions

File tree

.github/workflows/validate.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ jobs:
4848
uses: astral-sh/ruff-action@v3
4949
with:
5050
args: check --exit-zero # succeed despite errors until https://github.com/custom-components/zaptec/issues/258 is done
51-
src: >-
52-
custom_components/zaptec
53-
tests
51+
src: "."
5452

5553
manifest-requirements:
5654
name: Manifest requirements validation

.ruff.toml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
target-version = "py313"
44
line-length = 98
55

6-
[lint.per-file-ignores]
7-
"tests/**/*.py" = [
8-
"S101", # Allow assert in tests
9-
"INP001", # Don't complain over missing __init__.py in test dirs
10-
]
11-
126
[lint]
137
select = [
148
"ALL",
@@ -49,14 +43,29 @@ ignore = [
4943

5044
[lint.flake8-pytest-style]
5145
fixture-parentheses = false
46+
mark-parentheses = false
5247

5348
[lint.pyupgrade]
5449
keep-runtime-typing = true
5550

56-
[lint.mccabe]
57-
max-complexity = 25
58-
5951
[lint.isort]
6052
force-sort-within-sections = true
6153
combine-as-imports = true
6254
split-on-trailing-comma = false
55+
56+
[lint.per-file-ignores]
57+
"tests/**/*.py" = [
58+
"S101", # Allow assert in tests
59+
"INP001", # Don't complain over missing __init__.py in test dirs
60+
]
61+
"scripts/*" = [
62+
"D103", # Don't complain over missing docstrings in scripts
63+
"T201", # Allow for scripts to write to stdout
64+
]
65+
66+
[lint.mccabe]
67+
max-complexity = 25
68+
69+
[lint.pydocstyle]
70+
convention = "google"
71+
property-decorators = ["propcache.api.cached_property"]

scripts/check_requirements.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@
1818
PYPI_URL = "https://pypi.org/pypi/{package}/json"
1919

2020

21-
def load_manifest_requirements() -> list[Requirement]: # noqa: D103 (disable docstrings requirement)
21+
def load_manifest_requirements() -> list[Requirement]:
2222
with MANIFEST.open() as f:
2323
manifest = json.load(f)
2424
reqs: list[str] = manifest.get("requirements", [])
2525
return [Requirement(req) for req in reqs]
2626

2727

28-
def load_minimum_ha_version() -> Version: # noqa: D103
28+
def load_minimum_ha_version() -> Version:
2929
with HACS.open() as f:
3030
hacs = json.load(f)
3131
return Version(hacs.get("homeassistant", None))
3232

3333

34-
def load_relevant_constraints(url: str, reqs: list[Requirement]) -> dict[str, Requirement]: # noqa: D103
34+
def load_relevant_constraints(url: str, reqs: list[Requirement]) -> dict[str, Requirement]:
3535
names = [req.name for req in reqs]
3636
constraints: dict[str, Requirement] = {}
37-
with urllib.request.urlopen(url) as response:
37+
with urllib.request.urlopen(url) as response: # noqa: S310 (ignore suspicious-url-open-usage since url is hardcoded https)
3838
for raw_line in response:
3939
line = raw_line.decode().strip()
4040
if not line or line.startswith("#"):
@@ -46,11 +46,11 @@ def load_relevant_constraints(url: str, reqs: list[Requirement]) -> dict[str, Re
4646
return constraints
4747

4848

49-
def get_pypi_versions_for_package(package: str) -> list[Version]: # noqa: D103
49+
def get_pypi_versions_for_package(package: str) -> list[Version]:
5050
url = PYPI_URL.format(package=package)
5151

5252
versions: list[Version] = []
53-
with urllib.request.urlopen(url) as resp:
53+
with urllib.request.urlopen(url) as resp: # noqa: S310
5454
data = json.load(resp)
5555

5656
for v in data.get("releases", {}):
@@ -61,14 +61,14 @@ def get_pypi_versions_for_package(package: str) -> list[Version]: # noqa: D103
6161
return versions
6262

6363

64-
def get_pypi_versions(packages: list[str]) -> dict[str, list[Version]]: # noqa: D103
64+
def get_pypi_versions(packages: list[str]) -> dict[str, list[Version]]:
6565
versions: dict[str, list[Version]] = {}
6666
for package in packages:
6767
versions[package] = get_pypi_versions_for_package(package)
6868
return versions
6969

7070

71-
def check_compatibility( # noqa: D103
71+
def check_compatibility(
7272
requirements: list[Requirement],
7373
constraints: dict[str, Requirement],
7474
pypi_lib: dict[str, list[Version]],
@@ -94,13 +94,13 @@ def check_compatibility( # noqa: D103
9494
return errors
9595

9696

97-
def get_ha_tags() -> list[str]: # noqa: D103
97+
def get_ha_tags() -> list[str]:
9898
tags = []
9999
page = 1
100100
last_page = 3
101101
while page <= last_page:
102102
url = f"{HA_RELEASES_URL}?per_page=100&page={page}"
103-
with urllib.request.urlopen(url) as resp:
103+
with urllib.request.urlopen(url) as resp: # noqa: S310
104104
data = json.load(resp)
105105
if not data:
106106
break
@@ -116,7 +116,7 @@ def get_ha_tags() -> list[str]: # noqa: D103
116116
return sorted(versions, reverse=True)
117117

118118

119-
def get_constraints_url(version: str = "") -> str: # noqa: D103
119+
def get_constraints_url(version: str = "") -> str:
120120
return CONSTRAINTS_URL.format(v=version if version else "dev")
121121

122122

scripts/lint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ cd "$(dirname "$0")/.."
77
if [ "$1" = "ci" ]; then
88
# Don't try to fix errors, just fail
99
ruff format . --diff
10-
ruff check custom_components/zaptec --exit-zero # succeed despite errors until https://github.com/custom-components/zaptec/issues/258 is done
10+
ruff check . --exit-zero # succeed despite errors until https://github.com/custom-components/zaptec/issues/258 is done
1111
# ruff check .
1212
else
1313
# Auto-fix as much as possible
1414
ruff format .
15-
ruff check custom_components/zaptec --fix
15+
ruff check . --fix
1616
fi

0 commit comments

Comments
 (0)