uv
uv copied to clipboard
Add `uv run --watch script.py` command to rerun `uv run` on `.py` file changes
Sounds cool!
Hi @nikitavoloboev, Do you plan to send a PR? I am also interested in this feature. Not sure if I should start the development. Thank you.
@Gankra started looking into this and noted there was some lurking complexity.
Two issues to resolve:
- how do we select which files to watch (first draft can just watch the script, but it would be nice if its deps could be watched)
- how do we "properly" cancel scripts on windows to rerun them (we have code for it on unix only, possible this is trivial but the existence of bespoke unix handling has me worried there's extra complexity)
I would look into how bun does that and copy that for uv. I never had issues there, I assume the only diff is the dep part but I never needed to rerun on dep changes.
Any updates on this? it would be an awesome feature
@zanieb @Gankra id be interested in working on this one - don't have any experience with windows dev though - thoughts on enabling for Unix only to start?
Also - is the idea to implement specifically for script file paths or any target that can be passed in to "run"?
Was just taking a look at the notify crate - thoughts on starting out with something like that for the watcher implementation?
@thejchap yes the notify crate (or maybe specifically notify_debouncer_mini which wraps it) is the right tool. The impls in mdbook are in my experience pretty reasonably to base this work off of:
https://github.com/rust-lang/mdBook/blob/master/src/cmd/watch.rs https://github.com/rust-lang/mdBook/blob/master/src/cmd/watch/native.rs
I would prefer if it were cross-platform, I think for the most part all the logic will be portable, so sure get it working on unix first and we'll figure it out from there.
I believe for the first draft just taking a script to run is acceptable.
sounds good - and thanks for the mdbook pointers. will get into it
@Gankra got an MVP implementation here: https://github.com/astral-sh/uv/pull/12847
pausing here for some early feedback. i left notes on a couple specific things that came up in the description (around exit codes/clearscreen behavior/debounce behavior), but any general feedback on the direction before i get in further is appreciated
@zanieb @Gankra let me know if i can help/make any more progress on this one