Skip to content
Closed
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
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ select = [
"D", # flake8-docstrings
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"EM", # flake8-errmsg
"ERA", # eradicate (commented-out code)
"FA", # flake8-future-annotations
"FLY", # flynt (f-string conversion)
Expand Down Expand Up @@ -231,6 +232,8 @@ select = [
"DTZ005", # tests intentionally call datetime.now() without tz
"ERA001", # test fixtures keep commented-out reference snippets
"E402", # optional-dependency guards (pytest.importorskip) precede imports
"EM101", # inline exception messages are fine in test assertions
"EM102", # inline f-string exception messages are fine in test assertions
]
"setup.py" = ["D100"]
"conftest.py" = ["D100"]
Expand Down Expand Up @@ -266,6 +269,21 @@ select = [
# public exception names — renaming would break the API consumers depend on
"N818",
]
"src/uiprotect/data/devices.py" = [
# private-API models slated for removal in the public-API migration; not worth the churn
"EM101",
"EM102",
]
"src/uiprotect/data/nvr.py" = [
# private-API models slated for removal in the public-API migration; not worth the churn
"EM101",
"EM102",
]
"src/uiprotect/data/user.py" = [
# private-API models slated for removal in the public-API migration; not worth the churn
"EM101",
"EM102",
]

[tool.ruff.lint.isort]
known-first-party = ["uiprotect", "tests"]
Expand Down
15 changes: 10 additions & 5 deletions scripts/fetch_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def _get_download_url(version: str | None) -> tuple[str, str]:
if version:
parts = version.split(".")
if len(parts) != 3:
raise ValueError(f"version must be MAJOR.MINOR.PATCH, got {version!r}")
msg = f"version must be MAJOR.MINOR.PATCH, got {version!r}"
raise ValueError(msg)
major, minor, patch = parts
params += [
f"filter=eq~~version_major~~{major}",
Expand All @@ -69,7 +70,8 @@ def _get_download_url(version: str | None) -> tuple[str, str]:

entries = data["_embedded"]["firmware"]
if not entries:
raise RuntimeError(f"No firmware found for version={version!r}")
msg = f"No firmware found for version={version!r}"
raise RuntimeError(msg)

fw = entries[0]
return fw["_links"]["data"]["href"], fw["version"]
Expand All @@ -78,7 +80,8 @@ def _get_download_url(version: str | None) -> tuple[str, str]:
def _extract_from_deb(deb_bytes: bytes) -> bytes:
"""Extract the integration openapi.json from a .deb (ar archive)."""
if deb_bytes[:8] != b"!<arch>\n":
raise ValueError("Not an ar archive")
msg = "Not an ar archive"
raise ValueError(msg)

offset = 8
while offset < len(deb_bytes):
Expand All @@ -92,10 +95,12 @@ def _extract_from_deb(deb_bytes: bytes) -> bytes:
with tarfile.open(fileobj=io.BytesIO(member_data)) as tf:
f = tf.extractfile(tf.getmember(SPEC_MEMBER))
if f is None:
raise RuntimeError(f"{SPEC_MEMBER!r} is not a regular file in deb")
msg = f"{SPEC_MEMBER!r} is not a regular file in deb"
raise RuntimeError(msg)
return f.read()

raise FileNotFoundError(f"{SPEC_MEMBER!r} not found in deb")
msg = f"{SPEC_MEMBER!r} not found in deb"
raise FileNotFoundError(msg)


if __name__ == "__main__":
Expand Down
Loading
Loading