main.py
¶
The main functions, used to generate or update projects.
copy(src_path=None, dst_path='.', data=None, *, answers_file=None, exclude=None, skip_if_exists=None, tasks=None, envops=None, extra_paths=None, pretend=False, force=False, skip=False, quiet=False, cleanup_on_error=True, vcs_ref=None, only_diff=True, subdirectory=None)
¶
Uses the template in src_path
to generate a new project at dst_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_path |
Optional[str] |
Absolute path to the project skeleton. May be a version control system URL.
If |
None |
dst_path |
Union[str, pathlib.Path] |
Absolute path to where to render the skeleton |
'.' |
data |
Dict[str, Any] |
Optional. Data to be passed to the templates in addtion to the user data
from a |
None |
answers_file |
Optional[str] |
Path where to obtain the answers recorded from the last update.
The path must be relative to |
None |
exclude |
Optional[Sequence[str]] |
A list of names or gitignore-style patterns matching files or folders that must not be copied. |
None |
skip_if_exists |
Optional[Sequence[str]] |
A list of names or gitignore-style patterns matching files or folders, that are skipped if another with the same name already exists in the destination folder. (It only makes sense if you are copying to a folder that already exists). |
None |
tasks |
Optional[Sequence[str]] |
Optional lists of commands to run in order after finishing the copy. Like in the templates files, you can use variables on the commands that will be replaced by the real values before running the command. If one of the commands fail, the rest of them will not run. |
None |
envops |
Dict[str, Any] |
Extra options for the Jinja template environment. |
None |
extra_paths |
Optional[Sequence[str]] |
Optional. Additional paths, outside the |
None |
pretend |
Optional[bool] |
Run but do not make any changes. |
False |
force |
Optional[bool] |
Overwrite files that already exist, without asking. |
False |
skip |
Optional[bool] |
Skip files that already exist, without asking. |
False |
quiet |
Optional[bool] |
Suppress the status output. |
False |
cleanup_on_error |
Optional[bool] |
Remove the destination folder if the copy process or one of the tasks fail. |
True |
vcs_ref |
Optional[str] |
VCS reference to checkout in the template. |
None |
only_diff |
Optional[bool] |
Try to update only the template diff. |
True |
subdirectory |
Optional[str] |
Specify a subdirectory to use when generating the project. |
None |
Source code in copier/main.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 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 |
|
copy_local(conf)
¶
Use the given configuration to generate a project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
ConfigData |
Configuration obtained with |
required |
Source code in copier/main.py
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 |
|
files_are_identical(src_path, dst_path, content)
¶
Tell whether two files are identical.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
src_path |
Path |
Source file. |
required |
dst_path |
Path |
Destination file. |
required |
content |
Optional[str] |
File contents. |
required |
Returns:
Type | Description |
---|---|
bool |
True if the files are identical, False otherwise. |
Source code in copier/main.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
get_source_paths(conf, folder, rel_folder, files, render, must_filter)
¶
Get the paths to all the files to render.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
ConfigData |
Configuration obtained with |
required |
folder |
Path |
required | |
rel_folder |
Path |
Relative path to the folder. |
required |
files |
Sequence[str] |
required | |
render |
Renderer |
The template renderer instance. |
required |
must_filter |
Callable[[Union[str, pathlib.Path]], bool] |
A callable telling whether to skip rendering a file. |
required |
Returns:
Type | Description |
---|---|
List[Tuple[pathlib.Path, pathlib.Path]] |
The list of files to render. |
Source code in copier/main.py
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 |
|
overwrite_file(conf, dst_path, rel_path)
¶
Handle the case when there's an update conflict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
ConfigData |
Configuration obtained with |
required |
dst_path |
Path |
The destination file. |
required |
rel_path |
Path |
The new file. |
required |
Returns:
Type | Description |
---|---|
bool |
True if the overwrite was forced or the user answered yes, False if skipped by configuration or if the user answered no. |
Source code in copier/main.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
render_file(conf, rel_path, src_path, render, must_skip)
¶
Process or copy a file of the skeleton.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
ConfigData |
Configuration obtained with |
required |
rel_path |
Path |
The relative path to the file. |
required |
src_path |
Path |
required | |
render |
Renderer |
The template renderer instance. |
required |
must_skip |
Callable[[Union[str, pathlib.Path]], bool] |
A callable telling whether to skip a file. |
required |
Source code in copier/main.py
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 |
|
render_folder(rel_folder, conf)
¶
Render a complete folder.
This function renders the folder's name as well as its contents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rel_folder |
Path |
The relative path to the folder. |
required |
conf |
ConfigData |
Configuration obtained with |
required |
Source code in copier/main.py
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 |
|
run_tasks(conf, render, tasks)
¶
Run the given tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
ConfigData |
Configuration obtained with |
required |
render |
Renderer |
The template renderer instance. |
required |
tasks |
Sequence[Dict] |
The list of tasks to run. |
required |
Source code in copier/main.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
|
update_diff(conf)
¶
Use the given configuration to update a project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf |
ConfigData |
Configuration obtained with |
required |
Source code in copier/main.py
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 |
|