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
parse_validation_errors(exception)
¶
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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 |
|
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.