|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
cookiecutter.exceptions |
|
5
|
|
|
----------------------- |
|
6
|
|
|
|
|
7
|
|
|
All exceptions used in the Cookiecutter code base are defined here. |
|
8
|
|
|
""" |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class CookiecutterException(Exception): |
|
12
|
|
|
""" |
|
13
|
|
|
Base exception class. All Cookiecutter-specific exceptions should subclass |
|
14
|
|
|
this class. |
|
15
|
|
|
""" |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class NonTemplatedInputDirException(CookiecutterException): |
|
19
|
|
|
""" |
|
20
|
|
|
Raised when a project's input dir is not templated. |
|
21
|
|
|
The name of the input directory should always contain a string that is |
|
22
|
|
|
rendered to something else, so that input_dir != output_dir. |
|
23
|
|
|
""" |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class UnknownTemplateDirException(CookiecutterException): |
|
27
|
|
|
""" |
|
28
|
|
|
Raised when Cookiecutter cannot determine which directory is the project |
|
29
|
|
|
template, e.g. more than one dir appears to be a template dir. |
|
30
|
|
|
""" |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
class MissingProjectDir(CookiecutterException): |
|
34
|
|
|
""" |
|
35
|
|
|
Raised during cleanup when remove_repo() can't find a generated project |
|
36
|
|
|
directory inside of a repo. |
|
37
|
|
|
""" |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
class ConfigDoesNotExistException(CookiecutterException): |
|
41
|
|
|
""" |
|
42
|
|
|
Raised when get_config() is passed a path to a config file, but no file |
|
43
|
|
|
is found at that path. |
|
44
|
|
|
""" |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
class InvalidConfiguration(CookiecutterException): |
|
48
|
|
|
""" |
|
49
|
|
|
Raised if the global configuration file is not valid YAML or is |
|
50
|
|
|
badly contructed. |
|
51
|
|
|
""" |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
class UnknownRepoType(CookiecutterException): |
|
55
|
|
|
""" |
|
56
|
|
|
Raised if a repo's type cannot be determined. |
|
57
|
|
|
""" |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
class VCSNotInstalled(CookiecutterException): |
|
61
|
|
|
""" |
|
62
|
|
|
Raised if the version control system (git or hg) is not installed. |
|
63
|
|
|
""" |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
class ContextDecodingException(CookiecutterException): |
|
67
|
|
|
""" |
|
68
|
|
|
Raised when a project's JSON context file can not be decoded. |
|
69
|
|
|
""" |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
class OutputDirExistsException(CookiecutterException): |
|
73
|
|
|
""" |
|
74
|
|
|
Raised when the output directory of the project exists already. |
|
75
|
|
|
""" |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
class InvalidModeException(CookiecutterException): |
|
79
|
|
|
""" |
|
80
|
|
|
Raised when cookiecutter is called with both `no_input==True` and |
|
81
|
|
|
`replay==True` at the same time. |
|
82
|
|
|
""" |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
class FailedHookException(CookiecutterException): |
|
86
|
|
|
""" |
|
87
|
|
|
Raised when a hook script fails |
|
88
|
|
|
""" |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
class UndefinedVariableInTemplate(CookiecutterException): |
|
92
|
|
|
"""Raised when a template uses a variable which is not defined in the |
|
93
|
|
|
context. |
|
94
|
|
|
""" |
|
95
|
|
|
def __init__(self, message, error, context): |
|
96
|
|
|
self.message = message |
|
97
|
|
|
self.error = error |
|
98
|
|
|
self.context = context |
|
99
|
|
|
|
|
100
|
|
|
def __str__(self): |
|
101
|
|
|
return ( |
|
102
|
|
|
"{self.message}. " |
|
103
|
|
|
"Error message: {self.error.message}. " |
|
104
|
|
|
"Context: {self.context}" |
|
105
|
|
|
).format(**locals()) |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
class UnknownExtension(CookiecutterException): |
|
109
|
|
|
"""Raised when an environment is unable to import a required extension.""" |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
class RepositoryNotFound(CookiecutterException): |
|
113
|
|
|
""" |
|
114
|
|
|
Raised when the specified cookiecutter repository doesn't exist. |
|
115
|
|
|
""" |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
class RepositoryCloneFailed(CookiecutterException): |
|
119
|
|
|
"""Raised when a cookiecutter template can't be cloned.""" |
|
120
|
|
|
|
|
121
|
|
|
BRANCH_ERRORS = [ |
|
122
|
|
|
'error: pathspec', |
|
123
|
|
|
'unknown revision', |
|
124
|
|
|
] |
|
125
|
|
|
|
|
126
|
|
|
def __init__(self, exception, repo_url, checkout): |
|
127
|
|
|
if 'not found' in exception.output.lower(): |
|
128
|
|
|
raise RepositoryNotFound( |
|
129
|
|
|
'The repository {} could not be found, ' |
|
130
|
|
|
'have you made a typo?'.format(repo_url) |
|
131
|
|
|
) |
|
132
|
|
|
elif any(error in exception.output for error in self.BRANCH_ERRORS): |
|
133
|
|
|
super(RepositoryCloneFailed, self).__init__( |
|
134
|
|
|
'The {} branch of repository {} could not found, ' |
|
135
|
|
|
'have you made a typo?'.format(checkout, repo_url) |
|
136
|
|
|
) |
|
137
|
|
|
else: |
|
138
|
|
|
raise exception |
|
139
|
|
|
|