watchfiles icon indicating copy to clipboard operation
watchfiles copied to clipboard

Add option to disable recursive watch of folders

Open bvanelli opened this issue 2 years ago • 2 comments

Currently, all folders are recursively watched, with the only option to exclude folders via options with filters.

https://github.com/samuelcolvin/watchfiles/blob/937d00fe5ba9c1c8f6360823078a9b6387c9e07c/src/lib.rs#L50

I would propose to include a boolean flag recursive=False that would disable this default behaviour, to only parse the folders without recursion.

I'm willing to implement the future, as it seems simple enough, but my Rust knowledge is limited.

bvanelli avatar Jul 27 '22 13:07 bvanelli

Seems fair to me, PR welcome.

samuelcolvin avatar Jul 27 '22 14:07 samuelcolvin

Hello @samuelcolvin ,

I was working on this feature (see here https://github.com/bvanelli/watchfiles/commit/7daf501e71d9d5354defa532e6458313537a2c76) but I'm noticing some strange behavior regarding the notify library.

On the add recursive in my tests, no event is raised for the subdirectory: https://github.com/bvanelli/watchfiles/blob/178-disable-recursion/tests/test_rust_notify.py#L19

However, for the modify test, suddenly there is a modify event raised for the parent directory, when modifying a file inside the directory: https://github.com/bvanelli/watchfiles/blob/178-disable-recursion/tests/test_rust_notify.py#L47

I tried searching on the library documentation but without success. Also, there is no issue open on notify for this particular behavior. I also thought it could be related to OS, I'm running windows.

Do you know anything about it?

bvanelli avatar Aug 02 '22 18:08 bvanelli

Do you know anything about it?

Sorry, I don't know, best to ask on notify. But I suspect the answer will be, that's just weird behaviours/a bug in the OS implementation, we can't fix it.

samuelcolvin avatar Aug 22 '22 20:08 samuelcolvin

fixed in #183

samuelcolvin avatar Aug 30 '22 13:08 samuelcolvin