11import os
22import sys
33import time
4+
45from django .core .management .base import BaseCommand
56from django .contrib .staticfiles .finders import get_finders
67import sass
@@ -50,9 +51,9 @@ def add_arguments(self, parser):
5051 help = "Watch input path and re-generate css files when scss files are changed." ,
5152 )
5253
53- def compile_sass (self , outfile , ** kwargs ):
54+ def compile_sass (self , outfile : str , ** kwargs ) -> None :
5455 rval = sass .compile (** kwargs )
55- # sass.compile() will return None of used with dirname.
56+ # sass.compile() will return None if used with dirname.
5657 # If used with filename, it will return a string of file contents.
5758 if rval and outfile :
5859 # If we got a css and sourcemap tuple, write the sourcemap.
@@ -74,7 +75,7 @@ def compile_sass(self, outfile, **kwargs):
7475 file .write (rval )
7576 file .close ()
7677
77- def handle (self , * args , ** options ):
78+ def handle (self , * args , ** options ) -> None :
7879 """
7980 Finds all static paths used by the project, and runs sass
8081 including those paths.
@@ -102,7 +103,9 @@ def handle(self, *args, **options):
102103 if os .path .isdir (outpath ):
103104 sassargs .update ({"dirname" : (inpath , outpath )})
104105 else :
105- raise NotADirectoryError ("Output path must also be a directory when input path is a directory." )
106+ raise NotADirectoryError (
107+ "Output path must also be a directory when input path is a directory."
108+ )
106109
107110 if os .path .isfile (inpath ):
108111 sassargs .update ({"filename" : inpath })
@@ -115,7 +118,7 @@ def handle(self, *args, **options):
115118 if options ["g" ]:
116119 sassargs .update ({"source_map_filename" : outfile + ".map" })
117120
118- # Watch files for changes if specified.
121+ # Watch files for changes if specified.
119122 if options ["watch" ]:
120123 try :
121124 self .stdout .write ("Watching..." )
@@ -134,7 +137,7 @@ def handle(self, *args, **options):
134137 needs_updated = True
135138 watchfiles .update ({fullpath : curr_mtime })
136139
137- # Recompile the sass if needed
140+ # Recompile the sass if needed.
138141 if needs_updated :
139142 # Catch compile errors to keep the watcher running.
140143 try :
@@ -143,14 +146,14 @@ def handle(self, *args, **options):
143146 except sass .CompileError as exc :
144147 self .stdout .write (str (exc ))
145148
146- # Go back to sleep
149+ # Go back to sleep.
147150 time .sleep (3 )
148151
149152 except KeyboardInterrupt :
150153 self .stdout .write ("Bye." )
151154 sys .exit (0 )
152155
153- # Write css
156+ # Write css.
154157 self .stdout .write ("Writing css..." )
155158 self .compile_sass (outfile , ** sassargs )
156159 self .stdout .write ("Done." )
0 commit comments