Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from watchgod to watchfiles #1437

Merged
merged 21 commits into from Jun 18, 2022
Merged

Conversation

samuelcolvin
Copy link
Sponsor Contributor

@samuelcolvin samuelcolvin commented Apr 1, 2022

See https://watchfiles.helpmanual.io/migrating/.

TL;DR; I've renamed watchgod to watchfiles and rewritten it to use the rust "notify" crate for all the heavy lifting. This PR is a WIP to see if you're willing to move ahead with a change like this.

Still TODO/to answer:

  • I've changed the logic of BaseReload to try and make StatReload and watchfiles share an interface, are you happy with this?
  • tests are a fair bit more complicated, are you happy with how I'm implemented/changed them?
  • I don't see an obvious way to deal with --reload-include and --reload-exclude being paths rather than extensions. Are you happy to drop this functionality? It's much less important now there's little overhead to scanning big directories, if not, we can implement something but it'll be complicated. I think I've dealt with this a287d5c

@samuelcolvin samuelcolvin marked this pull request as ready for review April 1, 2022 19:36
@samuelcolvin
Copy link
Sponsor Contributor Author

Would be great if someone could kick off tests?

@samuelcolvin
Copy link
Sponsor Contributor Author

From https://github.com/encode/uvicorn/settings/actions the below option might save you a lot of time kicking off tests and would be helpful for new contributors.

image

@Kludex
Copy link
Sponsor Member

Kludex commented Apr 2, 2022

Ah... I didn't know it was configurable. I'm going ask @tomchristie to enable that over encode. Thanks 🙏

Ping @florimondmanca as you asked about this the other day.

@samuelcolvin
Copy link
Sponsor Contributor Author

Ah... I didn't know it was configurable. I'm going ask @tomchristie to enable that over encode. Thanks 🙏

Ye, took me some time to find it, it's really helpful.

@samuelcolvin
Copy link
Sponsor Contributor Author

I would love feedback on this, but please don't merge. I'd like to make some more changes once samuelcolvin/watchfiles#113 is merged and released (mostly making sure tests don't wait forever if no changes are detected).

@Kludex Kludex added the hold Don't merge yet label Apr 3, 2022
@Kludex
Copy link
Sponsor Member

Kludex commented Apr 3, 2022

I think I'll not have time to review this today, but my initial thoughts are to first deprecate watchgod, and not to remove it directly. As on the user's point of view those are different packages, and it would be a breaking change (even if that package is not supposed to be used in production on uvicorn...).

But... I think it's fine to change all documentation and replace the standard extra requirements. About the tests, I'll need to check.

@samuelcolvin
Copy link
Sponsor Contributor Author

Makes sense, should be possible to add back the watchgod class, then choose between the three.

@samuelcolvin
Copy link
Sponsor Contributor Author

AKAIK this is ready to review.

Copy link
Sponsor Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the logic of BaseReload to try and make StatReload and watchfiles share an interface, are you happy with this?

I'm fine with the changes on the BaseReload class. It's easier to understand the logic of run(). Thanks. 👍

I don't care about the change on the reloader_name for each reloader class. Do you @euri10 ?

I've made an initial review. I didn't check the tests yet.

.gitignore Outdated Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
uvicorn/supervisors/watchgodreload.py Outdated Show resolved Hide resolved
uvicorn/supervisors/basereload.py Show resolved Hide resolved
uvicorn/supervisors/watchgodreload.py Show resolved Hide resolved
uvicorn/supervisors/watchgodreload.py Show resolved Hide resolved
uvicorn/supervisors/watchfilesreload.py Show resolved Hide resolved
@Kludex
Copy link
Sponsor Member

Kludex commented Apr 9, 2022

Thanks for the PR 🙇

samuelcolvin and others added 2 commits April 9, 2022 16:40
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Copy link
Sponsor Contributor Author

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions added.

uvicorn/supervisors/basereload.py Show resolved Hide resolved
uvicorn/supervisors/watchfilesreload.py Show resolved Hide resolved
uvicorn/supervisors/watchgodreload.py Show resolved Hide resolved
uvicorn/supervisors/watchgodreload.py Show resolved Hide resolved
@samuelcolvin
Copy link
Sponsor Contributor Author

@Kludex sorry to hassle, why update on this?

@Kludex
Copy link
Sponsor Member

Kludex commented Jun 17, 2022

Update what?

@samuelcolvin
Copy link
Sponsor Contributor Author

ty, will check in the following day(s) 🙏

You mentioned you'd check this.

@Kludex
Copy link
Sponsor Member

Kludex commented Jun 17, 2022

Ah! Sorry!

I'm going to check in some hours. 🙏

uvicorn/supervisors/watchfilesreload.py Outdated Show resolved Hide resolved
uvicorn/supervisors/watchfilesreload.py Outdated Show resolved Hide resolved
tests/supervisors/test_reload.py Outdated Show resolved Hide resolved
@Kludex
Copy link
Sponsor Member

Kludex commented Jun 17, 2022

@samuelcolvin Done! 👍

Besides those 3 comments, I don't have more to say here. Thanks for the PR! 🙇

@Kludex
Copy link
Sponsor Member

Kludex commented Jun 18, 2022

I'll see today how's going to be our release schedule (i.e. if there's going to be a patch before merging this). Jfyk

@Kludex Kludex removed the hold Don't merge yet label Jun 18, 2022
@Kludex Kludex mentioned this pull request Jun 18, 2022
5 tasks
@Kludex Kludex merged commit b1a4582 into encode:master Jun 18, 2022
@Kludex
Copy link
Sponsor Member

Kludex commented Jun 18, 2022

Thanks @samuelcolvin ! 🙇

Sorry for taking so long on the review.

@samuelcolvin
Copy link
Sponsor Contributor Author

No problem at all, thanks reviewing and all your work.

@sovanna
Copy link

sovanna commented Jun 24, 2022

I needed to install rust in order to install uvicorn to make watchfiles works.

pip install uvicorn[standard] didn't work for me anymore.

I had the issue below.

Collecting watchfiles
  Using cached watchfiles-0.15.0.tar.gz (36 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Checking for Rust toolchain....

      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/

      [end of output]

Using inside a Docker container (FROM pypy:3)

@samuelcolvin
Copy link
Sponsor Contributor Author

Best to create an issue on watchfiles.

Currently we don't distribute binaries for pypy.

You can always skip installing watchfiles and uvicorn will fall back to polling.

@bropuffshroom
Copy link

I needed to install rust in order to install uvicorn to make watchfiles works.

pip install uvicorn[standard] didn't work for me anymore.

I had the issue below.

Collecting watchfiles
  Using cached watchfiles-0.15.0.tar.gz (36 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Checking for Rust toolchain....

      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/

      [end of output]

Using inside a Docker container (FROM pypy:3)

Can confirm this. I ran fastapi in a docker and the reload just didn't work, but older version works.
This basically rendered --reload broken on uvicorn[standard] installation for some environment, without giving any warning or information whatsoever. I just spend a few hours to debug why the auto reload didn't work for me.

I personally think it's probably not a good idea to migrate to watchfiles for now just because watchgod is deprecated.

For my situation (I'm running a linux container on windows), I didn't run into any trouble installing uvicorn[standard] or watchfiles.

For anyone who ran into the same issue, as mentioned above, after the uvicorn[standard] installation, uninstall watchfiles and uvicorn will fall back to StatReload and the reload will be working.

@bropuffshroom
Copy link

I needed to install rust in order to install uvicorn to make watchfiles works.

pip install uvicorn[standard] didn't work for me anymore.

I had the issue below.

Collecting watchfiles
  Using cached watchfiles-0.15.0.tar.gz (36 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Checking for Rust toolchain....

      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/

      [end of output]

Using inside a Docker container (FROM pypy:3)

Can confirm this. I ran fastapi in a docker and the reload just didn't work, but older version works.
This basically rendered --reload broken on uvicorn[standard] installation for some environment, without giving any warning or information whatsoever.

In my very personal opinion I think it's probably not a good idea to migrate to watchfiles for now just because watchgod is deprecated, since I just spend a few hours to debug why the auto reload didn't work for me.

For my situation (I'm running a linux container on windows), I didn't run into any trouble installing uvicorn[standard] or watchfiles.

For anyone who ran into the same issue, as mentioned above, after the uvicorn[standard] installation, uninstall watchfiles and uvicorn will fall back to StatReload and the reload will be working.

@samuelcolvin
Copy link
Sponsor Contributor Author

samuelcolvin commented Jul 29, 2022

Please create new issues rather than commenting on closed PRs. You're issue is not the same as this, both issues have been fixed.

Your issue looks to be the same as samuelcolvin/watchfiles#169, you just need to set WATCHFILES_FORCE_POLLING and reloading will work.

There were many issues with watchgod, hence why I rewrote it to create watchfiles. As the author of both i can assure you watchfiles is much better in many ways.

@bropuffshroom
Copy link

Please create new issues rather than commenting on closed PRs. You're issue is not the same as this, both issues have been fixed.

Your issue looks to be the same as samuelcolvin/watchfiles#169, you just need to set WATCHFILES_FORCE_POLLING and reloading will help.

There were many issues with watchgod, hence why I rewrote it to create watchfiles. As the author of both i can assure you watchfiles is much better in many ways.

Thanks for your work. Both are excellent libraries.

@dvglab
Copy link

dvglab commented Sep 1, 2022

Please create new issues rather than commenting on closed PRs. You're issue is not the same as this, both issues have been fixed.

Your issue looks to be the same as samuelcolvin/watchfiles#169, you just need to set WATCHFILES_FORCE_POLLING and reloading will work.

There were many issues with watchgod, hence why I rewrote it to create watchfiles. As the author of both i can assure you watchfiles is much better in many ways.

Information about WATCHFILES_FORCE_POLLING is very important. I've lost a lot of hours before found it here. It seems to me it should be on uvicorn site somewhere in documentation. It was a real headache to realize why the reload function don't work on a docker for Windows. Thanks God I found it here.

@Kludex
Copy link
Sponsor Member

Kludex commented Sep 1, 2022

PR to improve docs are welcome.

@samuelcolvin samuelcolvin deleted the watchfiles branch September 1, 2022 13:36
Kludex added a commit to sephioh/uvicorn that referenced this pull request Oct 29, 2022
* switch from watchgod to watchfiles

* fixing ot skipping tests

* linting and self.exclude_dirs

* move touch_soon

* fix tests on windows

* fix tests on windows with py37

* add back "WatchGodReload" for backwards compatibility

* depreciated message on WatchGodReload

* linting

* uprev watchfiles and use yield_on_timeout

* Apply suggestions from code review

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* suggestions

* moving warning call

* Move the warning to the WatchGodReload.__init__

* improve coverage

* reinstate test_should_detect_new_reload_dirs

* linting

* Remove main.py

* Remove unused code

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Kludex added a commit that referenced this pull request Oct 29, 2022
* switch from watchgod to watchfiles

* fixing ot skipping tests

* linting and self.exclude_dirs

* move touch_soon

* fix tests on windows

* fix tests on windows with py37

* add back "WatchGodReload" for backwards compatibility

* depreciated message on WatchGodReload

* linting

* uprev watchfiles and use yield_on_timeout

* Apply suggestions from code review

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* suggestions

* moving warning call

* Move the warning to the WatchGodReload.__init__

* improve coverage

* reinstate test_should_detect_new_reload_dirs

* linting

* Remove main.py

* Remove unused code

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants