@@ -86,10 +86,11 @@ def compile_to_css_and_save(input_file, dest_file):
8686
8787
8888class SourceModificationEventHandler (FileSystemEventHandler ):
89- def __init__ (self , input_file , dest_file ):
89+ def __init__ (self , input_file , dest_file , watched_dir ):
9090 super (SourceModificationEventHandler , self ).__init__ ()
9191 self ._input_file = input_file
9292 self ._dest_file = dest_file
93+ self ._watched_dir = watched_dir
9394 self ._watched_extension = os .path .splitext (self ._input_file )[1 ]
9495
9596 def _recompile (self ):
@@ -106,7 +107,8 @@ def _recompile(self):
106107 def on_modified (self , event ):
107108 # On Mac, event will always be a directory.
108109 # On Windows, only recompile if event's file has the same extension as the input file
109- if event .is_directory or os .path .splitext (event .src_path )[1 ] == self ._watched_extension :
110+ if event .is_directory and os .path .samefile (event .src_path , self ._watched_dir ) or (
111+ os .path .splitext (event .src_path )[1 ] == self ._watched_extension ):
110112 self ._recompile ()
111113
112114 def on_created (self , event ):
@@ -127,10 +129,11 @@ def on_created(self, event):
127129 compile_to_css_and_save (args .input , args .output )
128130
129131 if args .watch :
130- event_handler = SourceModificationEventHandler (args .input , args .output )
132+ watched_dir = os .path .abspath (os .path .dirname (args .input ))
133+ event_handler = SourceModificationEventHandler (args .input , args .output , watched_dir )
131134 logging .info ("qtsass is watching {}..." .format (args .input ))
132135 observer = Observer ()
133- observer .schedule (event_handler , os . path . dirname ( args . input ) , recursive = False )
136+ observer .schedule (event_handler , watched_dir , recursive = False )
134137 observer .start ()
135138 try :
136139 while True :
0 commit comments