1111from urllib .parse import quote , urlparse , urlunparse
1212
1313import qrcode
14- from watchdog .events import FileSystemEventHandler
15- from watchdog .observers import Observer
16-
1714from flet .cli .commands .base import BaseCommand
1815from flet_core .utils import random_string
1916from flet_runtime .app import close_flet_view , open_flet_view
2320 is_windows ,
2421 open_in_browser ,
2522)
23+ from watchdog .events import FileSystemEventHandler
24+ from watchdog .observers import Observer
2625
2726
2827class Command (BaseCommand ):
@@ -127,7 +126,7 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
127126 dest = "ignore_dirs" ,
128127 type = str ,
129128 default = None ,
130- help = "directories to ignore during watch. If more than one, separate with a semicolon ." ,
129+ help = "directories to ignore during watch. If more than one, separate with a comma ." ,
131130 )
132131
133132 def handle (self , options : argparse .Namespace ) -> None :
@@ -166,28 +165,31 @@ def handle(self, options: argparse.Namespace) -> None:
166165 Path (os .path .dirname (script_path )).joinpath (assets_dir ).resolve ()
167166 )
168167
169- ignore_dirs = options .ignore_dirs
170- if ignore_dirs :
171- ignore_dirs = [
168+ ignore_dirs = (
169+ [
172170 str (Path (os .path .dirname (script_path )).joinpath (directory ).resolve ())
173- for directory in ignore_dirs .split ("; " )
171+ for directory in options . ignore_dirs .split (", " )
174172 ]
173+ if options .ignore_dirs
174+ else []
175+ )
175176
176177 my_event_handler = Handler (
177- [sys .executable , "-u" ]
178+ args = [sys .executable , "-u" ]
178179 + ["-m" ] * options .module
179180 + [options .script if options .module else script_path ],
180- None if options .directory or options .recursive else script_path ,
181- port ,
182- options .host ,
183- options .app_name ,
184- uds_path ,
185- options .web ,
186- options .ios ,
187- options .android ,
188- options .hidden ,
189- assets_dir ,
190- ignore_dirs if options .directory or options .recursive else None ,
181+ watch_directory = options .directory or options .recursive ,
182+ script_path = script_path ,
183+ port = port ,
184+ host = options .host ,
185+ page_name = options .app_name ,
186+ uds_path = uds_path ,
187+ web = options .web ,
188+ ios = options .ios ,
189+ android = options .android ,
190+ hidden = options .hidden ,
191+ assets_dir = assets_dir ,
192+ ignore_dirs = ignore_dirs ,
191193 )
192194
193195 my_observer = Observer ()
@@ -210,6 +212,7 @@ class Handler(FileSystemEventHandler):
210212 def __init__ (
211213 self ,
212214 args ,
215+ watch_directory ,
213216 script_path ,
214217 port ,
215218 host ,
@@ -224,6 +227,7 @@ def __init__(
224227 ) -> None :
225228 super ().__init__ ()
226229 self .args = args
230+ self .watch_directory = watch_directory
227231 self .script_path = script_path
228232 self .port = port
229233 self .host = host
@@ -234,7 +238,7 @@ def __init__(
234238 self .android = android
235239 self .hidden = hidden
236240 self .assets_dir = assets_dir
237- self .ignore_dirs = ignore_dirs or []
241+ self .ignore_dirs = ignore_dirs
238242 self .last_time = time .time ()
239243 self .is_running = False
240244 self .fvp = None
@@ -275,21 +279,15 @@ def start_process(self):
275279 th .start ()
276280
277281 def on_any_event (self , event ):
278- is_in_ignore_dirs = False
279282 for directory in self .ignore_dirs :
280283 child = os .path .abspath (event .src_path )
281284 # 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 (
285+ if os .path .commonpath ([directory ]) == os .path .commonpath (
283286 [directory , child ]
284- )
285- if is_in_ignore_dirs :
286- break
287+ ):
288+ return
287289
288- if (
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- ):
290+ if self .watch_directory or event .src_path == self .script_path :
293291 current_time = time .time ()
294292 if (current_time - self .last_time ) > 0.5 and self .is_running :
295293 self .last_time = current_time
0 commit comments