treefmt-check
checks.x86_64-linux.treefmt
· build #178
· raw
1treefmt v2.5.0ERRO formatter | ruff-check: failed to apply with options '[check --fix]': exit status 123D301 Use `r"""` if any backslashes in a docstring4 --> lib/spaces_install_lib.py:400:55 |6399 | def nix_string(value: str) -> str:7400 | / """`value` as a Nix double-quoted string literal. The three sequences8401 | | that Nix reads inside `"…"` are escaped: `\\`, `"` and `${`.9402 | | """10 | |_______^11403 | escaped = value.replace("\\", "\\\\").replace('"', '\\"').replace("${", "\\${")12404 | return f'"{escaped}"'13 |14help: Add `r` prefix1516RUF005 Consider iterable unpacking instead of concatenation17 --> packages/spaces-install-backend/backend.py:728:2218 |19726 | host = plan["hostname"]20727 | live_modules = list(LIVE_FLAKE_MODULES) if live else []21728 | config_modules = live_modules + [22 | ______________________^23729 | | f"./machines/{host}/generated.nix",24730 | | f"./machines/{host}/configuration.nix",25731 | | f"./machines/{host}/hardware-configuration.nix",26732 | | f"./machines/{host}/hermes.nix",27733 | | ]28 | |_____^29734 | extra = []30735 | if Path("/etc/spaces-test-support").exists():31 |32help: Replace with iterable unpacking3334TRY301 Abstract `raise` to an inner function35 --> packages/spaces-install-backend/backend.py:1700:1736 |371698 | run_checked(["systemctl", "reboot"])381699 | else: # pragma: no cover391700 | raise AssertionError(action)40 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^411701 | except Exception:421702 | # Past the stop the user has no agent. Whatever failed (the stop43 |4445PT008 Use `return_value=` instead of patching with `lambda`46 --> packages/spaces-install-backend/test_backend.py:790:1347 |48788 | with (49789 | tempfile.TemporaryDirectory() as tmp,50790 | mock.patch.object(backend.os, "uname", lambda: uname),51 | ^^^^^^^^^^^^^^^^^52791 | ):53792 | repo = Path(tmp) / "dotfiles"54 |5556RUF012 Mutable default value for class attribute57 --> packages/spaces-install-backend/test_backend.py:814:1758 |59812 | HARDWARE = LiveRepoTest.HARDWARE60813 | SPACES_FLAKE = "/nix/store/aaaa-spaces-src"61814 | OVERRIDES = {"nixpkgs": "/nix/store/bbbb-nixpkgs"}62 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^63815 |64816 | def seed(self):65 |66help: Consider initializing in `__init__` or annotating with `typing.ClassVar`6768RUF012 Mutable default value for class attribute69 --> packages/spaces-install-backend/test_backend.py:891:1770 |71889 | HARDWARE_TARGET = '{ ... }:\n{ boot.initrd.availableKernelModules = [ "nvme" ]; }\n'72890 | SPACES_FLAKE = "/nix/store/aaaa-spaces-src"73891 | OVERRIDES = {"nixpkgs": "/nix/store/bbbb-nixpkgs"}74 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^75892 | DRV = "/nix/store/cccc-nixos-system-testhost.drv"76893 | TOPLEVEL = "/nix/store/dddd-nixos-system-testhost"77 |78help: Consider initializing in `__init__` or annotating with `typing.ClassVar`7980SIM117 Use a single `with` statement with multiple contexts instead of nested `with` statements81 --> packages/spaces-install-backend/test_backend.py:1033:1382 |831031 | stale = run_dir / "installed.json"841032 | stale.write_text("{}\n")851033 | / with mock.patch.object(backend, "ROOT_RUN_DIR", run_dir):861034 | | with self.assertRaises(backend.InstallError):87 | |_____________________________________________________________^881035 | backend.install_to(891036 | tmp / "mnt", plan(password_file=str(tmp / "missing")), "efi"90 |91help: Combine `with` statements9293EM102 Exception must not use an f-string literal, assign to variable first94 --> packages/spaces-install-backend/test_backend.py:1338:4495 |961336 | mode_at_reboot.append(unplug.stat().st_mode & 0o777 if unplug.exists() else None)971337 | if armed and argv[0] == fail_at:981338 | raise backend.InstallError(f"{argv[0]} failed")99 | ^^^^^^^^^^^^^^^^^^^1001339 | if argv[0] == "ssh-keygen":1011340 | return real_run(argv, **kwargs)102 |103help: Assign to variable; remove f-string literal104105ARG001 Unused function argument: `unit`106 --> packages/spaces-install-backend/test_backend.py:1361:29107 |1081359 | return ""1091360 |1101361 | def fake_unit_state(unit):111 | ^^^^1121362 | return "inactive"113 |114115S105 Possible hardcoded password assigned to: "TOKEN_HEADER"116 --> packages/spaces-installer-session/bootstrap.py:51:16117 |11849 | from websockets.exceptions import WebSocketException11950 |12051 | TOKEN_HEADER = "X-Hermes-Session-Token"121 | ^^^^^^^^^^^^^^^^^^^^^^^^12252 |12353 | # The first user turn. It names the situation and the skill, nothing124 |125126ANN201 Missing return type annotation for public function `log`127 --> packages/spaces-installer-session/bootstrap.py:60:5128 |12960 | def log(msg):130 | ^^^13161 | print(f"spaces-installer-session: {msg}", file=sys.stderr)132 |133help: Add return type annotation: `None`134135ANN001 Missing type annotation for function argument `msg`136 --> packages/spaces-installer-session/bootstrap.py:60:9137 |13860 | def log(msg):139 | ^^^14061 | print(f"spaces-installer-session: {msg}", file=sys.stderr)141 |142143ANN204 Missing return type annotation for special method `__init__`144 --> packages/spaces-installer-session/bootstrap.py:65:9145 |14664 | class Dashboard:14765 | def __init__(self, base_url, ws_url, token):148 | ^^^^^^^^14966 | self.base_url = base_url.rstrip("/")15067 | self.ws_url = ws_url151 |152help: Add return type annotation: `None`153154ANN001 Missing type annotation for function argument `base_url`155 --> packages/spaces-installer-session/bootstrap.py:65:24156 |15764 | class Dashboard:15865 | def __init__(self, base_url, ws_url, token):159 | ^^^^^^^^16066 | self.base_url = base_url.rstrip("/")16167 | self.ws_url = ws_url162 |163164ANN001 Missing type annotation for function argument `ws_url`165 --> packages/spaces-installer-session/bootstrap.py:65:34166 |16764 | class Dashboard:16865 | def __init__(self, base_url, ws_url, token):169 | ^^^^^^17066 | self.base_url = base_url.rstrip("/")17167 | self.ws_url = ws_url172 |173174ANN001 Missing type annotation for function argument `token`175 --> packages/spaces-installer-session/bootstrap.py:65:42176 |17764 | class Dashboard:17865 | def __init__(self, base_url, ws_url, token):179 | ^^^^^18066 | self.base_url = base_url.rstrip("/")18167 | self.ws_url = ws_url182 |183184ANN202 Missing return type annotation for private function `_request`185 --> packages/spaces-installer-session/bootstrap.py:70:9186 |18768 | self.token = token18869 |18970 | def _request(self, method, path, body=None):190 | ^^^^^^^^19171 | data = None19272 | headers = {TOKEN_HEADER: self.token}193 |194help: Add return type annotation195196ANN001 Missing type annotation for function argument `method`197 --> packages/spaces-installer-session/bootstrap.py:70:24198 |19968 | self.token = token20069 |20170 | def _request(self, method, path, body=None):202 | ^^^^^^20371 | data = None20472 | headers = {TOKEN_HEADER: self.token}205 |206207ANN001 Missing type annotation for function argument `path`208 --> packages/spaces-installer-session/bootstrap.py:70:32209 |21068 | self.token = token21169 |21270 | def _request(self, method, path, body=None):213 | ^^^^21471 | data = None21572 | headers = {TOKEN_HEADER: self.token}216 |217218ANN001 Missing type annotation for function argument `body`219 --> packages/spaces-installer-session/bootstrap.py:70:38220 |22168 | self.token = token22269 |22370 | def _request(self, method, path, body=None):224 | ^^^^22571 | data = None22672 | headers = {TOKEN_HEADER: self.token}227 |228229ANN201 Missing return type annotation for public function `ready`230 --> packages/spaces-installer-session/bootstrap.py:84:9231 |23282 | return err.code, err.read()23383 |23484 | def ready(self):235 | ^^^^^23685 | try:23786 | with urllib.request.urlopen(self.base_url + "/api/status", timeout=5) as resp:238 |239help: Add return type annotation240241PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable242 --> packages/spaces-installer-session/bootstrap.py:87:39243 |24485 | try:24586 | with urllib.request.urlopen(self.base_url + "/api/status", timeout=5) as resp:24687 | return resp.status == 200247 | ^^^24888 | except urllib.error.HTTPError as err:24989 | err.close()250 |251252ANN201 Missing return type annotation for public function `session_exists`253 --> packages/spaces-installer-session/bootstrap.py:94:9254 |25592 | return False25693 |25794 | def session_exists(self, sid):258 | ^^^^^^^^^^^^^^25995 | status, _ = self._request("GET", f"/api/sessions/{sid}")26096 | return status == 200261 |262help: Add return type annotation263264ANN001 Missing type annotation for function argument `sid`265 --> packages/spaces-installer-session/bootstrap.py:94:30266 |26792 | return False26893 |26994 | def session_exists(self, sid):270 | ^^^27195 | status, _ = self._request("GET", f"/api/sessions/{sid}")27296 | return status == 200273 |274275PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable276 --> packages/spaces-installer-session/bootstrap.py:96:26277 |27894 | def session_exists(self, sid):27995 | status, _ = self._request("GET", f"/api/sessions/{sid}")28096 | return status == 200281 | ^^^28297 |28398 | def find_by_title(self, title):284 |285286ANN201 Missing return type annotation for public function `find_by_title`287 --> packages/spaces-installer-session/bootstrap.py:98:9288 |289 96 | return status == 200290 97 |291 98 | def find_by_title(self, title):292 | ^^^^^^^^^^^^^293 99 | # `order=recent` puts the newest activity first, so the session294100 | # the user last talked to wins when several carry the title.295 |296help: Add return type annotation297298ANN001 Missing type annotation for function argument `title`299 --> packages/spaces-installer-session/bootstrap.py:98:29300 |301 96 | return status == 200302 97 |303 98 | def find_by_title(self, title):304 | ^^^^^305 99 | # `order=recent` puts the newest activity first, so the session306100 | # the user last talked to wins when several carry the title.307 |308309PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable310 --> packages/spaces-installer-session/bootstrap.py:106:26311 |312104 | "GET", f"/api/sessions?limit=100&offset={offset}&archived=include&order=recent"313105 | )314106 | if status != 200:315 | ^^^316107 | raise RuntimeError(f"GET /api/sessions answered {status}: {body!r}")317108 | rows = body.get("sessions") or []318 |319320EM102 Exception must not use an f-string literal, assign to variable first321 --> packages/spaces-installer-session/bootstrap.py:107:36322 |323105 | )324106 | if status != 200:325107 | raise RuntimeError(f"GET /api/sessions answered {status}: {body!r}")326 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^327108 | rows = body.get("sessions") or []328109 | for row in rows:329 |330help: Assign to variable; remove f-string literal331332ANN201 Missing return type annotation for public function `set_title`333 --> packages/spaces-installer-session/bootstrap.py:116:9334 |335114 | return None336115 |337116 | def set_title(self, sid, title):338 | ^^^^^^^^^339117 | status, body = self._request("PATCH", f"/api/sessions/{sid}", {"title": title})340118 | if status != 200:341 |342help: Add return type annotation: `None`343344ANN001 Missing type annotation for function argument `sid`345 --> packages/spaces-installer-session/bootstrap.py:116:25346 |347114 | return None348115 |349116 | def set_title(self, sid, title):350 | ^^^351117 | status, body = self._request("PATCH", f"/api/sessions/{sid}", {"title": title})352118 | if status != 200:353 |354355ANN001 Missing type annotation for function argument `title`356 --> packages/spaces-installer-session/bootstrap.py:116:30357 |358114 | return None359115 |360116 | def set_title(self, sid, title):361 | ^^^^^362117 | status, body = self._request("PATCH", f"/api/sessions/{sid}", {"title": title})363118 | if status != 200:364 |365366PLR2004 Magic value used in comparison, consider replacing `200` with a constant variable367 --> packages/spaces-installer-session/bootstrap.py:118:22368 |369116 | def set_title(self, sid, title):370117 | status, body = self._request("PATCH", f"/api/sessions/{sid}", {"title": title})371118 | if status != 200:372 | ^^^373119 | raise RuntimeError(f"PATCH /api/sessions/{sid} answered {status}: {body!r}")374 |375376EM102 Exception must not use an f-string literal, assign to variable first377 --> packages/spaces-installer-session/bootstrap.py:119:32378 |379117 | status, body = self._request("PATCH", f"/api/sessions/{sid}", {"title": title})380118 | if status != 200:381119 | raise RuntimeError(f"PATCH /api/sessions/{sid} answered {status}: {body!r}")382 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^383120 |384121 | async def _rpc(self, ws, rid, method, params):385 |386help: Assign to variable; remove f-string literal387388ANN202 Missing return type annotation for private function `_rpc`389 --> packages/spaces-installer-session/bootstrap.py:121:15390 |391119 | raise RuntimeError(f"PATCH /api/sessions/{sid} answered {status}: {body!r}")392120 |393121 | async def _rpc(self, ws, rid, method, params):394 | ^^^^395122 | await ws.send(json.dumps({"jsonrpc": "2.0", "id": rid, "method": method, "params": params}))396123 | # Events (gateway.ready, message.start, ...) interleave with replies.397 |398help: Add return type annotation399400ANN001 Missing type annotation for function argument `ws`401 --> packages/spaces-installer-session/bootstrap.py:121:26402 |403119 | raise RuntimeError(f"PATCH /api/sessions/{sid} answered {status}: {body!r}")404120 |405121 | async def _rpc(self, ws, rid, method, params):406 | ^^407122 | await ws.send(json.dumps({"jsonrpc": "2.0", "id": rid, "method": method, "params": params}))408123 | # Events (gateway.ready, message.start, ...) interleave with replies.409 |410411ANN001 Missing type annotation for function argument `rid`412 --> packages/spaces-installer-session/bootstrap.py:121:30413 |414119 | raise RuntimeError(f"PATCH /api/sessions/{sid} answered {status}: {body!r}")415120 |416121 | async def _rpc(self, ws, rid, method, params):417 | ^^^418122 | await ws.send(json.dumps({"jsonrpc": "2.0", "id": rid, "method": method, "params": params}))419123 | # Events (gateway.ready, message.start, ...) interleave with replies.420 |421422ANN001 Missing type annotation for function argument `method`423 --> packages/spaces-installer-session/bootstrap.py:121:35424 |425119 | raise RuntimeError(f"PATCH /api/sessions/{sid} answered {status}: {body!r}")426120 |427121 | async def _rpc(self, ws, rid, method, params):428 | ^^^^^^429122 | await ws.send(json.dumps({"jsonrpc": "2.0", "id": rid, "method": method, "params": params}))430123 | # Events (gateway.ready, message.start, ...) interleave with replies.431 |432433ANN001 Missing type annotation for function argument `params`434 --> packages/spaces-installer-session/bootstrap.py:121:43435 |436119 | raise RuntimeError(f"PATCH /api/sessions/{sid} answered {status}: {body!r}")437120 |438121 | async def _rpc(self, ws, rid, method, params):439 | ^^^^^^440122 | await ws.send(json.dumps({"jsonrpc": "2.0", "id": rid, "method": method, "params": params}))441123 | # Events (gateway.ready, message.start, ...) interleave with replies.442 |443444EM102 Exception must not use an f-string literal, assign to variable first445 --> packages/spaces-installer-session/bootstrap.py:129:36446 |447127 | continue448128 | if "error" in frame:449129 | raise RuntimeError(f"{method}: {frame['error']}")450 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^451130 | return frame.get("result") or {}452131 | raise RuntimeError(f"{method}: the gateway closed the socket before it answered")453 |454help: Assign to variable; remove f-string literal455456EM102 Exception must not use an f-string literal, assign to variable first457 --> packages/spaces-installer-session/bootstrap.py:131:28458 |459129 | raise RuntimeError(f"{method}: {frame['error']}")460130 | return frame.get("result") or {}461131 | raise RuntimeError(f"{method}: the gateway closed the socket before it answered")462 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^463132 |464133 | async def _create_and_prompt(self, title, text):465 |466help: Assign to variable; remove f-string literal467468ANN202 Missing return type annotation for private function `_create_and_prompt`469 --> packages/spaces-installer-session/bootstrap.py:133:15470 |471131 | raise RuntimeError(f"{method}: the gateway closed the socket before it answered")472132 |473133 | async def _create_and_prompt(self, title, text):474 | ^^^^^^^^^^^^^^^^^^475134 | url = f"{self.ws_url}?token={self.token}"476135 | async with connect(url, open_timeout=30) as ws:477 |478help: Add return type annotation479480ANN001 Missing type annotation for function argument `title`481 --> packages/spaces-installer-session/bootstrap.py:133:40482 |483131 | raise RuntimeError(f"{method}: the gateway closed the socket before it answered")484132 |485133 | async def _create_and_prompt(self, title, text):486 | ^^^^^487134 | url = f"{self.ws_url}?token={self.token}"488135 | async with connect(url, open_timeout=30) as ws:489 |490491ANN001 Missing type annotation for function argument `text`492 --> packages/spaces-installer-session/bootstrap.py:133:47493 |494131 | raise RuntimeError(f"{method}: the gateway closed the socket before it answered")495132 |496133 | async def _create_and_prompt(self, title, text):497 | ^^^^498134 | url = f"{self.ws_url}?token={self.token}"499135 | async with connect(url, open_timeout=30) as ws:500 |501502EM102 Exception must not use an f-string literal, assign to variable first503 --> packages/spaces-installer-session/bootstrap.py:140:36504 |505138 | stored_id = created.get("stored_session_id")506139 | if not runtime_id or not stored_id:507140 | raise RuntimeError(f"session.create returned no ids: {created!r}")508 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^509141 | await self._rpc(ws, 2, "prompt.submit", {"session_id": runtime_id, "text": text})510142 | return stored_id511 |512help: Assign to variable; remove f-string literal513514ANN201 Missing return type annotation for public function `create_and_prompt`515 --> packages/spaces-installer-session/bootstrap.py:144:9516 |517142 | return stored_id518143 |519144 | def create_and_prompt(self, title, text):520 | ^^^^^^^^^^^^^^^^^521145 | return asyncio.run(self._create_and_prompt(title, text))522 |523help: Add return type annotation524525ANN001 Missing type annotation for function argument `title`526 --> packages/spaces-installer-session/bootstrap.py:144:33527 |528142 | return stored_id529143 |530144 | def create_and_prompt(self, title, text):531 | ^^^^^532145 | return asyncio.run(self._create_and_prompt(title, text))533 |534535ANN001 Missing type annotation for function argument `text`536 --> packages/spaces-installer-session/bootstrap.py:144:40537 |538142 | return stored_id539143 |540144 | def create_and_prompt(self, title, text):541 | ^^^^542145 | return asyncio.run(self._create_and_prompt(title, text))543 |544545ANN201 Missing return type annotation for public function `parse_args`546 --> packages/spaces-installer-session/bootstrap.py:148:5547 |548148 | def parse_args(argv):549 | ^^^^^^^^^^550149 | p = argparse.ArgumentParser(description="open the install conversation once per boot")551150 | p.add_argument("--base-url", required=True, help="dashboard URL, http://127.0.0.1:<port>")552 |553help: Add return type annotation554555ANN001 Missing type annotation for function argument `argv`556 --> packages/spaces-installer-session/bootstrap.py:148:16557 |558148 | def parse_args(argv):559 | ^^^^560149 | p = argparse.ArgumentParser(description="open the install conversation once per boot")561150 | p.add_argument("--base-url", required=True, help="dashboard URL, http://127.0.0.1:<port>")562 |563564PTH118 `os.path.join()` should be replaced by `Path` with `/` operator565 --> packages/spaces-installer-session/bootstrap.py:154:17566 |567152 | p.add_argument(568153 | "--state-file",569154 | default=os.path.join(os.environ.get("XDG_RUNTIME_DIR", "/run/user/%d" % os.getuid()), "spaces-installer", "session"),570 | ^^^^^^^^^^^^571155 | help="where the stored session id is recorded",572156 | )573 |574575UP031 Use format specifiers instead of percent format576 --> packages/spaces-installer-session/bootstrap.py:154:64577 |578152 | p.add_argument(579153 | "--state-file",580154 | default=os.path.join(os.environ.get("XDG_RUNTIME_DIR", "/run/user/%d" % os.getuid()), "spaces-installer", "session"),581 | ^^^^^^^^^^^^^^582155 | help="where the stored session id is recorded",583156 | )584 |585help: Replace with format specifiers586587ANN201 Missing return type annotation for public function `record`588 --> packages/spaces-installer-session/bootstrap.py:165:5589 |590165 | def record(state_file, sid):591 | ^^^^^^592166 | path = Path(state_file)593167 | path.parent.mkdir(parents=True, exist_ok=True)594 |595help: Add return type annotation: `None`596597ANN001 Missing type annotation for function argument `state_file`598 --> packages/spaces-installer-session/bootstrap.py:165:12599 |600165 | def record(state_file, sid):601 | ^^^^^^^^^^602166 | path = Path(state_file)603167 | path.parent.mkdir(parents=True, exist_ok=True)604 |605606ANN001 Missing type annotation for function argument `sid`607 --> packages/spaces-installer-session/bootstrap.py:165:24608 |609165 | def record(state_file, sid):610 | ^^^611166 | path = Path(state_file)612167 | path.parent.mkdir(parents=True, exist_ok=True)613 |614615PTH105 `os.replace()` should be replaced by `Path.replace()`616 --> packages/spaces-installer-session/bootstrap.py:170:5617 |618168 | tmp = path.with_name(path.name + ".tmp")619169 | tmp.write_text(sid)620170 | os.replace(tmp, path)621 | ^^^^^^^^^^622help: Replace with `Path(...).replace(...)`623624ANN201 Missing return type annotation for public function `main`625 --> packages/spaces-installer-session/bootstrap.py:173:5626 |627173 | def main(argv=None):628 | ^^^^629174 | args = parse_args(argv)630175 | try:631 |632help: Add return type annotation: `int | None`633634ANN001 Missing type annotation for function argument `argv`635 --> packages/spaces-installer-session/bootstrap.py:173:10636 |637173 | def main(argv=None):638 | ^^^^639174 | args = parse_args(argv)640175 | try:641 |642643TRY300 Consider moving this statement to an `else` block644 --> packages/spaces-installer-session/bootstrap.py:209:9645 |646207 | log(f"created session {sid} titled {args.title!r}")647208 | record(args.state_file, sid)648209 | return 0649 | ^^^^^^^^650210 | except (RuntimeError, OSError, WebSocketException, ValueError) as err:651211 | log(str(err))652 |653654Found 78 errors (19 fixed, 59 remaining).655No fixes available (13 hidden fixes can be enabled with the `--unsafe-fixes` option).656657ERRO formatter | shellcheck: failed to apply with options '[]': exit status 1658659660In packages/spaces-install-secret/spaces-install-secret.sh line 1:661# Usage: spaces-install-secret password|luks-passphrase662^-- SC2148 (error): Tips depend on target shell and yours is unknown. Add a shebang or a 'shell' directive.663664For more information:665 https://www.shellcheck.net/wiki/SC2148 -- Tips depend on target shell and y...666667traversed 606 files668emitted 400 files for processing669formatted 238 files (14 changed) in 893ms670Error: failed to finalise formatting: formatting failures detected