template.py
Tools related to template management.
Template
¶
Object that represents a template and its current state.
Attributes:
Name | Type | Description |
---|---|---|
url |
str
|
Absolute origin that points to the template. It can be:
|
ref |
OptStr
|
The tag to checkout in the template. Only used if If Usually it should be a tag, or |
use_prereleases |
bool
|
When Only used if:
Helpful if you want to test templates before doing a proper release, but you need some features that require a proper PEP440 version identifier. |
Source code in copier/template.py
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 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
|
answers_relpath()
¶
Get the answers file relative path, as specified in the template.
If not specified, returns the default .copier-answers.yml
.
See answers_file.
Source code in copier/template.py
198 199 200 201 202 203 204 205 206 207 208 |
|
commit()
¶
If the template is VCS-tracked, get its commit description.
Source code in copier/template.py
210 211 212 213 214 215 |
|
commit_hash()
¶
If the template is VCS-tracked, get its commit full hash.
Source code in copier/template.py
217 218 219 220 221 |
|
config_data()
¶
Get config from the template.
It reads the copier.yml
file to get its
settings.
Source code in copier/template.py
223 224 225 226 227 228 229 230 231 232 233 |
|
default_answers()
¶
Get default answers for template's questions.
Source code in copier/template.py
235 236 237 238 |
|
envops()
¶
Get the Jinja configuration specified in the template, or default values.
See envops.
Source code in copier/template.py
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 |
|
exclude()
¶
Get exclusions specified in the template, or default ones.
See exclude.
Source code in copier/template.py
278 279 280 281 282 283 284 |
|
jinja_extensions()
¶
Get Jinja2 extensions specified in the template, or ()
.
See jinja_extensions.
Source code in copier/template.py
286 287 288 289 290 291 292 |
|
local_abspath()
¶
Get the absolute path to the template on disk.
This may clone it if url
points to a VCS-tracked template.
Dirty changes for local VCS-tracked templates will be copied.
Source code in copier/template.py
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
|
metadata()
¶
Get template metadata.
This data, if any, should be saved in the answers file to be able to restore the template to this same state.
Source code in copier/template.py
294 295 296 297 298 299 300 301 302 303 304 |
|
migration_tasks(stage, from_template)
¶
Get migration objects that match current version spec.
Versions are compared using PEP 440.
See migrations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage |
Literal['task', 'before', 'after']
|
A valid stage name to find tasks for. |
required |
from_template |
'Template'
|
Original template, from which we are migrating. |
required |
Source code in copier/template.py
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 |
|
min_copier_version()
¶
Gets minimal copier version for the template and validates it.
See min_copier_version.
Source code in copier/template.py
344 345 346 347 348 349 350 351 352 353 |
|
questions_data()
¶
Get questions from the template.
See questions.
Source code in copier/template.py
355 356 357 358 359 360 361 |
|
secret_questions()
¶
Get names of secret questions from the template.
These questions shouldn't be saved into the answers file.
Source code in copier/template.py
363 364 365 366 367 368 369 370 371 372 373 |
|
skip_if_exists()
¶
Get skip patterns from the template.
These files will never be rewritten when rendering the template.
See skip_if_exists.
Source code in copier/template.py
375 376 377 378 379 380 381 382 383 |
|
subdirectory()
¶
Get the subdirectory as specified in the template.
The subdirectory points to the real template code, allowing the templater to separate it from other template assets, such as docs, tests, etc.
See subdirectory.
Source code in copier/template.py
385 386 387 388 389 390 391 392 393 394 395 |
|
tasks()
¶
Get tasks defined in the template.
See tasks.
Source code in copier/template.py
397 398 399 400 401 402 403 |
|
templates_suffix()
¶
Get the suffix defined for templates.
By default: .jinja
.
See templates_suffix.
Source code in copier/template.py
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
url_expanded()
¶
Get usable URL.
url
can be specified in shortcut
format, which wouldn't be understood by the underlying VCS system. This
property returns the expanded version, which should work properly.
Source code in copier/template.py
446 447 448 449 450 451 452 453 454 |
|
vcs()
¶
Get VCS system used by the template, if any.
Source code in copier/template.py
480 481 482 483 484 |
|
version()
¶
PEP440-compliant version object.
Source code in copier/template.py
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
|
filter_config(data)
¶
Separates config and questions data.
Source code in copier/template.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
load_template_config(conf_path, quiet=False)
¶
Load the copier.yml
file.
This is like a simple YAML load, but applying all specific quirks needed
for the copier.yml
file.
For example, it supports the !include
tag with glob includes, and
merges multiple sections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf_path |
Path
|
The path to the |
required |
quiet |
bool
|
Used to configure the exception. |
False
|
Raises:
Type | Description |
---|---|
InvalidConfigFileError
|
When the file is formatted badly. |
Source code in copier/template.py
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 |
|
verify_copier_version(version_str)
¶
Raise an error if the current Copier version is less than the given version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
version_str |
str
|
Minimal copier version for the template. |
required |
Source code in copier/template.py
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 |
|