GitHub Actions commited on
Commit
f6ead22
Β·
1 Parent(s): d5d0b5e

Fix: Ruff linting issues - SIM/E402/F401 violations

Browse files

- SIM105: Replace try-except-pass with contextlib.suppress (5 fixes)
- SIM102/SIM117: Combine nested if/with statements (4 fixes)
- E402: Reorganize imports to top of files, remove UTC = UTC assignments
- F401: Remove unused Diff and RegistryEvent imports
- Fixed docstring placement in identity/__init__.py

hearthnet/bus/__init__.py CHANGED
@@ -13,7 +13,7 @@ from hearthnet.bus.capability import (
13
  RouteRequest,
14
  )
15
  from hearthnet.bus.health import HealthTracker
16
- from hearthnet.bus.registry import Diff, Registry, RegistryEvent
17
  from hearthnet.bus.router import BusConfig, Router
18
  from hearthnet.types import CapabilityName, HearthNetError, Version
19
 
 
13
  RouteRequest,
14
  )
15
  from hearthnet.bus.health import HealthTracker
16
+ from hearthnet.bus.registry import Registry
17
  from hearthnet.bus.router import BusConfig, Router
18
  from hearthnet.types import CapabilityName, HearthNetError, Version
19
 
hearthnet/emergency/state.py CHANGED
@@ -74,10 +74,9 @@ class StateBus:
74
  self._transition_times = [
75
  t for t in self._transition_times if now - t < EMERGENCY_ANTI_FLAP_WINDOW_SECONDS
76
  ]
77
- if len(self._transition_times) >= EMERGENCY_ANTI_FLAP_MAX_TRANSITIONS:
78
  # Too many flaps β€” hold pessimistic
79
- if old_mode in ("degraded", "offline") and new_mode == "online":
80
- new_mode = old_mode # don't restore yet
81
 
82
  new_state = EmergencyState(
83
  mode=new_mode,
 
74
  self._transition_times = [
75
  t for t in self._transition_times if now - t < EMERGENCY_ANTI_FLAP_WINDOW_SECONDS
76
  ]
77
+ if len(self._transition_times) >= EMERGENCY_ANTI_FLAP_MAX_TRANSITIONS and old_mode in ("degraded", "offline") and new_mode == "online":
78
  # Too many flaps β€” hold pessimistic
79
+ new_mode = old_mode # don't restore yet
 
80
 
81
  new_state = EmergencyState(
82
  mode=new_mode,
hearthnet/events/log.py CHANGED
@@ -11,14 +11,12 @@ ReplayEngine drives materialised views (marketplace, chat).
11
  from __future__ import annotations
12
 
13
  import asyncio
 
14
  import json
15
  import sqlite3
16
  import threading
17
  from collections.abc import AsyncIterator
18
- from datetime import datetime, timezone
19
-
20
- UTC = timezone.utc
21
- import contextlib
22
  from pathlib import Path
23
  from typing import Any
24
 
 
11
  from __future__ import annotations
12
 
13
  import asyncio
14
+ import contextlib
15
  import json
16
  import sqlite3
17
  import threading
18
  from collections.abc import AsyncIterator
19
+ from datetime import UTC, datetime
 
 
 
20
  from pathlib import Path
21
  from typing import Any
22
 
hearthnet/events/snapshot.py CHANGED
@@ -1,13 +1,11 @@
1
  from __future__ import annotations
2
 
3
  import base64
 
4
  import json
5
  import os
6
  from dataclasses import dataclass
7
- from datetime import datetime, timezone
8
-
9
- UTC = timezone.utc
10
- import contextlib
11
  from pathlib import Path
12
  from typing import TYPE_CHECKING, Any
13
 
 
1
  from __future__ import annotations
2
 
3
  import base64
4
+ import contextlib
5
  import json
6
  import os
7
  from dataclasses import dataclass
8
+ from datetime import UTC, datetime
 
 
 
9
  from pathlib import Path
10
  from typing import TYPE_CHECKING, Any
11
 
hearthnet/identity/__init__.py CHANGED
@@ -1,11 +1,11 @@
1
- from __future__ import annotations
2
-
3
  """hearthnet.identity β€” M01 Identity module.
4
 
5
  Provides Ed25519 key management, canonical JSON, signing/verification,
6
  and node/community manifests.
7
  """
8
 
 
 
9
  from hearthnet.identity.keys import (
10
  IdentityError,
11
  KeyPair,
 
 
 
1
  """hearthnet.identity β€” M01 Identity module.
2
 
3
  Provides Ed25519 key management, canonical JSON, signing/verification,
4
  and node/community manifests.
5
  """
6
 
7
+ from __future__ import annotations
8
+
9
  from hearthnet.identity.keys import (
10
  IdentityError,
11
  KeyPair,
hearthnet/identity/manifest.py CHANGED
@@ -1,9 +1,7 @@
1
  from __future__ import annotations
2
 
3
  from dataclasses import dataclass
4
- from datetime import datetime, timedelta, timezone
5
-
6
- UTC = timezone.utc
7
  from typing import Any
8
 
9
  from hearthnet.identity.keys import (
 
1
  from __future__ import annotations
2
 
3
  from dataclasses import dataclass
4
+ from datetime import UTC, datetime, timedelta
 
 
5
  from typing import Any
6
 
7
  from hearthnet.identity.keys import (
hearthnet/services/chat/service.py CHANGED
@@ -1,9 +1,7 @@
1
  from __future__ import annotations
2
 
3
  import uuid
4
- from datetime import datetime, timezone
5
-
6
- UTC = timezone.utc
7
 
8
  from hearthnet.bus.capability import CapabilityDescriptor, RouteRequest
9
  from hearthnet.services.chat.delivery import DeliveryManager
 
1
  from __future__ import annotations
2
 
3
  import uuid
4
+ from datetime import UTC, datetime
 
 
5
 
6
  from hearthnet.bus.capability import CapabilityDescriptor, RouteRequest
7
  from hearthnet.services.chat.delivery import DeliveryManager
hearthnet/services/llm/backends/ollama.py CHANGED
@@ -96,18 +96,17 @@ class OllamaBackend:
96
 
97
  import httpx
98
 
99
- async with httpx.AsyncClient(timeout=120.0) as client:
100
- async with client.stream("POST", f"{self._base_url}/api/chat", json=payload) as resp:
101
- async for line in resp.aiter_lines():
102
- if line:
103
- try:
104
- data = json.loads(line)
105
- text = data.get("message", {}).get("content", "")
106
- done = data.get("done", False)
107
- if text:
108
- yield Token(text=text, stop=done)
109
- except json.JSONDecodeError:
110
- pass
111
 
112
  async def complete(self, prompt: str, *, model: str, stream: bool = False, **kwargs):
113
  messages = [{"role": "user", "content": prompt}]
 
96
 
97
  import httpx
98
 
99
+ async with httpx.AsyncClient(timeout=120.0) as client, client.stream("POST", f"{self._base_url}/api/chat", json=payload) as resp:
100
+ async for line in resp.aiter_lines():
101
+ if line:
102
+ try:
103
+ data = json.loads(line)
104
+ text = data.get("message", {}).get("content", "")
105
+ done = data.get("done", False)
106
+ if text:
107
+ yield Token(text=text, stop=done)
108
+ except json.JSONDecodeError:
109
+ pass
 
110
 
111
  async def complete(self, prompt: str, *, model: str, stream: bool = False, **kwargs):
112
  messages = [{"role": "user", "content": prompt}]
hearthnet/services/marketplace/post.py CHANGED
@@ -1,9 +1,7 @@
1
  from __future__ import annotations
2
 
3
  from dataclasses import dataclass
4
- from datetime import datetime, timezone
5
-
6
- UTC = timezone.utc
7
  from typing import Literal
8
 
9
  Category = Literal["offer", "request", "info", "emergency"]
 
1
  from __future__ import annotations
2
 
3
  from dataclasses import dataclass
4
+ from datetime import UTC, datetime
 
 
5
  from typing import Literal
6
 
7
  Category = Literal["offer", "request", "info", "emergency"]
hearthnet/services/marketplace/service.py CHANGED
@@ -1,9 +1,7 @@
1
  from __future__ import annotations
2
 
3
  import uuid
4
- from datetime import datetime, timedelta, timezone
5
-
6
- UTC = timezone.utc
7
 
8
  from hearthnet.bus.capability import CapabilityDescriptor, RouteRequest
9
  from hearthnet.constants import MARKET_DEFAULT_TTL_SECONDS
 
1
  from __future__ import annotations
2
 
3
  import uuid
4
+ from datetime import UTC, datetime, timedelta
 
 
5
 
6
  from hearthnet.bus.capability import CapabilityDescriptor, RouteRequest
7
  from hearthnet.constants import MARKET_DEFAULT_TTL_SECONDS
hearthnet/services/marketplace/views.py CHANGED
@@ -1,12 +1,6 @@
1
  from __future__ import annotations
2
 
3
- from datetime import datetime, timezone
4
-
5
- UTC = timezone.utc
6
-
7
- UTC = UTC
8
-
9
- UTC = UTC
10
  from typing import Any
11
 
12
  from hearthnet.services.marketplace.post import Location, Post
 
1
  from __future__ import annotations
2
 
3
+ from datetime import UTC, datetime
 
 
 
 
 
 
4
  from typing import Any
5
 
6
  from hearthnet.services.marketplace.post import Location, Post
hearthnet/transport/client.py CHANGED
@@ -7,9 +7,9 @@ import json
7
  import secrets
8
  from collections.abc import AsyncIterator
9
  from dataclasses import dataclass, field
10
- from datetime import datetime, timezone
11
 
12
- UTC = timezone.utc
13
 
14
  try:
15
  import httpx
@@ -110,17 +110,16 @@ class HttpClient:
110
  headers = self._make_headers(payload)
111
  headers["Accept"] = "text/event-stream"
112
  try:
113
- async with httpx.AsyncClient(verify=self._verify_ssl) as client:
114
- async with client.stream(
115
- "POST",
116
- f"{self._base_url}/bus/v1/call",
117
- json=payload,
118
- headers=headers,
119
- ) as resp:
120
- async for line in resp.aiter_lines():
121
- if line.startswith("data: "):
122
- with contextlib.suppress(json.JSONDecodeError):
123
- yield json.loads(line[6:])
124
  except Exception as exc:
125
  raise CallError("partition", str(exc)) from exc
126
 
 
7
  import secrets
8
  from collections.abc import AsyncIterator
9
  from dataclasses import dataclass, field
10
+ from datetime import UTC, datetime
11
 
12
+ UTC = UTC
13
 
14
  try:
15
  import httpx
 
110
  headers = self._make_headers(payload)
111
  headers["Accept"] = "text/event-stream"
112
  try:
113
+ async with httpx.AsyncClient(verify=self._verify_ssl) as client, client.stream(
114
+ "POST",
115
+ f"{self._base_url}/bus/v1/call",
116
+ json=payload,
117
+ headers=headers,
118
+ ) as resp:
119
+ async for line in resp.aiter_lines():
120
+ if line.startswith("data: "):
121
+ with contextlib.suppress(json.JSONDecodeError):
122
+ yield json.loads(line[6:])
 
123
  except Exception as exc:
124
  raise CallError("partition", str(exc)) from exc
125
 
hearthnet/transport/server.py CHANGED
@@ -21,9 +21,7 @@ from __future__ import annotations
21
 
22
  import asyncio
23
  from collections.abc import Callable
24
- from datetime import datetime, timezone
25
-
26
- UTC = timezone.utc
27
  from typing import Any
28
 
29
  try:
 
21
 
22
  import asyncio
23
  from collections.abc import Callable
24
+ from datetime import UTC, datetime
 
 
25
  from typing import Any
26
 
27
  try:
hearthnet/types.py CHANGED
@@ -1,7 +1,7 @@
1
  from __future__ import annotations
2
 
3
  from dataclasses import dataclass
4
- from typing import Literal
5
 
6
  NodeID = str
7
  CommunityID = str
@@ -44,7 +44,7 @@ class HearthNetError(Exception):
44
 
45
 
46
  # ── Phase 3 type aliases ─────────────────────────────────────────────────────
47
- from typing import NewType
48
 
49
  ShardID = NewType("ShardID", str) # "<model_id>:<lo>-<hi>[:tier]"
50
  ExpertID = NewType("ExpertID", str) # "human:..." | "model:..." | "service:..." | "external:..."
 
1
  from __future__ import annotations
2
 
3
  from dataclasses import dataclass
4
+ from typing import Literal, NewType
5
 
6
  NodeID = str
7
  CommunityID = str
 
44
 
45
 
46
  # ── Phase 3 type aliases ─────────────────────────────────────────────────────
47
+
48
 
49
  ShardID = NewType("ShardID", str) # "<model_id>:<lo>-<hi>[:tier]"
50
  ExpertID = NewType("ExpertID", str) # "human:..." | "model:..." | "service:..." | "external:..."
hearthnet/ui/__pycache__/onboarding.cpython-313.pyc CHANGED
Binary files a/hearthnet/ui/__pycache__/onboarding.cpython-313.pyc and b/hearthnet/ui/__pycache__/onboarding.cpython-313.pyc differ
 
hearthnet/ui/app.py CHANGED
@@ -17,7 +17,7 @@ except ImportError:
17
  HAS_GRADIO = False
18
 
19
 
20
- # Inject easter egg ticker CSS/HTML into Gradio's head
21
  _EASTER_EGG_CSS = """
22
  <style id="egg-ticker-style">
23
  body {
@@ -84,21 +84,26 @@ _EASTER_EGG_CSS = """
84
  <span class="etk"><b>AP News</b> Top Stories</span>
85
  </div>
86
  </div>
87
- <script id="egg-ticker-script">
88
- (function() {
89
- let eggOpen = false;
 
 
 
 
 
 
90
  const ticker = document.getElementById('egg-ticker');
91
- if (!ticker) return;
 
 
 
92
 
93
- // Attach to window so it survives navigation
94
  window.toggleEasterEgg = function() {
95
  eggOpen = !eggOpen;
96
- if (ticker) {
97
- ticker.classList.toggle('active', eggOpen);
98
- }
99
  };
100
 
101
- // Listen for 'e' key
102
  document.addEventListener('keydown', function(evt) {
103
  if ((evt.key === 'e' || evt.key === 'E') &&
104
  document.activeElement &&
@@ -106,9 +111,13 @@ _EASTER_EGG_CSS = """
106
  window.toggleEasterEgg();
107
  }
108
  });
109
- })();
 
 
 
110
  </script>
111
  """
 
112
 
113
 
114
  class UiApp:
 
17
  HAS_GRADIO = False
18
 
19
 
20
+ # Easter egg ticker CSS (no script - will be injected via Blocks head parameter)
21
  _EASTER_EGG_CSS = """
22
  <style id="egg-ticker-style">
23
  body {
 
84
  <span class="etk"><b>AP News</b> Top Stories</span>
85
  </div>
86
  </div>
87
+ """
88
+
89
+ # Easter egg script - injected via Blocks head parameter
90
+ _EASTER_EGG_SCRIPT = """
91
+ <script>
92
+ (function() {
93
+ let eggOpen = false;
94
+
95
+ function initEasterEgg() {
96
  const ticker = document.getElementById('egg-ticker');
97
+ if (!ticker) {
98
+ setTimeout(initEasterEgg, 100);
99
+ return;
100
+ }
101
 
 
102
  window.toggleEasterEgg = function() {
103
  eggOpen = !eggOpen;
104
+ ticker.classList.toggle('active', eggOpen);
 
 
105
  };
106
 
 
107
  document.addEventListener('keydown', function(evt) {
108
  if ((evt.key === 'e' || evt.key === 'E') &&
109
  document.activeElement &&
 
111
  window.toggleEasterEgg();
112
  }
113
  });
114
+ }
115
+
116
+ initEasterEgg();
117
+ })();
118
  </script>
119
  """
120
+ """
121
 
122
 
123
  class UiApp:
hearthnet/ui/onboarding.py CHANGED
@@ -3,13 +3,10 @@
3
  from __future__ import annotations
4
 
5
  import base64
 
6
  import json
7
  from dataclasses import dataclass
8
- from datetime import timezone
9
-
10
- UTC = timezone.utc
11
-
12
- import contextlib
13
 
14
  from hearthnet.constants import INVITE_DEFAULT_TTL_SECONDS
15
 
@@ -155,14 +152,13 @@ def redeem_invite(
155
  event_log=None,
156
  ) -> dict:
157
  """Verify invite, emit member.joined event, return community manifest stub."""
158
- if blob.invitee_node_id not in (kp.node_id_full, kp.node_id_short):
159
- if blob.invitee_node_id: # "" means open invite
160
- raise OnboardingError(
161
- "invitee_mismatch",
162
- reason=(
163
- f"invite was for {blob.invitee_node_id[:20]}, we are {kp.node_id_full[:20]}"
164
- ),
165
- )
166
 
167
  if event_log is not None:
168
  with contextlib.suppress(Exception):
 
3
  from __future__ import annotations
4
 
5
  import base64
6
+ import contextlib
7
  import json
8
  from dataclasses import dataclass
9
+ from datetime import UTC
 
 
 
 
10
 
11
  from hearthnet.constants import INVITE_DEFAULT_TTL_SECONDS
12
 
 
152
  event_log=None,
153
  ) -> dict:
154
  """Verify invite, emit member.joined event, return community manifest stub."""
155
+ if blob.invitee_node_id not in (kp.node_id_full, kp.node_id_short) and blob.invitee_node_id: # "" means open invite
156
+ raise OnboardingError(
157
+ "invitee_mismatch",
158
+ reason=(
159
+ f"invite was for {blob.invitee_node_id[:20]}, we are {kp.node_id_full[:20]}"
160
+ ),
161
+ )
 
162
 
163
  if event_log is not None:
164
  with contextlib.suppress(Exception):