Coverage for src/endow/backend.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-09 19:20 +0200

1"""Backend entry points for constructing dependency graphs.""" 

2 

3from __future__ import annotations 

4 

5import typing as t 

6 

7from .base import Injectable 

8from .runtime import build_graph 

9 

10 

11class BackendBase(Injectable): 

12 """Root object that builds a graph from runtime inputs.""" 

13 

14 @classmethod 

15 def with_injected(cls, **runtime_inputs: t.Any) -> t.Self: 

16 """Build a backend instance from the provided runtime inputs.""" 

17 return build_graph(cls, runtime_inputs) 

18 

19 @classmethod 

20 def with_injected_checked(cls, strict: bool, **runtime_inputs: t.Any) -> t.Self: 

21 """Build a backend instance and check Service-to-Domain dependencies.""" 

22 return build_graph(cls, runtime_inputs, strict=strict) 

23 

24 @classmethod 

25 def from_env(cls, **runtime_inputs: t.Any) -> t.Self: 

26 """Backward-compatible alias for building a backend instance.""" 

27 return cls.with_injected(**runtime_inputs) 

28 

29 @classmethod 

30 def from_env_checked(cls, strict: bool, **runtime_inputs: t.Any) -> t.Self: 

31 """Backward-compatible alias for building a checked backend instance.""" 

32 return cls.with_injected_checked(strict, **runtime_inputs)