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

fix reload_dirs #1267

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def test_reload_dir_is_set(
== f"Will watch for changes in these directories: {[str(app_dir)]}"
)
assert config.reload_dirs == [app_dir]
config = Config(
app="tests.test_config:asgi_app", reload=True, reload_dirs=str(app_dir)
)
assert config.reload_dirs == [app_dir]


def test_non_existant_reload_dir_is_not_set(
Expand Down
16 changes: 12 additions & 4 deletions uvicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,15 @@ def resolve_reload_patterns(

directories = list(set(directories).difference(set(children)))

return (list(set(patterns)), directories)
return list(set(patterns)), directories
euri10 marked this conversation as resolved.
Show resolved Hide resolved


def _normalize_dirs(dirs: Union[List[str], str, None]) -> List[str]:
if dirs is None:
return []
if isinstance(dirs, str):
return [dirs]
return list(set(dirs))


class Config:
Expand Down Expand Up @@ -291,9 +299,9 @@ def __init__(
)

if self.should_reload:
reload_dirs = list(set(reload_dirs)) if reload_dirs else []
reload_includes = list(set(reload_includes)) if reload_includes else []
reload_excludes = list(set(reload_excludes)) if reload_excludes else []
reload_dirs = _normalize_dirs(reload_dirs)
reload_includes = _normalize_dirs(reload_includes)
reload_excludes = _normalize_dirs(reload_excludes)

self.reload_includes, self.reload_dirs = resolve_reload_patterns(
reload_includes, reload_dirs
Expand Down