11
11
logger = logging .getLogger ("static_precompiler" )
12
12
13
13
14
- __all__ = (
15
- "BaseCompiler" ,
16
- )
14
+ __all__ = ("BaseCompiler" ,)
17
15
18
16
19
17
class BaseCompiler (object ):
@@ -24,7 +22,7 @@ class BaseCompiler(object):
24
22
output_extension = None
25
23
26
24
def is_supported (self , source_path ):
27
- """ Return True iff provided source file type is supported by this precompiler.
25
+ """Return True iff provided source file type is supported by this precompiler.
28
26
29
27
:param source_path: relative path to a source file
30
28
:type source_path: str
@@ -35,7 +33,7 @@ def is_supported(self, source_path):
35
33
36
34
# noinspection PyMethodMayBeStatic
37
35
def get_full_source_path (self , source_path ):
38
- """ Return the full path to the given source file.
36
+ """Return the full path to the given source file.
39
37
Check if the source file exists.
40
38
The returned path is OS-dependent.
41
39
@@ -63,7 +61,7 @@ def get_full_source_path(self, source_path):
63
61
return full_path
64
62
65
63
def get_output_filename (self , source_filename ):
66
- """ Return the name of compiled file based on the name of source file.
64
+ """Return the name of compiled file based on the name of source file.
67
65
68
66
:param source_filename: name of a source file
69
67
:type source_filename: str
@@ -73,7 +71,7 @@ def get_output_filename(self, source_filename):
73
71
return "{0}.{1}" .format (os .path .splitext (source_filename )[0 ], self .output_extension )
74
72
75
73
def get_output_path (self , source_path ):
76
- """ Get relative path to compiled file based for the given source file.
74
+ """Get relative path to compiled file based for the given source file.
77
75
The returned path is in posix format.
78
76
79
77
:param source_path: relative path to a source file
@@ -87,7 +85,7 @@ def get_output_path(self, source_path):
87
85
return posixpath .join (settings .OUTPUT_DIR , source_dir , output_filename )
88
86
89
87
def get_full_output_path (self , source_path ):
90
- """ Get full path to compiled file based for the given source file.
88
+ """Get full path to compiled file based for the given source file.
91
89
The returned path is OS-dependent.
92
90
93
91
:param source_path: relative path to a source file
@@ -98,7 +96,7 @@ def get_full_output_path(self, source_path):
98
96
return os .path .join (settings .ROOT , utils .normalize_path (self .get_output_path (source_path )))
99
97
100
98
def get_source_mtime (self , source_path ):
101
- """ Get the modification time of the source file.
99
+ """Get the modification time of the source file.
102
100
103
101
:param source_path: relative path to a source file
104
102
:type source_path: str
@@ -108,7 +106,7 @@ def get_source_mtime(self, source_path):
108
106
return mtime .get_mtime (self .get_full_source_path (source_path ))
109
107
110
108
def get_output_mtime (self , source_path ):
111
- """ Get the modification time of the compiled file.
109
+ """Get the modification time of the compiled file.
112
110
Return None of compiled file does not exist.
113
111
114
112
:param source_path: relative path to a source file
@@ -122,7 +120,7 @@ def get_output_mtime(self, source_path):
122
120
return mtime .get_mtime (full_output_path )
123
121
124
122
def should_compile (self , source_path , from_management = False ):
125
- """ Return True iff provided source file should be compiled.
123
+ """Return True iff provided source file should be compiled.
126
124
127
125
:param source_path: relative path to a source file
128
126
:type source_path: str
@@ -151,7 +149,7 @@ def should_compile(self, source_path, from_management=False):
151
149
return False
152
150
153
151
def get_source (self , source_path ):
154
- """ Get the source code to be compiled.
152
+ """Get the source code to be compiled.
155
153
156
154
:param source_path: relative path to a source file
157
155
:type source_path: str
@@ -161,7 +159,7 @@ def get_source(self, source_path):
161
159
return utils .read_file (self .get_full_source_path (source_path ))
162
160
163
161
def compile (self , source_path , from_management = False , verbosity = 0 ):
164
- """ Compile the given source path and return relative path to the compiled file.
162
+ """Compile the given source path and return relative path to the compiled file.
165
163
Raise ValueError is the source file type is not supported.
166
164
May raise a StaticCompilationError if something goes wrong with compilation.
167
165
:param source_path: relative path to a source file
@@ -173,9 +171,7 @@ def compile(self, source_path, from_management=False, verbosity=0):
173
171
174
172
"""
175
173
if not self .is_supported (source_path ):
176
- raise ValueError ("'{0}' file type is not supported by '{1}'" .format (
177
- source_path , self .__class__ .__name__
178
- ))
174
+ raise ValueError ("'{0}' file type is not supported by '{1}'" .format (source_path , self .__class__ .__name__ ))
179
175
180
176
compiled_path = self .get_output_path (source_path )
181
177
@@ -196,21 +192,21 @@ def compile(self, source_path, from_management=False, verbosity=0):
196
192
return compiled_path
197
193
198
194
def compile_lazy (self , source_path ):
199
- """ Return a lazy object which, when translated to string, compiles the specified source path and returns
200
- the path to the compiled file.
201
- Raise ValueError is the source file type is not supported.
202
- May raise a StaticCompilationError if something goes wrong with compilation.
203
- :param source_path: relative path to a source file
204
- :type source_path: str
195
+ """Return a lazy object which, when translated to string, compiles the specified source path and returns
196
+ the path to the compiled file.
197
+ Raise ValueError is the source file type is not supported.
198
+ May raise a StaticCompilationError if something goes wrong with compilation.
199
+ :param source_path: relative path to a source file
200
+ :type source_path: str
205
201
206
- :returns: str
202
+ :returns: str
207
203
"""
208
204
return encoding .force_text (self .compile (source_path ))
209
205
210
206
compile_lazy = functional .lazy (compile_lazy , str )
211
207
212
208
def compile_file (self , source_path ):
213
- """ Compile the source file. Return the relative path to compiled file.
209
+ """Compile the source file. Return the relative path to compiled file.
214
210
May raise a StaticCompilationError if something goes wrong with compilation.
215
211
216
212
:param source_path: path to the source file
@@ -221,7 +217,7 @@ def compile_file(self, source_path):
221
217
raise NotImplementedError
222
218
223
219
def compile_source (self , source ):
224
- """ Compile the source code. May raise a StaticCompilationError
220
+ """Compile the source code. May raise a StaticCompilationError
225
221
if something goes wrong with compilation.
226
222
227
223
:param source: source code
@@ -232,7 +228,7 @@ def compile_source(self, source):
232
228
raise NotImplementedError
233
229
234
230
def find_dependencies (self , source_path ):
235
- """ Find the dependencies for the given source file.
231
+ """Find the dependencies for the given source file.
236
232
237
233
:param source_path: relative path to a source file
238
234
:type source_path: str
@@ -242,7 +238,7 @@ def find_dependencies(self, source_path):
242
238
243
239
# noinspection PyMethodMayBeStatic
244
240
def get_dependencies (self , source_path ):
245
- """ Get the saved dependencies for the given source file.
241
+ """Get the saved dependencies for the given source file.
246
242
247
243
:param source_path: relative path to a source file
248
244
:type source_path: str
@@ -261,7 +257,7 @@ def get_dependencies(self, source_path):
261
257
262
258
# noinspection PyMethodMayBeStatic
263
259
def get_dependents (self , source_path ):
264
- """ Get a list of files that depends on the given source file.
260
+ """Get a list of files that depends on the given source file.
265
261
266
262
:param source_path: relative path to a source file
267
263
:type source_path: str
@@ -280,7 +276,7 @@ def get_dependents(self, source_path):
280
276
281
277
# noinspection PyMethodMayBeStatic
282
278
def update_dependencies (self , source_path , dependencies ):
283
- """ Updates the saved dependencies for the given source file.
279
+ """Updates the saved dependencies for the given source file.
284
280
285
281
:param source_path: relative path to a source file
286
282
:type source_path: str
@@ -291,9 +287,7 @@ def update_dependencies(self, source_path, dependencies):
291
287
if not dependencies :
292
288
models .Dependency .objects .filter (source = source_path ).delete ()
293
289
else :
294
- models .Dependency .objects .filter (
295
- source = source_path
296
- ).exclude (
290
+ models .Dependency .objects .filter (source = source_path ).exclude (
297
291
depends_on__in = dependencies ,
298
292
).delete ()
299
293
for dependency in dependencies :
0 commit comments