Coverage for src/lilbee/core/config/validators.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-11-06 08:17 +0000

1"""Pydantic ``Field`` wrapper with lilbee-specific schema metadata.""" 

2 

3from typing import Any 

4 

5from pydantic import Field 

6 

7from .enums import ProfileScope 

8 

9 

10def ConfigField( # noqa: N802 pydantic Field wrapper; matches Field's PascalCase 

11 *args: Any, 

12 writable: bool = False, 

13 reindex: bool = False, 

14 write_only: bool = False, 

15 public: bool = True, 

16 derived: bool = False, 

17 profile: ProfileScope | None = None, 

18 from_env: bool = True, 

19 **kwargs: Any, 

20) -> Any: 

21 """Wrap pydantic ``Field`` and attach metadata via ``json_schema_extra``. 

22 

23 ``derived`` marks a field whose default means lilbee computes the value at runtime. 

24 ``profile`` marks a field a profile may hold, and the part of lilbee it tunes. 

25 """ 

26 extra: dict[str, bool | str] = {} 

27 if writable: 

28 extra["writable"] = True 

29 if derived: 

30 extra["derived"] = True 

31 if reindex: 

32 extra["reindex"] = True 

33 if write_only: 

34 extra["write_only"] = True 

35 if not public: 

36 extra["public"] = False 

37 if profile is not None: 

38 extra["profile"] = profile.value 

39 if not from_env: 

40 extra["from_env"] = False 

41 if extra: 

42 # Merge rather than assign: a caller passing its own json_schema_extra 

43 # had it silently dropped, with lilbee's flags winning. 

44 supplied = kwargs.get("json_schema_extra") 

45 kwargs["json_schema_extra"] = {**supplied, **extra} if isinstance(supplied, dict) else extra 

46 return Field(*args, **kwargs)