user_data.py
Functions used to load user data.
AnswersMap
¶
Object that gathers answers from different sources.
Attributes:
Name | Type | Description |
---|---|---|
user |
AnyByStrDict
|
Answers provided by the user, interactively. |
init |
AnyByStrDict
|
Answers provided on init. This will hold those answers that come from See data. |
metadata |
AnyByStrDict
|
Data used to be able to reproduce the template. It comes from copier.template.Template.metadata. |
last |
AnyByStrDict
|
Data from the answers file. |
user_defaults |
AnyByStrDict
|
Default data from the user e.g. previously completed and restored data. See copier.main.Worker. |
Source code in copier/user_data.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 |
|
combined: Mapping[str, Any]
property
¶
Answers combined from different sources, sorted by priority.
hide(key)
¶
Remove an answer by key.
Source code in copier/user_data.py
115 116 117 |
|
old_commit()
¶
Commit when the project was updated from this template the last time.
Source code in copier/user_data.py
111 112 113 |
|
Question
¶
One question asked to the user.
All attributes are init kwargs.
Attributes:
Name | Type | Description |
---|---|---|
choices |
Sequence[Any] | dict[Any, Any]
|
Selections available for the user if the question requires them. Can be templated. |
multiselect |
bool
|
Indicates if the question supports multiple answers. Only supported by choices type. |
default |
Any
|
Default value presented to the user to make it easier to respond. Can be templated. |
help |
str
|
Additional text printed to the user, explaining the purpose of this question. Can be templated. |
multiline |
str | bool
|
Indicates if the question should allow multiline input. Defaults
to |
placeholder |
str
|
Text that appears if there's nothing written in the input field, but disappears as soon as the user writes anything. Can be templated. |
secret |
bool
|
Indicates if the question should be removed from the answers file.
If the question type is str, it will hide user input on the screen
by displaying asterisks: |
type_name |
bool
|
The type of question. Affects the rendering, validation and filtering. Can be templated. |
var_name |
str
|
Question name in the answers dict. |
validator |
str
|
Jinja template with which to validate the user input. This template will be rendered with the combined answers as variables; it should render nothing if the value is valid, and an error message to show to the user otherwise. |
when |
str | bool
|
Condition that, if |
Source code in copier/user_data.py
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 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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
cast_answer(answer)
¶
Cast answer to expected type.
Source code in copier/user_data.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
get_default()
¶
Get the default value for this question, casted to its expected type.
Source code in copier/user_data.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
get_default_rendered()
¶
Get default answer rendered for the questionary lib.
The questionary lib expects some specific data types, and returns it when the user answers. Sometimes you need to compare the response to the rendered one, or viceversa.
This helper allows such usages.
Source code in copier/user_data.py
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 |
|
get_message()
¶
Get the message that will be printed to the user.
Source code in copier/user_data.py
331 332 333 334 335 336 337 338 339 340 341 342 |
|
get_multiline()
¶
Get the value for multiline.
Source code in copier/user_data.py
407 408 409 |
|
get_placeholder()
¶
Render and obtain the placeholder.
Source code in copier/user_data.py
344 345 346 |
|
get_questionary_structure()
¶
Get the question in a format that the questionary lib understands.
Source code in copier/user_data.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
get_type_name()
¶
Render the type name and return it.
Source code in copier/user_data.py
398 399 400 401 402 403 404 405 |
|
get_when()
¶
Get skip condition for question.
Source code in copier/user_data.py
421 422 423 |
|
parse_answer(answer)
¶
Parse the answer according to the question's type.
Source code in copier/user_data.py
444 445 446 447 448 449 450 451 452 |
|
render_value(value, extra_answers=None)
¶
Render a single templated value using Jinja.
If the value cannot be used as a template, it will be returned as is.
extra_answers
are combined self self.answers.combined
when rendering
the template.
Source code in copier/user_data.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
validate_answer(answer)
¶
Validate user answer.
Source code in copier/user_data.py
411 412 413 414 415 416 417 418 419 |
|
load_answersfile_data(dst_path, answers_file=None)
¶
Load answers data from a $dst_path/$answers_file
file if it exists.
Source code in copier/user_data.py
484 485 486 487 488 489 490 491 492 493 |
|
parse_yaml_string(string)
¶
Parse a YAML string and raise a ValueError if parsing failed.
This method is needed because :meth:prompt
requires a ValueError
to repeat failed questions.
Source code in copier/user_data.py
472 473 474 475 476 477 478 479 480 481 |
|