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

Feature: Change reload to be configurable with glob patterns #820

Merged
merged 43 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c945de8
Update reload test class
Roang-zero1 Oct 23, 2020
6eed093
Add tests for include and exclude
Roang-zero1 Oct 16, 2020
e0517cb
Add configuration for include and exclude
Roang-zero1 Oct 16, 2020
5006d12
Update startreload
Roang-zero1 Oct 16, 2020
ff38710
Update watchgodreload
Roang-zero1 Oct 16, 2020
9a2d1ec
Update documentation
Roang-zero1 Oct 16, 2020
439e9c7
Apply suggestions from code review
Roang-zero1 Oct 20, 2020
d4c34e8
Update docs/settings.md
Roang-zero1 Oct 20, 2020
d170c45
Update docs/settings.md
Roang-zero1 Oct 23, 2020
9c5d09b
Add test for StartReload output
Roang-zero1 Aug 4, 2021
d85f2f8
Update types
Roang-zero1 Aug 4, 2021
26a5e9c
Add coverage notation for TYPE_CHECKING
Roang-zero1 Aug 4, 2021
fd185c4
Fix documentation linting
Roang-zero1 Aug 4, 2021
9149dc1
Fix documentation for linting
Roang-zero1 Aug 4, 2021
fc6d4e2
Removed tmpdir fixture
euri10 Aug 5, 2021
e35beab
Changed context manager to take path arg
euri10 Aug 5, 2021
5d47d90
Merge pull request #2 from euri10/Roang-zero1-feature/reload-exclude-…
Roang-zero1 Aug 5, 2021
8e4e1c4
Update config tests with as_cwd util
Roang-zero1 Aug 5, 2021
8a05f79
Remove debug print statement
Roang-zero1 Aug 5, 2021
4bd5fd1
Fix reload_includes arbitrarliy dropping entries
Roang-zero1 Aug 5, 2021
9a10bf8
Add additional configuration tests
Roang-zero1 Aug 5, 2021
4019387
Fix mypy error for mkdir
Roang-zero1 Aug 5, 2021
3c586f2
Remove installation hint for watchgod
Roang-zero1 Aug 5, 2021
57f3f3e
➕ Add warning for invalid reload config
Roang-zero1 Aug 5, 2021
a28ecbf
➕ Add reload_dir result as log message
Roang-zero1 Aug 5, 2021
53e0124
➕ Add reload_directory_structure fixture
Roang-zero1 Aug 5, 2021
8494aa8
➕ Add reload defaults to cli help
Roang-zero1 Aug 5, 2021
0103bc6
➕ Add parsing of reload dirs from glob patterns
Roang-zero1 Aug 5, 2021
6acf294
🐛 Fix incorrect init in StatReload
Roang-zero1 Aug 5, 2021
e6253af
🔨 Refactor should_watch_dir for WatchGodReload
Roang-zero1 Aug 5, 2021
4771c8c
➕ Add result cache for should_watch_*
Roang-zero1 Aug 6, 2021
137607f
🐛 Fix slow first reload test
Roang-zero1 Aug 6, 2021
f8489a5
🐛 Fix directory checks for Windows
Roang-zero1 Aug 6, 2021
3d5960b
🐛 Fix reload warning message tests
Roang-zero1 Aug 6, 2021
78a5530
Update tests/supervisors/test_reload.py
Roang-zero1 Aug 6, 2021
76848e4
🔥 Remove debug print statement
Roang-zero1 Aug 6, 2021
2d598f9
🚨 Fix test linting
Roang-zero1 Aug 6, 2021
20553e1
➕ Add description for reload_directory_structure fixture
Roang-zero1 Aug 6, 2021
9355401
🐛 Fix path error in windows tests
Roang-zero1 Aug 6, 2021
cea0a45
🐛 Fix path test again
Roang-zero1 Aug 6, 2021
ed2a1e0
🔥 Remove duplicate test case
Roang-zero1 Aug 7, 2021
bdf899e
➕ Add sorting to reload_dirs list
Roang-zero1 Aug 7, 2021
2777df1
🐛 Fix redundant excluded directory log output
Roang-zero1 Aug 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Options:
--reload Enable auto-reload.
--reload-dir PATH Set reload directories explicitly, instead
of using the current working directory.
--reload-include TEXT Set glob patterns to include while watching
for files. Includes '*.py' by default, which
can be overridden in reload-excludes.
--reload-exclude TEXT Set glob patterns to exclude while watching
for files. Includes '.*, .py[cod], .sw.*,
~*' by default, which can be overridden in
reload-excludes.
--reload-delay FLOAT Delay between previous and next check if
application needs to be. Defaults to 0.25s.
[default: 0.25]
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ Options:
--reload Enable auto-reload.
--reload-dir PATH Set reload directories explicitly, instead
of using the current working directory.
--reload-include TEXT Set glob patterns to include while watching
for files. Includes '*.py' by default, which
can be overridden in reload-excludes.
--reload-exclude TEXT Set glob patterns to exclude while watching
for files. Includes '.*, .py[cod], .sw.*,
~*' by default, which can be overridden in
reload-excludes.
--reload-delay FLOAT Delay between previous and next check if
application needs to be. Defaults to 0.25s.
[default: 0.25]
Expand Down
9 changes: 8 additions & 1 deletion docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ you should put `uvicorn.run` into `if __name__ == '__main__'` clause in the main
## Development

* `--reload` - Enable auto-reload.
* `--reload-dir <path>` - Specify which directories to watch for python file changes. May be used multiple times. If unused, then by default all directories in current directory will be watched. If you are running programmatically use `reload_dirs=[]` and pass a list of strings.
* `--reload-dir <path>` - Specify which directories to watch for python file changes. May be used multiple times. If unused, then by default the whole current directory will be watched. If you are running programmatically use `reload_dirs=[]` and pass a list of strings.
* `--reload-include <glob-pattern>` - Specify a glob pattern to match files or directories which will be watched. May be used multiple times. By default the following patterns are included: `*.py`. These can be overwritten by explicitly excluding them.
* `--reload-exclude <glob-pattern>` - Specify a glob pattern to match files or directories which will excluded from watching. May be used multiple times. By default the following patterns are excluded: `.*, .py[cod], .sw.*, ~*`. These can be overwritten by explicitly including them.
euri10 marked this conversation as resolved.
Show resolved Hide resolved

By default Uvicorn uses simple changes detection strategy that compares python files modification times few times a second. If this approach doesn't work for your project (eg. because of its complexity), or you need watching of non python files you can install [watchgod](https://pypi.org/project/watchgod/) or install uvicorn with `uvicorn[standard]`, which will include watchgod.

```
```

## Production

Expand Down
57 changes: 57 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,60 @@ def tls_ca_ssl_context(tls_certificate_authority: trustme.CA) -> ssl.SSLContext:
ssl_ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
tls_certificate_authority.configure_trust(ssl_ctx)
return ssl_ctx


@pytest.fixture(scope="package")
def reload_directory_structure(tmp_path_factory: pytest.TempPathFactory):
"""
This fixture creates a directory structure to enable reload parameter tests

The fixture has the following structure:
root
├── [app, app_first, app_second, app_third]
│   ├── css
│   │   └── main.css
│   ├── js
│   │   └── main.js
│   ├── src
│   │   └── main.py
│   └── sub
│   └── sub.py
├── ext
│   └── ext.jpg
└── main.py
"""
root = tmp_path_factory.mktemp("reload_directory")
apps = ["app", "app_first", "app_second", "app_third"]

root_file = root / "main.py"
root_file.touch()

dotted_file = root / ".dotted"
dotted_file.touch()

dotted_dir = root / ".dotted_dir"
dotted_dir.mkdir()
dotted_dir_file = dotted_dir / "file.txt"
dotted_dir_file.touch()

for app in apps:
app_path = root / app
app_path.mkdir()
dir_files = [
("src", ["main.py"]),
("js", ["main.js"]),
("css", ["main.css"]),
("sub", ["sub.py"]),
]
for directory, files in dir_files:
directory_path = app_path / directory
directory_path.mkdir()
for file in files:
file_path = directory_path / file
file_path.touch()
ext_dir = root / "ext"
ext_dir.mkdir()
ext_file = ext_dir / "ext.jpg"
ext_file.touch()

yield root