rendercv.data.reader
¶
The rendercv.data.reader
module contains the functions that are used to read the input
file (YAML or JSON) and return them as an instance of RenderCVDataModel
, which is a
Pydantic data model of RenderCV's data format.
make_given_keywords_bold_in_sections(sections_input, keywords)
¶
Iterate over the dictionary recursively and make the given keywords bold.
Parameters:
-
sections_input
(Sections
) –TODO
-
keywords
(list[str]
) –The keywords to make bold.
Returns:
-
Sections
–The dictionary with the given keywords bold.
Source code in rendercv/data/reader.py
get_error_message_and_location_and_value_from_a_custom_error(error_string)
¶
Look at a string and figure out if it's a custom error message that has been
sent from rendercv.data.reader.read_input_file
. If it is, then return the custom
message, location, and the input value.
This is done because sometimes we raise an error about a specific field in the model validation level, but Pydantic doesn't give us the exact location of the error because it's a model-level error. So, we raise a custom error with three string arguments: message, location, and input value. Those arguments then combined into a string by Python. This function is used to parse that custom error message and return the three values.
Parameters:
-
error_string
(str
) –The error message.
Returns:
-
tuple[Optional[str], Optional[str], Optional[str]]
–The custom message, location, and the input value.
Source code in rendercv/data/reader.py
get_coordinates_of_a_key_in_a_yaml_file(yaml_file_as_string, location)
¶
Find the coordinates of a key in a YAML file.
Parameters:
-
yaml_file_as_string
(str
) –The YAML file as a string.
-
location
(list[str]
) –The location of the key in the YAML file. For example,
['cv', 'sections', 'education', '0', 'degree']
.
Returns:
-
tuple[int, int]
–The coordinates of the key in the YAML file in the format
-
tuple[int, int]
–((start_line, start_column), (end_line, end_column)).
-
tuple[tuple[int, int], tuple[int, int]]
–(Line and column numbers are 0-indexed.)
Source code in rendercv/data/reader.py
parse_validation_errors(exception, yaml_file_as_string=None)
¶
Take a Pydantic validation error, parse it, and return a list of error dictionaries that contain the error messages, locations, and the input values.
Pydantic's ValidationError
object is a complex object that contains a lot of
information about the error. This function takes a ValidationError
object and
extracts the error messages, locations, and the input values.
Parameters:
-
exception
(ValidationError
) –The Pydantic validation error object.
Returns:
-
list[dict[str, str]]
–A list of error dictionaries that contain the error messages, locations, and the
-
list[dict[str, str]]
–input values.
Source code in rendercv/data/reader.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
read_a_yaml_file(file_path_or_contents)
¶
Read a YAML file and return its content as a dictionary. The YAML file can be given as a path to the file or as the contents of the file as a string.
Parameters:
-
file_path_or_contents
(Path | str
) –The path to the YAML file or the contents of the YAML file as a string.
Returns:
-
dict
–The content of the YAML file as a dictionary.
Source code in rendercv/data/reader.py
validate_input_dictionary_and_return_the_data_model(input_dictionary, context=None)
¶
Validate the input dictionary by creating an instance of RenderCVDataModel
,
which is a Pydantic data model of RenderCV's data format.
Parameters:
-
input_dictionary
(dict
) –The input dictionary.
-
context
(Optional[dict]
, default:None
) –The context dictionary that is used to validate the input dictionary. It's used to send the input file path with the context object, but it's not required.
Returns:
-
RenderCVDataModel
–The data model.
Source code in rendercv/data/reader.py
read_input_file(file_path_or_contents)
¶
Read the input file (YAML or JSON) and return them as an instance of
RenderCVDataModel
, which is a Pydantic data model of RenderCV's data format.
Parameters:
-
file_path_or_contents
(Path | str
) –The path to the input file or the contents of the input file as a string.
Returns:
-
RenderCVDataModel
–The data model.