1717
1818class DjangoTemplatePluginException (Exception ):
1919 """Used for any errors from the plugin itself."""
20+
2021 pass
2122
2223
@@ -42,6 +43,7 @@ def check_debug():
4243 # I _think_ this check is all that's needed and the 3 "hasattr" checks
4344 # below can be removed, but it's not clear how to verify that
4445 from django .apps import apps
46+
4547 if not apps .ready :
4648 return False
4749
@@ -58,13 +60,9 @@ def check_debug():
5860
5961 for engine in django .template .engines .all ():
6062 if not isinstance (engine , django .template .backends .django .DjangoTemplates ):
61- raise DjangoTemplatePluginException (
62- "Can't use non-Django templates."
63- )
63+ raise DjangoTemplatePluginException ("Can't use non-Django templates." )
6464 if not engine .engine .debug :
65- raise DjangoTemplatePluginException (
66- "Template debugging must be enabled in settings."
67- )
65+ raise DjangoTemplatePluginException ("Template debugging must be enabled in settings." )
6866
6967 return True
7068
@@ -112,16 +110,15 @@ class DjangoTemplatePlugin(
112110 coverage .plugin .CoveragePlugin ,
113111 coverage .plugin .FileTracer ,
114112):
115-
116113 def __init__ (self , options ):
117114 extensions = options .get ("template_extensions" , "html,htm,txt" )
118115 self .extensions = [e .strip () for e in extensions .split ("," )]
119116
120117 self .debug_checked = False
121118
122- self .django_template_dir = os .path .normcase (os . path . realpath (
123- os .path .dirname (django .template .__file__ )
124- ))
119+ self .django_template_dir = os .path .normcase (
120+ os .path .realpath ( os . path . dirname (django .template .__file__ ) )
121+ )
125122
126123 self .source_map = {}
127124
@@ -130,11 +127,10 @@ def __init__(self, options):
130127 def sys_info (self ):
131128 return [
132129 ("django_template_dir" , self .django_template_dir ),
133- ("environment" , sorted (
134- ("{} = {}" .format (k , v ))
135- for k , v in os .environ .items ()
136- if "DJANGO" in k
137- )),
130+ (
131+ "environment" ,
132+ sorted (("{} = {}" .format (k , v )) for k , v in os .environ .items () if "DJANGO" in k ),
133+ ),
138134 ]
139135
140136 def configure (self , config ):
@@ -159,7 +155,7 @@ def find_executable_files(self, src_dir):
159155 # funny characters that probably mean they are editor junk.
160156 rx = r"^[^.#~!$@%^&*()+=,]+\.(" + "|" .join (self .extensions ) + r")$"
161157
162- for ( dirpath , dirnames , filenames ) in os .walk (src_dir ):
158+ for dirpath , dirnames , filenames in os .walk (src_dir ):
163159 if dirpath == self .html_report_dir :
164160 # Don't confuse the HTML report with HTML templates.
165161 continue
@@ -196,7 +192,7 @@ def line_number_range(self, frame):
196192 if 0 :
197193 dump_frame (frame , label = "line_number_range" )
198194
199- render_self = frame .f_locals [' self' ]
195+ render_self = frame .f_locals [" self" ]
200196 if isinstance (render_self , (NodeList , Template )):
201197 return - 1 , - 1
202198
@@ -226,13 +222,11 @@ def line_number_range(self, frame):
226222 filename = filename_for_frame (frame )
227223 line_map = self .get_line_map (filename )
228224 start = get_line_number (line_map , s_start )
229- end = get_line_number (line_map , s_end - 1 )
225+ end = get_line_number (line_map , s_end - 1 )
230226 if start < 0 or end < 0 :
231227 start , end = - 1 , - 1
232228 if SHOW_TRACING :
233- print ("line_number_range({}) -> {}" .format (
234- filename , (start , end )
235- ))
229+ print ("line_number_range({}) -> {}" .format (filename , (start , end )))
236230 return start , end
237231
238232 # --- FileTracer helpers
@@ -251,9 +245,9 @@ def get_line_map(self, filename):
251245 """
252246 if filename not in self .source_map :
253247 template_source = read_template_source (filename )
254- if 0 : # change to see the template text
248+ if 0 : # change to see the template text
255249 for i in range (0 , len (template_source ), 10 ):
256- print ("%3d: %r" % (i , template_source [i : i + 10 ]))
250+ print ("%3d: %r" % (i , template_source [i : i + 10 ]))
257251 self .source_map [filename ] = make_line_map (template_source )
258252 return self .source_map [filename ]
259253
@@ -292,7 +286,8 @@ def lines(self):
292286 for token in tokens :
293287 if SHOW_PARSING :
294288 print (
295- "%10s %2d: %r" % (
289+ "%10s %2d: %r"
290+ % (
296291 token .token_type .capitalize (),
297292 token .lineno ,
298293 token .contents ,
@@ -352,11 +347,9 @@ def lines(self):
352347 # When a tag is not at the start of a line, the preceding
353348 # TEXT token ends with whitespace and no newline.
354349 # That partial line is not executable content.
355- if num_lines > 0 and (
356- lines [- 1 ].isspace () and not lines [- 1 ].endswith (("\n " , "\r " ))
357- ):
350+ if num_lines > 0 and (lines [- 1 ].isspace () and not lines [- 1 ].endswith (("\n " , "\r " ))):
358351 num_lines -= 1
359- source_lines .update (range (lineno , lineno + num_lines ))
352+ source_lines .update (range (lineno , lineno + num_lines ))
360353
361354 if SHOW_PARSING :
362355 print (f"\t \t \t Now source_lines is: { source_lines !r} " )
@@ -388,19 +381,21 @@ def get_line_number(line_map, offset):
388381def dump_frame (frame , label = "" ):
389382 """Dump interesting information about this frame."""
390383 locals = dict (frame .f_locals )
391- self = locals .get (' self' , None )
392- context = locals .get (' context' , None )
384+ self = locals .get (" self" , None )
385+ context = locals .get (" context" , None )
393386 if "__builtins__" in locals :
394387 del locals ["__builtins__" ]
395388
396389 if label :
397390 label = " ( %s ) " % label
398391 print ("-- frame --%s---------------------" % label )
399- print ("{}:{}:{}" .format (
400- os .path .basename (frame .f_code .co_filename ),
401- frame .f_lineno ,
402- type (self ),
403- ))
392+ print (
393+ "{}:{}:{}" .format (
394+ os .path .basename (frame .f_code .co_filename ),
395+ frame .f_lineno ,
396+ type (self ),
397+ )
398+ )
404399 print (locals )
405400 if self :
406401 print ("self:" , self .__dict__ )
0 commit comments