-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
Conversation
Would be great if someone could kick off tests? |
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. |
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. |
Ye, took me some time to find it, it's really helpful. |
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). |
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. |
Makes sense, should be possible to add back the watchgod class, then choose between the three. |
AKAIK this is ready to review. |
There was a problem hiding this 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.
Thanks for the PR 🙇 |
Co-authored-by: Marcelo Trylesinski <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions added.
@Kludex sorry to hassle, why update on this? |
Update what? |
You mentioned you'd check this. |
Ah! Sorry! I'm going to check in some hours. 🙏 |
@samuelcolvin Done! 👍 Besides those 3 comments, I don't have more to say here. Thanks for the PR! 🙇 |
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 |
Thanks @samuelcolvin ! 🙇 Sorry for taking so long on the review. |
No problem at all, thanks reviewing and all your work. |
I needed to install
I had the issue below.
Using inside a Docker container (FROM pypy:3) |
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. |
Can confirm this. I ran fastapi in a docker and the reload just didn't work, but older version works. 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. |
Can confirm this. I ran fastapi in a docker and the reload just didn't work, but older version works. 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. |
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 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. |
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. |
PR to improve docs are welcome. |
* 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 <[email protected]> * 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 <[email protected]>
* 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 <[email protected]> * 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 <[email protected]>
See https://watchfiles.helpmanual.io/migrating/.
TL;DR; I've renamed
watchgod
towatchfiles
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:
BaseReload
to try and makeStatReload
and watchfiles share an interface, are you happy with this?I don't see an obvious way to deal withI think I've dealt with this a287d5c--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.