Coverage for rendercv/data/models/rendercv_settings.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-10-07 17:51 +0000

1""" 

2The `rendercv.models.rendercv_settings` module contains the data model of the 

3`rendercv_settings` field of the input file. 

4""" 

5 

6import pathlib 

7from typing import Optional 

8 

9import pydantic 

10 

11from .base import RenderCVBaseModelWithoutExtraKeys 

12from .computers import convert_string_to_path 

13 

14file_path_placeholder_description = ( 

15 "The following placeholders can be used:\n- FULL_MONTH_NAME: Full name of the" 

16 " month\n- MONTH_ABBREVIATION: Abbreviation of the month\n- MONTH: Month as a" 

17 " number\n- MONTH_IN_TWO_DIGITS: Month as a number in two digits\n- YEAR: Year as a" 

18 " number\n- YEAR_IN_TWO_DIGITS: Year as a number in two digits\n- NAME: The name of" 

19 " the CV owner\n- NAME_IN_SNAKE_CASE: The name of the CV owner in snake case\n-" 

20 " NAME_IN_LOWER_SNAKE_CASE: The name of the CV owner in lower snake case\n-" 

21 " NAME_IN_UPPER_SNAKE_CASE: The name of the CV owner in upper snake case\n-" 

22 " NAME_IN_KEBAB_CASE: The name of the CV owner in kebab case\n-" 

23 " NAME_IN_LOWER_KEBAB_CASE: The name of the CV owner in lower kebab case\n-" 

24 " NAME_IN_UPPER_KEBAB_CASE: The name of the CV owner in upper kebab case\nThe" 

25 " default value is an empty string.\n- FULL_MONTH_NAME: Full name of the month\n-" 

26 " MONTH_ABBREVIATION: Abbreviation of the month\n- MONTH: Month as a number\n-" 

27 " MONTH_IN_TWO_DIGITS: Month as a number in two digits\n- YEAR: Year as a number\n-" 

28 " YEAR_IN_TWO_DIGITS: Year as a number in two digits\nThe default value is" 

29 ' "MONTH_ABBREVIATION YEAR".\nThe default value is null.' 

30) 

31 

32file_path_placeholder_description_without_default = ( 

33 file_path_placeholder_description.replace("\nThe default value is null.", "") 

34) 

35 

36 

37class RenderCommandSettings(RenderCVBaseModelWithoutExtraKeys): 

38 """This class is the data model of the `render` command's settings.""" 

39 

40 output_folder_name: str = pydantic.Field( 

41 default="rendercv_output", 

42 title="Output Folder Name", 

43 description=( 

44 "The name of the folder where the output files will be saved." 

45 f" {file_path_placeholder_description_without_default}\nThe default value" 

46 ' is "rendercv_output".' 

47 ), 

48 ) 

49 

50 use_local_latex_command: Optional[str] = pydantic.Field( 

51 default=None, 

52 title="Local LaTeX Command", 

53 description=( 

54 "The command to compile the LaTeX file to a PDF file. The default value is" 

55 ' "pdflatex".' 

56 ), 

57 ) 

58 

59 pdf_path: Optional[pathlib.Path] = pydantic.Field( 

60 default=None, 

61 title="PDF Path", 

62 description=( 

63 "The path of the PDF file. If it is not provided, the PDF file will not be" 

64 f" generated. {file_path_placeholder_description}" 

65 ), 

66 ) 

67 

68 latex_path: Optional[pathlib.Path] = pydantic.Field( 

69 default=None, 

70 title="LaTeX Path", 

71 description=( 

72 "The path of the LaTeX file. If it is not provided, the LaTeX file will not" 

73 f" be generated. {file_path_placeholder_description}" 

74 ), 

75 ) 

76 

77 html_path: Optional[pathlib.Path] = pydantic.Field( 

78 default=None, 

79 title="HTML Path", 

80 description=( 

81 "The path of the HTML file. If it is not provided, the HTML file will not" 

82 f" be generated. {file_path_placeholder_description}" 

83 ), 

84 ) 

85 

86 png_path: Optional[pathlib.Path] = pydantic.Field( 

87 default=None, 

88 title="PNG Path", 

89 description=( 

90 "The path of the PNG file. If it is not provided, the PNG file will not be" 

91 f" generated. {file_path_placeholder_description}" 

92 ), 

93 ) 

94 

95 markdown_path: Optional[pathlib.Path] = pydantic.Field( 

96 default=None, 

97 title="Markdown Path", 

98 description=( 

99 "The path of the Markdown file. If it is not provided, the Markdown file" 

100 f" will not be generated. {file_path_placeholder_description}" 

101 ), 

102 ) 

103 

104 dont_generate_html: bool = pydantic.Field( 

105 default=False, 

106 title="Generate HTML Flag", 

107 description=( 

108 "A boolean value to determine whether the HTML file will be generated. The" 

109 " default value is False." 

110 ), 

111 ) 

112 

113 dont_generate_markdown: bool = pydantic.Field( 

114 default=False, 

115 title="Generate Markdown Flag", 

116 description=( 

117 "A boolean value to determine whether the Markdown file will be generated." 

118 " The default value is False." 

119 ), 

120 ) 

121 

122 dont_generate_png: bool = pydantic.Field( 

123 default=False, 

124 title="Generate PNG Flag", 

125 description=( 

126 "A boolean value to determine whether the PNG file will be generated. The" 

127 " default value is False." 

128 ), 

129 ) 

130 

131 @pydantic.field_validator( 

132 "pdf_path", 

133 "latex_path", 

134 "html_path", 

135 "png_path", 

136 "markdown_path", 

137 mode="before", 

138 ) 

139 @classmethod 

140 def convert_string_to_path(cls, value: Optional[str]) -> Optional[pathlib.Path]: 

141 """Converts a string to a `pathlib.Path` object by replacing the placeholders 

142 with the corresponding values. If the path is not an absolute path, it is 

143 converted to an absolute path by prepending the current working directory. 

144 """ 

145 if value is None: 

146 return None 

147 

148 return convert_string_to_path(value) 

149 

150 

151class RenderCVSettings(RenderCVBaseModelWithoutExtraKeys): 

152 """This class is the data model of the RenderCV settings.""" 

153 

154 render_command: Optional[RenderCommandSettings] = pydantic.Field( 

155 default=None, 

156 title="Render Command Settings", 

157 description=( 

158 "RenderCV's `render` command settings. They are the same as the command" 

159 " line arguments. CLI arguments have higher priority than the settings in" 

160 " the input file." 

161 ), 

162 )