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

35 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-12-25 23:06 +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, replace_placeholders 

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\n-" 

25 " FULL_MONTH_NAME: Full name of the month\n- MONTH_ABBREVIATION: Abbreviation of" 

26 " the month\n- MONTH: Month as a number\n- MONTH_IN_TWO_DIGITS: Month as a number" 

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

28 ' in two digits\nThe default value is "MONTH_ABBREVIATION YEAR".\nThe default value' 

29 " 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 design: Optional[str] = pydantic.Field( 

41 default=None, 

42 title="`design` Field's YAML File", 

43 description=( 

44 "The file path to the yaml file containing the `design` field separately." 

45 ), 

46 ) 

47 

48 rendercv_settings: Optional[str] = pydantic.Field( 

49 default=None, 

50 title="`rendercv_settings` Field's YAML File", 

51 description=( 

52 "The file path to the yaml file containing the `rendercv_settings` field" 

53 " separately." 

54 ), 

55 ) 

56 

57 locale_catalog: Optional[str] = pydantic.Field( 

58 default=None, 

59 title="`locale_catalog` Field's YAML File", 

60 description=( 

61 "The file path to the yaml file containing the `locale_catalog` field" 

62 " separately." 

63 ), 

64 ) 

65 

66 output_folder_name: str = pydantic.Field( 

67 default="rendercv_output", 

68 title="Output Folder Name", 

69 description=( 

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

71 f" {file_path_placeholder_description_without_default}\nThe default value" 

72 ' is "rendercv_output".' 

73 ), 

74 ) 

75 

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

77 default=None, 

78 title="Local LaTeX Command", 

79 description=( 

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

81 ' "pdflatex".' 

82 ), 

83 ) 

84 

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

86 default=None, 

87 title="PDF Path", 

88 description=( 

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

90 f" generated. {file_path_placeholder_description}" 

91 ), 

92 ) 

93 

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

95 default=None, 

96 title="LaTeX Path", 

97 description=( 

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

99 f" be generated. {file_path_placeholder_description}" 

100 ), 

101 ) 

102 

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

104 default=None, 

105 title="HTML Path", 

106 description=( 

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

108 f" be generated. {file_path_placeholder_description}" 

109 ), 

110 ) 

111 

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

113 default=None, 

114 title="PNG Path", 

115 description=( 

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

117 f" generated. {file_path_placeholder_description}" 

118 ), 

119 ) 

120 

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

122 default=None, 

123 title="Markdown Path", 

124 description=( 

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

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

127 ), 

128 ) 

129 

130 dont_generate_html: bool = pydantic.Field( 

131 default=False, 

132 title="Don't Generate HTML", 

133 description=( 

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

135 " default value is False." 

136 ), 

137 ) 

138 

139 dont_generate_markdown: bool = pydantic.Field( 

140 default=False, 

141 title="Don't Generate Markdown", 

142 description=( 

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

144 " The default value is False." 

145 ), 

146 ) 

147 

148 dont_generate_png: bool = pydantic.Field( 

149 default=False, 

150 title="Don't Generate PNG", 

151 description=( 

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

153 " default value is False." 

154 ), 

155 ) 

156 

157 watch: bool = pydantic.Field( 

158 default=False, 

159 title="Re-run RenderCV When the Input File is Updated", 

160 description=( 

161 "A boolean value to determine whether to re-run RenderCV when the input" 

162 "file is updated. The default value is False." 

163 ), 

164 ) 

165 

166 @pydantic.field_validator( 

167 "output_folder_name", 

168 mode="before", 

169 ) 

170 @classmethod 

171 def replace_placeholders(cls, value: str) -> str: 

172 """Replaces the placeholders in a string with the corresponding values.""" 

173 return replace_placeholders(value) 

174 

175 @pydantic.field_validator( 

176 "design", 

177 "locale_catalog", 

178 "rendercv_settings", 

179 "pdf_path", 

180 "latex_path", 

181 "html_path", 

182 "png_path", 

183 "markdown_path", 

184 mode="before", 

185 ) 

186 @classmethod 

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

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

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

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

191 """ 

192 if value is None: 

193 return None 

194 

195 return convert_string_to_path(value) 

196 

197 

198class RenderCVSettings(RenderCVBaseModelWithoutExtraKeys): 

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

200 

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

202 default=None, 

203 title="Render Command Settings", 

204 description=( 

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

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

207 " the input file." 

208 ), 

209 ) 

210 bold_keywords: list[str] = pydantic.Field( 

211 default=[], 

212 title="Bold Keywords", 

213 description=( 

214 "The keywords that will be bold in the output. The default value is an" 

215 " empty list." 

216 ), 

217 )