tools.py
Some utility functions.
TemporaryDirectory
¶
Bases: tempfile.TemporaryDirectory
A custom version of tempfile.TemporaryDirectory
that handles read-only files better.
On Windows, before Python 3.8, shutil.rmtree
does not handle read-only files very well.
This custom class makes use of a special error handler
to make sure that a temporary directory containing read-only files (typically created
when git-cloning a repository) is properly cleaned-up (i.e. removed) after using it
in a context manager.
Source code in copier/tools.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
cast_str_to_bool(value)
¶
Parse anything to bool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
Any
|
Anything to be casted to a bool. Tries to be as smart as possible.
|
required |
Source code in copier/tools.py
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 |
|
copier_version()
¶
Get closest match for the installed copier version.
Source code in copier/tools.py
44 45 46 47 48 49 50 51 52 53 54 55 |
|
force_str_end(original_str, end='\n')
¶
Make sure a original_str
ends with end
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original_str |
str
|
String that you want to ensure ending. |
required |
end |
str
|
String that must exist at the end of |
'\n'
|
Source code in copier/tools.py
120 121 122 123 124 125 126 127 128 129 |
|
handle_remove_readonly(func, path, exc)
¶
Handle errors when trying to remove read-only files through shutil.rmtree
.
This handler makes sure the given file is writable, then re-execute the given removal function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable
|
An OS-dependant function used to remove a file. |
required |
path |
str
|
The path to the file to remove. |
required |
exc |
Tuple[BaseException, OSError, TracebackType]
|
A |
required |
Source code in copier/tools.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|