Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load hooks from config #376

Merged
merged 1 commit into from
Nov 23, 2023
Merged
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
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
Loading