Coverage for src / rendercv / schema / models / rendercv_model.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-25 13:49 +0000

1import pathlib 

2 

3import pydantic 

4 

5from .base import BaseModelWithoutExtraKeys 

6from .cv.cv import Cv 

7from .design.classic_theme import ClassicTheme 

8from .design.design import Design 

9from .locale.locale import EnglishLocale, Locale 

10from .settings.settings import Settings 

11from .validation_context import get_input_file_path 

12 

13 

14class RenderCVModel(BaseModelWithoutExtraKeys): 

15 """Top-level model representing a complete RenderCV configuration. 

16 

17 Why: 

18 This is the root of the entire data model, combining CV content, 

19 design theme, locale translations, and rendering settings into a 

20 single validated structure. All rendering pipeline stages operate 

21 on this unified model. 

22 """ 

23 

24 # Technically, `cv` is a required field, but we don't pass it to the JSON Schema 

25 # so that the same schema can be used for standalone design, locale, and settings 

26 # files. 

27 model_config = pydantic.ConfigDict(json_schema_extra={"required": []}) 

28 cv: Cv = pydantic.Field( 

29 default_factory=Cv, 

30 title="CV", 

31 description="The content of the CV.", 

32 ) 

33 design: Design = pydantic.Field( 

34 default_factory=ClassicTheme, 

35 title="Design", 

36 description=( 

37 "The design information of the CV. The default is the `classic` theme." 

38 ), 

39 ) 

40 locale: Locale = pydantic.Field( 

41 default_factory=EnglishLocale, 

42 title="Locale Catalog", 

43 description=( 

44 "The locale catalog of the CV to allow the support of multiple languages." 

45 ), 

46 ) 

47 settings: Settings = pydantic.Field( 

48 default_factory=Settings, 

49 title="RenderCV Settings", 

50 description="The settings of the RenderCV.", 

51 ) 

52 

53 _input_file_path: pathlib.Path | None = pydantic.PrivateAttr(default=None) 

54 

55 @pydantic.model_validator(mode="after") 

56 def set_input_file_path(self, info: pydantic.ValidationInfo) -> "RenderCVModel": 

57 """Store input file path in private attribute for path resolution. 

58 

59 Why: 

60 Photo paths and other relative references need input file location 

61 for resolution. Private attribute stores this after validation for 

62 downstream processing. 

63 

64 Args: 

65 info: Validation context containing input file path. 

66 

67 Returns: 

68 Model instance with _input_file_path set. 

69 """ 

70 self._input_file_path = get_input_file_path(info) 

71 return self