The new WatchfilesWatcher implementation (fb59849ccd45) has the issue reported in https://github.com/samuelcolvin/watchfiles/issues/235 . If the file is recreated, as some editors will do on saving, it will no longer be watched.
On saving a Beancount file using vi, a single event of <Change.deleted: 3> shows up, and causes the reload indicator to show in the UI, but nothing will show after that.
I would watch the entire directory with recursive=False, then check which file changes in your own logic.
works fine. e.g.
files = ['some-file', 'another-file']
watch_dirs = set([Path(p).parent for p in files])
for changes in watch(*watch_dirs, recursive=False):
for c in changes:
if c[0] in [Change.added, Change.modified]:
for f in files:
try:
if Path(f).samefile(c[1]):
print(f)
except FileNotFoundError:
pass
Adding this approach to the existing behaviour isn't a trivial change, due to WatchfilesWatcher taking both files: Iterable[Path] and folders: Iterable[Path]. The implementation would need to determine the effective set of directories to watch, then filter the events to check for an exact match for targets specified by files, but accept anything that was specified by folder, which may require more state in _WatchfilesThread.
The new
WatchfilesWatcher
implementation (fb59849ccd45) has the issue reported in https://github.com/samuelcolvin/watchfiles/issues/235 . If the file is recreated, as some editors will do on saving, it will no longer be watched.On saving a Beancount file using
vi
, a single event of<Change.deleted: 3>
shows up, and causes the reload indicator to show in the UI, but nothing will show after that.The workaround suggested in that report:
works fine. e.g.
Adding this approach to the existing behaviour isn't a trivial change, due to
WatchfilesWatcher
taking bothfiles: Iterable[Path]
andfolders: Iterable[Path]
. The implementation would need to determine the effective set of directories to watch, then filter the events to check for an exact match for targets specified byfiles
, but accept anything that was specified byfolder
, which may require more state in_WatchfilesThread
.