Skip to content

Commit 06c5ede

Browse files
committed
safer env vars config validation, initialization gate for network node add
1 parent d66c15c commit 06c5ede

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

src/koi_net/config/loader.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
from contextlib import contextmanager
23
from pathlib import Path
34
from typing import Generic, TypeVar
@@ -45,10 +46,10 @@ def mutate(self):
4546

4647
def validate_env_vars(self):
4748
for field in self.schema.model_fields.values():
48-
field_class = field.annotation
49-
if issubclass(field_class, EnvConfig):
49+
field_type = field.annotation
50+
if inspect.isclass(field_type) and issubclass(field_type, EnvConfig):
5051
try:
51-
field_class()
52+
field_type()
5253
except ValidationError as exc:
5354
missing_vars = [
5455
err["loc"][0].upper()

src/koi_net/interface/module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def resolve_ref(self, module_ref) -> str:
3434

3535
def load_class(self, module_name: str, reload_module: bool = False):
3636
if module_name not in self.module_map:
37-
print(f"loading module {module_name}")
37+
print(f"Loading module '{module_name}'...")
3838
module = importlib.import_module(module_name + MODULE_CORE)
3939
self.module_map[module_name] = module
4040
elif reload_module:
41-
print(f"reloading module {module_name}")
41+
print(f"Reloading module '{module_name}'...")
4242
module = importlib.reload(self.module_map[module_name])
4343
self.module_map[module_name] = module
4444
else:

src/koi_net/interface/network.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def load_nodes(self) -> list[NodeInterface]:
3535
self.nodes.append(node)
3636

3737
if node.exists():
38+
print(f"Loading node '{node.name}'...")
3839
node.init()
3940

4041
def resolve_node(self, name: str) -> NodeInterface | None:

src/koi_net/interface/node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def init(self):
8181
renderable=text,
8282
title="Cannot initialize node, missing the following enironment variables:",
8383
border_style="red"))
84+
except Exception as err:
85+
print(err)
8486

8587
def state(self):
8688
return self.node.get_state()

src/koi_net/interface/shell.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ def node_add(self, module_ref: str, name: str | None = None):
158158

159159
if not node.exists():
160160
node.create()
161-
162-
self.network.add_node(node)
161+
162+
if node.initialized:
163+
self.network.add_node(node)
163164

164165
@load_node
165166
def node_rm(self, node: NodeInterface):

0 commit comments

Comments
 (0)