Skip to content

Commit 1ce2903

Browse files
fix: ignore temp files in scriptor watch mode (#223)
Anchor the .py regex to end-of-string so editor temp files like `foo.py.tmp.XXX` are no longer matched. Add an existence check before getmtime() as a second guard against race conditions where a transient file disappears before it can be processed.
1 parent a07f82f commit 1ce2903

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/viur_cli/scriptor/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,10 @@ def watch_loop():
372372

373373
def on_modified(event):
374374
try:
375-
# check for tmp file
376375
if event.src_path.endswith("~"):
377376
return
377+
if not os.path.exists(event.src_path):
378+
return
378379
if event.src_path not in modified_files:
379380
modified_files[event.src_path] = os.path.getmtime(event.src_path)
380381
elif os.path.getmtime(event.src_path) == modified_files[event.src_path]:
@@ -386,7 +387,7 @@ def on_modified(event):
386387
print(f"Error: on file {event.src_path} {e}")
387388
traceback.print_exc()
388389

389-
regexes = [r".*\.py"]
390+
regexes = [r".*\.py$"]
390391
ignore_regexes = []
391392
ignore_directories = True
392393
case_sensitive = False

0 commit comments

Comments
 (0)