Skip to content

Commit

Permalink
Load hooks from config
Browse files Browse the repository at this point in the history
  • Loading branch information
isra17 committed Nov 23, 2023
1 parent 0fdf6f2 commit 8f88600
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions mypy_stubs/typing_inspect/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing as t

def is_optional_type(typ: t.Any) -> bool: ...
def is_typevar(typ: t.Any) -> bool: ...
def get_args(typ: t.Any) -> tuple: ...
7 changes: 6 additions & 1 deletion src/saturn_engine/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from collections.abc import Mapping
from enum import Enum

import typing_inspect

from . import CINamespace
from .inspect import eval_class_annotations
from .inspect import import_name
Expand Down Expand Up @@ -55,7 +57,7 @@ def load_envvar(self: TConfig, envvar: str) -> TConfig:
"""Load an object from a path stored in an environment variable."""
return self.load_object(os.environ.get(envvar))

def register_interface(self: TConfig, namespace: str, interface: Type) -> TConfig:
def register_interface(self: TConfig, namespace: str, interface: Any) -> TConfig:
"""Add an interface to the config under namespace.
Interfaces are used to validate config keys and values.
Expand Down Expand Up @@ -252,6 +254,9 @@ def check_type(obj: Any, typ: Any, scope: Any) -> bool:
if typ is float:
return isinstance(obj, (float, int))

if typing_inspect.is_typevar(typ):
return True

if not isinstance(obj, typ):
return False

Expand Down
1 change: 1 addition & 0 deletions src/saturn_engine/worker/services/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
class ServicesManager:
def __init__(self, config: Config) -> None:
self.strict = config.c.services_manager.strict_services
config = config.register_interface(Hooks.name, Hooks.Options())
self.services: Services = ServicesNamespace(
config=config,
hooks=Hooks.from_options(config.r.get("hooks", {})),
Expand Down

0 comments on commit 8f88600

Please sign in to comment.