-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
Feature: Change reload to be configurable with glob patterns #820
Feature: Change reload to be configurable with glob patterns #820
Conversation
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.
thanks for this !
I begun reviewing this and realize it would be simpler to split it in 2:
- the test refactor
- the added functionality
in no particular order, this one seems simpler from my point of view.
Sorry but cant wrap my head around reviewing that much to be honest, and in any case it's a separate issue.
I left my comments anyway since I begun but the split would be much appreciated
Sure, I'll start the work on separating out the test refactor. |
b142a28
to
328e960
Compare
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.
Here are some points of consideration
1284ab0
to
b0062ab
Compare
As requested I've separated out the test class refactor to #833. Ready for new round of review. Added some comments to point out where feedback is requesed. |
b0062ab
to
b3810e9
Compare
Will look at it over the weekend and get back to you, thanks !
…On Fri, Oct 23, 2020, 7:22 PM Lucas ***@***.***> wrote:
As requested I've separated out the test class refactor to #833
<#833>.
Ready for new round of review. Added some comments to point out where
feedback is requesed.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#820 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAINSPX5VCEQNWOXUTB4SMDSMG3W7ANCNFSM4ST3ARHA>
.
|
Any updates on this PR? |
Just got the notification. I would be willing to revisit this PR, just let me know what is needed. |
Hi @Roang-zero1 👋 I'm going to review it over the weekend. If you'd like, merging master would be great! 😄 Sorry for the delay on it! |
Bump @Kludex |
* Use per test parameter to enable in depth testing
* Use Path instead of os.path for all manipulations * Use glob pattern to search for python files
* Use should_watch_dir to filter directories * Use glob patterns to filter files
Fix copy paste errors Co-authored-by: euri10 <euri10@users.noreply.github.com>
Fix docs error Co-authored-by: euri10 <euri10@users.noreply.github.com>
Co-authored-by: euri10 <euri10@users.noreply.github.com>
First reload test was working without the prepared directory. Therefore it initialized on the repository itself, thereby being slow.
I've added the changes, unfortunately this meant reworking large parts of this PR 🔨. (Sorry @euri10 for the additional work) I think I've added test cases for all new functionality. I've added a cache to the watchers, this reduces the CPU load, but costs memory. Please indicate if that is ok. There is now a fixture for testing all the reload related use cases, it is currently scoped for |
Just saw the failed test. I'll look into what the problem with Windows is tomorrow. |
Windows raises an OSError when a path is not found. This change introduces a helper function to mitigate this.
Windows paths were incorrect in the tests, this fixes these messages.
this is a subtle one:
you cannot build manually the list |
Co-authored-by: euri10 <euri10@users.noreply.github.com>
for the failing test, let's deal with that sorting the files in the output for predictable behaviour: diff --git a/tests/test_config.py b/tests/test_config.py
index a999b33..73f2e5f 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -225,8 +225,10 @@ def test_reload_includes_exclude_dir_patterns_are_matched(
"Will watch for changes in these directories: "
in caplog.records[-1].message
)
- assert str(first_app_dir) in caplog.records[-1].message
- assert str(second_app_dir) in caplog.records[-1].message
+ assert (
+ caplog.records[-1].message
+ == f"Will watch for changes in these directories: {sorted([str(first_app_dir), str(second_app_dir)])}"
+ )
assert frozenset(config.reload_dirs) == frozenset(
[first_app_dir, second_app_dir]
)
)
)
diff --git a/uvicorn/config.py b/uvicorn/config.py
index 4fae430..13f5898 100644
--- a/uvicorn/config.py
+++ b/uvicorn/config.py
@@ -331,7 +331,7 @@ class Config:
logger.info(
"Will watch for changes in these directories: %s",
- list(map(str, self.reload_dirs)),
+ sorted(list(map(str, self.reload_dirs))),
)
if env_file is not None: |
Log messages were printed for excluded directories, even if these directories were not in any of the watched reload_dirs.
thanks a lot @Roang-zero1 for this, this is a very nice enhancement ! |
* Update reload test class * Use per test parameter to enable in depth testing * Add tests for include and exclude * Add configuration for include and exclude * Update startreload * Use Path instead of os.path for all manipulations * Use glob pattern to search for python files * Update watchgodreload * Use should_watch_dir to filter directories * Use glob patterns to filter files * Update documentation * Apply suggestions from code review Fix copy paste errors Co-authored-by: euri10 <euri10@users.noreply.github.com> * Update docs/settings.md Fix docs error Co-authored-by: euri10 <euri10@users.noreply.github.com> * Update docs/settings.md Co-authored-by: euri10 <euri10@users.noreply.github.com> * Add test for StartReload output * Update types * Add coverage notation for TYPE_CHECKING * Fix documentation linting * Fix documentation for linting * Removed tmpdir fixture * Changed context manager to take path arg * Update config tests with as_cwd util * Move as_cwd to test utils * Update test_config tests with new util * Remove usage of tmpdir * Remove debug print statement * Fix reload_includes arbitrarliy dropping entries * Add additional configuration tests * Fix mypy error for mkdir * Remove installation hint for watchgod Co-authored-by: euri10 <euri10@users.noreply.github.com> * ➕ Add warning for invalid reload config If any of the reload settings are present, but the app would not reload there will not be a warning informing the user. * ➕ Add reload_dir result as log message * ➕ Add reload_directory_structure fixture Use one directory structure for all reload test. * ➕ Add reload defaults to cli help * ➕ Add parsing of reload dirs from glob patterns Glob patterns are now matched agains directories which will be added to reload_dirs if not present. This also extends to excluded directories. Exclude patterns now take precedence over includes. * 🐛 Fix incorrect init in StatReload * 🔨 Refactor should_watch_dir for WatchGodReload Uses a global dict to cache results. Prioritizes exclude directories and patterns. Finds additional reload/exclude directories if they are created under an existing watcher. * ➕ Add result cache for should_watch_* * 🐛 Fix slow first reload test First reload test was working without the prepared directory. Therefore it initialized on the repository itself, thereby being slow. * 🐛 Fix directory checks for Windows Windows raises an OSError when a path is not found. This change introduces a helper function to mitigate this. * 🐛 Fix reload warning message tests Windows paths were incorrect in the tests, this fixes these messages. * Update tests/supervisors/test_reload.py Co-authored-by: euri10 <euri10@users.noreply.github.com> * 🔥 Remove debug print statement * 🚨 Fix test linting * ➕ Add description for reload_directory_structure fixture * 🐛 Fix path error in windows tests * 🐛 Fix path test again * 🔥 Remove duplicate test case * ➕ Add sorting to reload_dirs list * 🐛 Fix redundant excluded directory log output Log messages were printed for excluded directories, even if these directories were not in any of the watched reload_dirs. Co-authored-by: euri10 <euri10@users.noreply.github.com> Co-authored-by: euri10 <benoit.barthelet@gmail.com>
@Roang-zero1 @euri10 @Kludex this PR introduced a regression and deleted the test for it ( Config('myapp:app', reload=True, reload_dirs='src') prints:
https://github.com/encode/uvicorn/pull/820/files#diff-6982a5e270879281f9182303a9da9776148857b46325afb230e50ef8eb3264c9R294 |
* Update reload test class * Use per test parameter to enable in depth testing * Add tests for include and exclude * Add configuration for include and exclude * Update startreload * Use Path instead of os.path for all manipulations * Use glob pattern to search for python files * Update watchgodreload * Use should_watch_dir to filter directories * Use glob patterns to filter files * Update documentation * Apply suggestions from code review Fix copy paste errors Co-authored-by: euri10 <euri10@users.noreply.github.com> * Update docs/settings.md Fix docs error Co-authored-by: euri10 <euri10@users.noreply.github.com> * Update docs/settings.md Co-authored-by: euri10 <euri10@users.noreply.github.com> * Add test for StartReload output * Update types * Add coverage notation for TYPE_CHECKING * Fix documentation linting * Fix documentation for linting * Removed tmpdir fixture * Changed context manager to take path arg * Update config tests with as_cwd util * Move as_cwd to test utils * Update test_config tests with new util * Remove usage of tmpdir * Remove debug print statement * Fix reload_includes arbitrarliy dropping entries * Add additional configuration tests * Fix mypy error for mkdir * Remove installation hint for watchgod Co-authored-by: euri10 <euri10@users.noreply.github.com> * ➕ Add warning for invalid reload config If any of the reload settings are present, but the app would not reload there will not be a warning informing the user. * ➕ Add reload_dir result as log message * ➕ Add reload_directory_structure fixture Use one directory structure for all reload test. * ➕ Add reload defaults to cli help * ➕ Add parsing of reload dirs from glob patterns Glob patterns are now matched agains directories which will be added to reload_dirs if not present. This also extends to excluded directories. Exclude patterns now take precedence over includes. * 🐛 Fix incorrect init in StatReload * 🔨 Refactor should_watch_dir for WatchGodReload Uses a global dict to cache results. Prioritizes exclude directories and patterns. Finds additional reload/exclude directories if they are created under an existing watcher. * ➕ Add result cache for should_watch_* * 🐛 Fix slow first reload test First reload test was working without the prepared directory. Therefore it initialized on the repository itself, thereby being slow. * 🐛 Fix directory checks for Windows Windows raises an OSError when a path is not found. This change introduces a helper function to mitigate this. * 🐛 Fix reload warning message tests Windows paths were incorrect in the tests, this fixes these messages. * Update tests/supervisors/test_reload.py Co-authored-by: euri10 <euri10@users.noreply.github.com> * 🔥 Remove debug print statement * 🚨 Fix test linting * ➕ Add description for reload_directory_structure fixture * 🐛 Fix path error in windows tests * 🐛 Fix path test again * 🔥 Remove duplicate test case * ➕ Add sorting to reload_dirs list * 🐛 Fix redundant excluded directory log output Log messages were printed for excluded directories, even if these directories were not in any of the watched reload_dirs. Co-authored-by: euri10 <euri10@users.noreply.github.com> Co-authored-by: euri10 <benoit.barthelet@gmail.com>
With this change it is possible to control which files will trigger a reload of uvicorn.
Features:
reload-include
is a repeatable list of unix style glob patterns pathlib.Path.glob that will be included in reload watch.reload-exclude
is a repeatable list of unix style glob patterns pathlib.Path.glob that will be excluded in reload watch.should_watch_dir
to reduce setup overheadshould_watch_file
withpathlib
to verify included pathsEdit by @Kludex: