@@ -122,6 +122,13 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
122122 default = "assets" ,
123123 help = "path to assets directory" ,
124124 )
125+ parser .add_argument (
126+ "--ignore-dirs" ,
127+ dest = "ignore_dirs" ,
128+ type = str ,
129+ default = None ,
130+ help = "directories to ignore during watch. If more than one, separate with a semicolon." ,
131+ )
125132
126133 def handle (self , options : argparse .Namespace ) -> None :
127134 if options .module :
@@ -159,6 +166,13 @@ def handle(self, options: argparse.Namespace) -> None:
159166 Path (os .path .dirname (script_path )).joinpath (assets_dir ).resolve ()
160167 )
161168
169+ ignore_dirs = options .ignore_dirs
170+ if ignore_dirs :
171+ ignore_dirs = [
172+ str (Path (os .path .dirname (script_path )).joinpath (directory ).resolve ())
173+ for directory in ignore_dirs .split (";" )
174+ ]
175+
162176 my_event_handler = Handler (
163177 [sys .executable , "-u" ]
164178 + ["-m" ] * options .module
@@ -173,6 +187,7 @@ def handle(self, options: argparse.Namespace) -> None:
173187 options .android ,
174188 options .hidden ,
175189 assets_dir ,
190+ ignore_dirs if options .directory or options .recursive else None ,
176191 )
177192
178193 my_observer = Observer ()
@@ -205,6 +220,7 @@ def __init__(
205220 android ,
206221 hidden ,
207222 assets_dir ,
223+ ignore_dirs ,
208224 ) -> None :
209225 super ().__init__ ()
210226 self .args = args
@@ -218,6 +234,7 @@ def __init__(
218234 self .android = android
219235 self .hidden = hidden
220236 self .assets_dir = assets_dir
237+ self .ignore_dirs = ignore_dirs or []
221238 self .last_time = time .time ()
222239 self .is_running = False
223240 self .fvp = None
@@ -258,9 +275,21 @@ def start_process(self):
258275 th .start ()
259276
260277 def on_any_event (self , event ):
278+ is_in_ignore_dirs = False
279+ for directory in self .ignore_dirs :
280+ child = os .path .abspath (event .src_path )
281+ # check if the file which triggered the reload is in the (ignored) directory
282+ is_in_ignore_dirs = os .path .commonpath ([directory ]) == os .path .commonpath (
283+ [directory , child ]
284+ )
285+ if is_in_ignore_dirs :
286+ break
287+
261288 if (
262- self .script_path is None or event .src_path == self .script_path
263- ) and not event .is_directory :
289+ not is_in_ignore_dirs
290+ and (self .script_path is None or event .src_path == self .script_path )
291+ and not event .is_directory
292+ ):
264293 current_time = time .time ()
265294 if (current_time - self .last_time ) > 0.5 and self .is_running :
266295 self .last_time = current_time
0 commit comments