uv icon indicating copy to clipboard operation
uv copied to clipboard

Add `uv run --watch script.py` command to rerun `uv run` on `.py` file changes

Open nikivdev opened this issue 1 year ago • 1 comments

Essentially Bun watch mode but with uv.

Some more context for this on Discord.

nikivdev avatar Dec 05 '24 01:12 nikivdev

Sounds cool!

zanieb avatar Dec 05 '24 01:12 zanieb

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.

posutsai avatar Jan 17 '25 04:01 posutsai

@Gankra started looking into this and noted there was some lurking complexity.

zanieb avatar Jan 17 '25 04:01 zanieb

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)

Gankra avatar Jan 17 '25 13:01 Gankra

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.

nikivdev avatar Jan 17 '25 14:01 nikivdev

Any updates on this? it would be an awesome feature

breightend avatar Apr 04 '25 15:04 breightend

@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 avatar Apr 04 '25 16:04 thejchap

@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.

Gankra avatar Apr 08 '25 20:04 Gankra

sounds good - and thanks for the mdbook pointers. will get into it

thejchap avatar Apr 08 '25 23:04 thejchap

@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

thejchap avatar Apr 11 '25 22:04 thejchap

@zanieb @Gankra let me know if i can help/make any more progress on this one

thejchap avatar Jun 04 '25 13:06 thejchap