Skip to content

Commit

Permalink
Merge branch 'master' into bug/fix-shutdown-event-on-windows-in-hot-r…
Browse files Browse the repository at this point in the history
…eloader
  • Loading branch information
StarHeartHunt authored Oct 22, 2022
2 parents 2300113 + b06cc63 commit 1e48e1e
Show file tree
Hide file tree
Showing 27 changed files with 336 additions and 415 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ uvicorn.egg-info/
venv/
htmlcov/
site/
dist/
35 changes: 33 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Change Log

## 0.19.0 - 2022-10-19

### Added

- Support Python 3.11 (#1652) 16/09/22
- Bump minimal `httptools` version to `0.5.0` (#1645) 13/09/22
- Ignore HTTP/2 upgrade and optionally ignore WebSocket upgrade (#1661) 19/10/22
- Add `py.typed` to comply with PEP 561 (#1687) 07/10/22

### Fixed

- Set `propagate` to `False` on "uvicorn" logger (#1288) 08/10/22
- USR1 signal is now handled correctly on `UvicornWorker`. (#1565) 26/08/22
- Use path with query string on `WebSockets` logs (#1385) 11/09/22
- Fix behavior on which "Date" headers were not updated on the same connection (#1706) 19/10/22

### Removed

- Remove the `--debug` flag (#1640) 14/09/22
- Remove the `DebugMiddleware` (#1697) 07/10/22

## 0.18.3 - 2022-08-24

### Fixed

- Remove cyclic references on HTTP implementations. (#1604) 24/08/22

### Changed

- `reload_delay` default changed from `None` to `0.25` on `uvicorn.run()` and `Config`. `None` is not an acceptable value anymore. (#1545) 02/07/22

## 0.18.2 - 2022-06-27

### Fixed
Expand Down Expand Up @@ -41,8 +72,8 @@

### Fixed

- Fix case where url is fragmented in httptools protocol (#1263) 2/16/22
- Fix WSGI middleware not to explode quadratically in the case of a larger body (#1329) 2/16/16
- Fix case where url is fragmented in httptools protocol (#1263) 16/02/22
- Fix WSGI middleware not to explode quadratically in the case of a larger body (#1329) 16/02/16

### Changed

Expand Down
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

11 changes: 9 additions & 2 deletions docs/settings.md
Original file line number Diff line number Diff line change
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 All @@ -60,7 +67,7 @@ For more nuanced control over which file modifications trigger reloads, install

* `--loop <str>` - Set the event loop implementation. The uvloop implementation provides greater performance, but is not compatible with Windows or PyPy. **Options:** *'auto', 'asyncio', 'uvloop'.* **Default:** *'auto'*.
* `--http <str>` - Set the HTTP protocol implementation. The httptools implementation provides greater performance, but it not compatible with PyPy. **Options:** *'auto', 'h11', 'httptools'.* **Default:** *'auto'*.
* `--ws <str>` - Set the WebSockets protocol implementation. Either of the `websockets` and `wsproto` packages are supported. Use `'none'` to deny all websocket requests. **Options:** *'auto', 'none', 'websockets', 'wsproto'.* **Default:** *'auto'*.
* `--ws <str>` - Set the WebSockets protocol implementation. Either of the `websockets` and `wsproto` packages are supported. Use `'none'` to ignore all websocket requests. **Options:** *'auto', 'none', 'websockets', 'wsproto'.* **Default:** *'auto'*.
* `--ws-max-size <int>` - Set the WebSockets max message size, in bytes. Please note that this can be used only with the default `websockets` protocol.
* `--ws-ping-interval <float>` - Set the WebSockets ping interval, in seconds. Please note that this can be used only with the default `websockets` protocol.
* `--ws-ping-timeout <float>` - Set the WebSockets ping timeout, in seconds. Please note that this can be used only with the default `websockets` protocol.
Expand Down
63 changes: 63 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "uvicorn"
dynamic = ["version"]
description = "The lightning-fast ASGI server."
readme = "README.md"
license = "BSD-3-Clause"
requires-python = ">=3.7"
authors = [
{ name = "Tom Christie", email = "tom@tomchristie.com" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"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",
]
dependencies = [
"click>=7.0",
"h11>=0.8",
"typing-extensions;python_version < '3.8'",
]

[project.optional-dependencies]
standard = [
"colorama>=0.4;sys_platform == 'win32'",
"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')",
"watchfiles>=0.13",
"websockets>=10.0",
]

[project.scripts]
uvicorn = "uvicorn.main:main"

[project.urls]
Changelog = "https://github.com/encode/uvicorn/blob/master/CHANGELOG.md"
Funding = "https://github.com/sponsors/encode"
Homepage = "https://www.uvicorn.org/"
Source = "https://github.com/encode/uvicorn"

[tool.hatch.version]
path = "uvicorn/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
"/uvicorn",
]
27 changes: 14 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
asgiref==3.5.2

# Explicit optionals
wsproto==1.1.0
wsproto==1.2.0

# Packaging
build==0.8.0
twine==4.0.1
wheel==0.37.1

# Testing
autoflake==1.4
black==22.6.0
autoflake==1.6.1
black==22.8.0
flake8==3.9.2
importlib-metadata==4.13.0; python_version>='3.7'
isort==5.10.1
pytest==7.1.2
pytest-mock==3.8.2
mypy==0.961
pytest==7.1.3
pytest-mock==3.9.0
mypy==0.981
types-click==7.1.8
types-pyyaml==6.0.9
types-pyyaml==6.0.12
trustme==0.9.0
cryptography==37.0.4
coverage==6.4.1
coverage-conditional-plugin==0.5.0
cryptography==38.0.1
coverage==6.5.0
coverage-conditional-plugin==0.7.0
httpx==0.23.0
watchgod==0.8.2

# Documentation
mkdocs==1.3.0
mkdocs-material==8.3.9
mkdocs==1.4.0
mkdocs-material==8.5.4
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ fi

set -x

${PREFIX}python setup.py sdist bdist_wheel
${PREFIX}python -m build
${PREFIX}twine check dist/*
${PREFIX}mkdocs build
5 changes: 3 additions & 2 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ if [ -z "$GITHUB_ACTIONS" ]; then
"$PYTHON" -m venv "$VENV"
PIP="$VENV/bin/pip"
else
PIP="pip"
PIP="$PYTHON -m pip"
fi

"$PIP" install -r "$REQUIREMENTS"
${PIP} install -U pip
${PIP} install -r "$REQUIREMENTS"
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
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,13 +82,14 @@ plugins =

[coverage:report]
precision = 2
fail_under = 97.33
fail_under = 97.69
show_missing = true
skip_covered = true
exclude_lines =
pragma: no cover
pragma: nocover
if TYPE_CHECKING:
if typing.TYPE_CHECKING:
raise NotImplementedError

[coverage:coverage_conditional_plugin]
Expand Down
109 changes: 18 additions & 91 deletions setup.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,103 +1,30 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import re
import sys

from setuptools import setup


def get_version(package):
"""
Return package version as listed in `__version__` in `init.py`.
"""
path = os.path.join(package, "__init__.py")
init_py = open(path, "r", encoding="utf8").read()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)


def get_long_description():
"""
Return the README.
"""
return open("README.md", "r", encoding="utf8").read()


def get_packages(package):
sys.stderr.write(
"""
Return root package and all sub-packages.
"""
return [
dirpath
for dirpath, dirnames, filenames in os.walk(package)
if os.path.exists(os.path.join(dirpath, "__init__.py"))
]


env_marker_cpython = (
"sys_platform != 'win32'"
" and (sys_platform != 'cygwin'"
" and platform_python_implementation != 'PyPy')"
===============================
Unsupported installation method
===============================
Uvicorn no longer supports installation with `python setup.py install`.
Please use `python -m pip install .` instead.
"""
)
sys.exit(1)

env_marker_win = "sys_platform == 'win32'"
env_marker_below_38 = "python_version < '3.8'"

minimal_requirements = [
"click>=7.0",
"h11>=0.8",
"typing-extensions;" + env_marker_below_38,
]


extra_requirements = [
"websockets>=10.0",
"httptools>=0.4.0",
"uvloop>=0.14.0,!=0.15.0,!=0.15.1; " + env_marker_cpython,
"colorama>=0.4;" + env_marker_win,
"watchfiles>=0.13",
"python-dotenv>=0.13",
"PyYAML>=5.1",
]

# The below code will never execute, however GitHub is particularly
# picky about where it finds Python packaging metadata.
# See: https://github.com/github/feedback/discussions/6456
#
# To be removed once GitHub catches up.

setup(
name="uvicorn",
version=get_version("uvicorn"),
url="https://www.uvicorn.org/",
license="BSD",
description="The lightning-fast ASGI server.",
long_description=get_long_description(),
long_description_content_type="text/markdown",
author="Tom Christie",
author_email="tom@tomchristie.com",
packages=get_packages("uvicorn"),
python_requires=">=3.7",
install_requires=minimal_requirements,
extras_require={"standard": extra_requirements},
include_package_data=True,
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Topic :: Internet :: WWW/HTTP",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
install_requires=[
"click>=7.0",
"h11>=0.8",
"typing-extensions;python_version < '3.8'",
],
entry_points="""
[console_scripts]
uvicorn=uvicorn.main:main
""",
project_urls={
"Funding": "https://github.com/sponsors/encode",
"Source": "https://github.com/encode/uvicorn",
"Changelog": "https://github.com/encode/uvicorn/blob/master/CHANGELOG.md",
},
)
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@

from uvicorn.config import LOGGING_CONFIG

# Note: We explicitly turn the propagate on just for tests, because pytest
# caplog not able to capture no-propagate loggers.
#
# And the caplog_for_logger helper also not work on test config cases, because
# when create Config object, Config.configure_logging will remove caplog.handler.
#
# The simple solution is set propagate=True before execute tests.
#
# See also: https://github.com/pytest-dev/pytest/issues/3697
LOGGING_CONFIG["loggers"]["uvicorn"]["propagate"] = True


@pytest.fixture
def tls_certificate_authority() -> trustme.CA:
Expand Down
Loading

0 comments on commit 1e48e1e

Please sign in to comment.