Skip to content

Commit

Permalink
Merge branch 'encode:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hajs committed Sep 19, 2022
2 parents 51d4b75 + 56c0da8 commit 53ac0b4
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: "${{ matrix.os }}"
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- uses: "actions/checkout@v3"
Expand Down
9 changes: 8 additions & 1 deletion docs/settings.md
Expand Up @@ -38,11 +38,18 @@ If Uvicorn _cannot_ load [watchfiles](https://pypi.org/project/watchfiles/) at r

### Reloading with watchfiles

For more nuanced control over which file modifications trigger reloads, install `uvicorn[standard]`, which includes watchfiles as a dependency. Alternatively, install [watchfiles](https://pypi.org/project/watchfiles/) where Uvicorn can see it. This will enable the following options (which are otherwise ignored).
For more nuanced control over which file modifications trigger reloads, install `uvicorn[standard]`, which includes watchfiles as a dependency. Alternatively, install [watchfiles](https://pypi.org/project/watchfiles/) where Uvicorn can see it.

Using Uvicorn with watchfiles will enable the following options (which are otherwise ignored).

* `--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 defaults can be overwritten by including them in `--reload-exclude`.
* `--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 defaults can be overwritten by including them in `--reload-include`.

!!! tip
When using Uvicorn through [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux), you might
have to set the `WATCHFILES_FORCE_POLLING` environment variable, for file changes to trigger a reload.
See [watchfiles documentation](https://watchfiles.helpmanual.io/api/watch/) for further details.

## Production

* `--workers <int>` - Use multiple worker processes. Defaults to the `$WEB_CONCURRENCY` environment variable if available, or 1.
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Expand Up @@ -23,6 +23,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Internet :: WWW/HTTP",
Expand All @@ -36,7 +37,7 @@ dependencies = [
[project.optional-dependencies]
standard = [
"colorama>=0.4;sys_platform == 'win32'",
"httptools>=0.4.0",
"httptools>=0.5.0",
"python-dotenv>=0.13",
"PyYAML>=5.1",
"uvloop>=0.14.0,!=0.15.0,!=0.15.1; sys_platform != 'win32' and (sys_platform != 'cygwin' and platform_python_implementation != 'PyPy')",
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Expand Up @@ -20,7 +20,6 @@ files =
uvicorn/protocols/http/auto.py,
uvicorn/protocols/websockets/auto.py,
uvicorn/supervisors/__init__.py,
uvicorn/middleware/debug.py,
uvicorn/middleware/wsgi.py,
uvicorn/supervisors/watchfilesreload.py,
uvicorn/supervisors/watchgodreload.py,
Expand Down Expand Up @@ -73,6 +72,7 @@ filterwarnings=
# Turn warnings that aren't filtered into exceptions
error
ignore: \"watchgod\" is depreciated\, you should switch to watchfiles \(`pip install watchfiles`\)\.:DeprecationWarning
ignore: 'cgi' is deprecated and slated for removal in Python 3\.13:DeprecationWarning

[coverage:run]
omit = venv/*
Expand All @@ -82,7 +82,7 @@ plugins =

[coverage:report]
precision = 2
fail_under = 97.74
fail_under = 97.69
show_missing = true
skip_covered = true
exclude_lines =
Expand Down
73 changes: 0 additions & 73 deletions tests/middleware/test_debug.py

This file was deleted.

19 changes: 3 additions & 16 deletions tests/test_config.py
Expand Up @@ -14,7 +14,6 @@
from tests.utils import as_cwd
from uvicorn._types import Environ, StartResponse
from uvicorn.config import Config
from uvicorn.middleware.debug import DebugMiddleware
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
from uvicorn.middleware.wsgi import WSGIMiddleware
from uvicorn.protocols.http.h11_impl import H11Protocol
Expand Down Expand Up @@ -58,28 +57,16 @@ def wsgi_app(environ: Environ, start_response: StartResponse) -> None:
pass # pragma: nocover


def test_debug_app() -> None:
config = Config(app=asgi_app, debug=True, proxy_headers=False)
config.load()

assert config.debug is True
assert isinstance(config.loaded_app, DebugMiddleware)


@pytest.mark.parametrize(
"app, expected_should_reload",
[(asgi_app, False), ("tests.test_config:asgi_app", True)],
)
def test_config_should_reload_is_set(
app: "ASGIApplication", expected_should_reload: bool
) -> None:
config_debug = Config(app=app, debug=True)
assert config_debug.debug is True
assert config_debug.should_reload is expected_should_reload

config_reload = Config(app=app, reload=True)
assert config_reload.reload is True
assert config_reload.should_reload is expected_should_reload
config = Config(app=app, reload=True)
assert config.reload is True
assert config.should_reload is expected_should_reload


def test_should_warn_on_invalid_reload_configuration(
Expand Down
7 changes: 1 addition & 6 deletions uvicorn/config.py
Expand Up @@ -42,7 +42,6 @@

from uvicorn.importer import ImportFromStringError, import_from_string
from uvicorn.middleware.asgi2 import ASGI2Middleware
from uvicorn.middleware.debug import DebugMiddleware
from uvicorn.middleware.message_logger import MessageLoggerMiddleware
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
from uvicorn.middleware.wsgi import WSGIMiddleware
Expand Down Expand Up @@ -228,7 +227,6 @@ def __init__(
access_log: bool = True,
use_colors: Optional[bool] = None,
interface: InterfaceType = "auto",
debug: bool = False,
reload: bool = False,
reload_dirs: Optional[Union[List[str], str]] = None,
reload_delay: float = 0.25,
Expand Down Expand Up @@ -275,7 +273,6 @@ def __init__(
self.access_log = access_log
self.use_colors = use_colors
self.interface = interface
self.debug = debug
self.reload = reload
self.reload_delay = reload_delay
self.workers = workers or 1
Expand Down Expand Up @@ -511,8 +508,6 @@ def load(self) -> None:
elif self.interface == "asgi2":
self.loaded_app = ASGI2Middleware(self.loaded_app)

if self.debug:
self.loaded_app = DebugMiddleware(self.loaded_app)
if logger.level <= TRACE_LOG_LEVEL:
self.loaded_app = MessageLoggerMiddleware(self.loaded_app)
if self.proxy_headers:
Expand Down Expand Up @@ -589,4 +584,4 @@ def bind_socket(self) -> socket.socket:

@property
def should_reload(self) -> bool:
return isinstance(self.app, str) and (self.debug or self.reload)
return isinstance(self.app, str) and self.reload
7 changes: 0 additions & 7 deletions uvicorn/main.py
Expand Up @@ -79,9 +79,6 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
@click.option(
"--fd", type=int, default=None, help="Bind to socket from this file descriptor."
)
@click.option(
"--debug", is_flag=True, default=False, help="Enable debug mode.", hidden=True
)
@click.option("--reload", is_flag=True, default=False, help="Enable auto-reload.")
@click.option(
"--reload-dir",
Expand Down Expand Up @@ -372,7 +369,6 @@ def main(
ws_per_message_deflate: bool,
lifespan: LifespanType,
interface: InterfaceType,
debug: bool,
reload: bool,
reload_dirs: typing.List[str],
reload_includes: typing.List[str],
Expand Down Expand Up @@ -424,7 +420,6 @@ def main(
log_level=log_level,
access_log=access_log,
interface=interface,
debug=debug,
reload=reload,
reload_dirs=reload_dirs or None,
reload_includes=reload_includes or None,
Expand Down Expand Up @@ -471,7 +466,6 @@ def run(
ws_per_message_deflate: bool = True,
lifespan: LifespanType = "auto",
interface: InterfaceType = "auto",
debug: bool = False,
reload: bool = False,
reload_dirs: typing.Optional[typing.Union[typing.List[str], str]] = None,
reload_includes: typing.Optional[typing.Union[typing.List[str], str]] = None,
Expand Down Expand Up @@ -524,7 +518,6 @@ def run(
ws_per_message_deflate=ws_per_message_deflate,
lifespan=lifespan,
interface=interface,
debug=debug,
reload=reload,
reload_dirs=reload_dirs,
reload_includes=reload_includes,
Expand Down

0 comments on commit 53ac0b4

Please sign in to comment.