Skip to content

Commit

Permalink
Merge pull request #1 from davidbrochart/anyio
Browse files Browse the repository at this point in the history
Replace asyncio and trio implementations with anyio
  • Loading branch information
davidbrochart authored Apr 3, 2024
2 parents 3fbd5f2 + e9d326b commit 07e8ac8
Show file tree
Hide file tree
Showing 73 changed files with 1,042 additions and 2,456 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:

jobs:
tox:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -42,14 +41,9 @@ jobs:


h2spec:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- {name: 'asyncio', worker: 'asyncio'}
- {name: 'trio', worker: 'trio'}

steps:
- uses: actions/checkout@v3
Expand All @@ -67,7 +61,7 @@ jobs:

- name: Run server
working-directory: compliance/h2spec
run: nohup hypercorn --keyfile key.pem --certfile cert.pem -k ${{ matrix.worker }} server:app &
run: nohup anycorn --keyfile key.pem --certfile cert.pem server:app &

- name: Download h2spec
run: |
Expand All @@ -78,14 +72,9 @@ jobs:
run: ./h2spec -tk -h 127.0.0.1 -p 8000 -o 10

autobahn:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- {name: 'asyncio', worker: 'asyncio'}
- {name: 'trio', worker: 'trio'}

steps:
- uses: actions/checkout@v3
Expand All @@ -102,7 +91,7 @@ jobs:
- run: python3 -m pip install trio .
- name: Run server
working-directory: compliance/autobahn
run: nohup hypercorn -k ${{ matrix.worker }} server:app &
run: nohup anycorn server:app &

- name: Run Unit Tests
working-directory: compliance/autobahn
Expand Down
73 changes: 37 additions & 36 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,82 +1,83 @@
Hypercorn
=========
Anycorn
=======

.. image:: https://github.com/pgjones/hypercorn/raw/main/artwork/logo.png
.. image:: https://github.com/davidbrochart/anycorn/raw/main/artwork/logo.png
:alt: Hypercorn logo

|Build Status| |docs| |pypi| |http| |python| |license|

Hypercorn is an `ASGI
Anycorn is an `ASGI
<https://github.com/django/asgiref/blob/main/specs/asgi.rst>`_ and
WSGI web server based on the sans-io hyper, `h11
<https://github.com/python-hyper/h11>`_, `h2
<https://github.com/python-hyper/hyper-h2>`_, and `wsproto
<https://github.com/python-hyper/wsproto>`_ libraries and inspired by
Gunicorn. Hypercorn supports HTTP/1, HTTP/2, WebSockets (over HTTP/1
and HTTP/2), ASGI, and WSGI specifications. Hypercorn can utilise
asyncio, uvloop, or trio worker types.
Gunicorn. Anycorn supports HTTP/1, HTTP/2, WebSockets (over HTTP/1
and HTTP/2), ASGI, and WSGI specifications. Anycorn utilises
anyio worker types.

Hypercorn can optionally serve the current draft of the HTTP/3
Anycorn can optionally serve the current draft of the HTTP/3
specification using the `aioquic
<https://github.com/aiortc/aioquic/>`_ library. To enable this install
the ``h3`` optional extra, ``pip install hypercorn[h3]`` and then
choose a quic binding e.g. ``hypercorn --quic-bind localhost:4433
the ``h3`` optional extra, ``pip install anycorn[h3]`` and then
choose a quic binding e.g. ``anycorn --quic-bind localhost:4433
...``.

Hypercorn was initially part of `Quart
<https://github.com/pgjones/quart>`_ before being separated out into a
standalone server. Hypercorn forked from version 0.5.0 of Quart.
Anycorn is a fork of `Hypercorn
<https://github.com/pgjones/hypercorn>`_ that replaces asyncio where
asyncio and Trio implementations are replaced with AnyIO.
Anycorn forked from version 0.16.0 of Hypercorn.

Quickstart
----------

Hypercorn can be installed via `pip
Anycorn can be installed via `pip
<https://docs.python.org/3/installing/index.html>`_,

.. code-block:: console
$ pip install hypercorn
$ pip install anycorn
and requires Python 3.8 or higher.

With hypercorn installed ASGI frameworks (or apps) can be served via
Hypercorn via the command line,
With anycorn installed ASGI frameworks (or apps) can be served via
Anycorn via the command line,

.. code-block:: console
$ hypercorn module:app
$ anycorn module:app
Alternatively Hypercorn can be used programatically,
Alternatively Anycorn can be used programatically,

.. code-block:: python
import asyncio
from hypercorn.config import Config
from hypercorn.asyncio import serve
import anyio
from anycorn.config import Config
from anycorn import serve
from module import app
asyncio.run(serve(app, Config()))
anyio.run(serve, app, Config())
learn more (including a Trio example of the above) in the `API usage
learn more in the `API usage
<https://hypercorn.readthedocs.io/en/latest/how_to_guides/api_usage.html>`_
docs.

Contributing
------------

Hypercorn is developed on `Github
<https://github.com/pgjones/hypercorn>`_. If you come across an issue,
Anycorn is developed on `Github
<https://github.com/davidbrochart/anycorn>`_. If you come across an issue,
or have a feature request please open an `issue
<https://github.com/pgjones/hypercorn/issues>`_. If you want to
<https://github.com/davidbrochart/anycorn/issues>`_. If you want to
contribute a fix or the feature-implementation please do (typo fixes
welcome), by proposing a `pull request
<https://github.com/pgjones/hypercorn/merge_requests>`_.
<https://github.com/davidbrochart/anycorn/merge_requests>`_.

Testing
~~~~~~~

The best way to test Hypercorn is with `Tox
The best way to test Anycorn is with `Tox
<https://tox.readthedocs.io>`_,

.. code-block:: console
Expand All @@ -89,26 +90,26 @@ this will check the code style and run the tests.
Help
----

The Hypercorn `documentation <https://hypercorn.readthedocs.io>`_ is
The Anycorn `documentation <https://hypercorn.readthedocs.io>`_ is
the best place to start, after that try searching stack overflow, if
you still can't find an answer please `open an issue
<https://github.com/pgjones/hypercorn/issues>`_.
<https://github.com/davidbrochart/anycorn/issues>`_.


.. |Build Status| image:: https://github.com/pgjones/hypercorn/actions/workflows/ci.yml/badge.svg
:target: https://github.com/pgjones/hypercorn/commits/main
.. |Build Status| image:: https://github.com/davidbrochart/anycorn/actions/workflows/ci.yml/badge.svg
:target: https://github.com/davidbrochart/anycorn/commits/main

.. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg
:target: https://hypercorn.readthedocs.io

.. |pypi| image:: https://img.shields.io/pypi/v/hypercorn.svg
:target: https://pypi.python.org/pypi/Hypercorn/
:target: https://pypi.python.org/pypi/anycorn/

.. |http| image:: https://img.shields.io/badge/http-1.0,1.1,2-orange.svg
:target: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

.. |python| image:: https://img.shields.io/pypi/pyversions/hypercorn.svg
:target: https://pypi.python.org/pypi/Hypercorn/
:target: https://pypi.python.org/pypi/anycorn/

.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://github.com/pgjones/hypercorn/blob/main/LICENSE
:target: https://github.com/davidbrochart/anycorn/blob/main/LICENSE
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = "Hypercorn"
name = "anycorn"
version = "0.16.0"
description = "A ASGI Server based on Hyper libraries and inspired by Gunicorn"
authors = ["pgjones <philip.graham.jones@googlemail.com>"]
authors = ["pgjones <philip.graham.jones@googlemail.com>", "David Brochart <david.brochart@gmail.com>"]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
Expand All @@ -19,10 +19,10 @@ classifiers = [
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
"Topic :: Software Development :: Libraries :: Python Modules",
]
include = ["src/hypercorn/py.typed"]
include = ["src/anycorn/py.typed"]
license = "MIT"
readme = "README.rst"
repository = "https://github.com/pgjones/hypercorn/"
repository = "https://github.com/davidbrochart/anycorn/"
documentation = "https://hypercorn.readthedocs.io"

[tool.poetry.dependencies]
Expand All @@ -31,12 +31,12 @@ aioquic = { version = ">= 0.9.0, < 1.0", optional = true }
exceptiongroup = ">= 1.1.0"
h11 = "*"
h2 = ">=3.1.0"
anyio = ">=4.0, <5.0"
priority = "*"
pydata_sphinx_theme = { version = "*", optional = true }
sphinxcontrib_mermaid = { version = "*", optional = true }
taskgroup = { version = "*", python = "<3.11", allow-prereleases = true }
tomli = { version = "*", python = "<3.11" }
trio = { version = ">=0.22.0", optional = true }
uvloop = { version = "*", markers = "platform_system != 'Windows'", optional = true }
wsproto = ">=0.14.0"

Expand All @@ -49,7 +49,7 @@ pytest-trio = "*"
trio = "*"

[tool.poetry.scripts]
hypercorn = "hypercorn.__main__:main"
anycorn = "anycorn.__main__:main"

[tool.poetry.extras]
docs = ["pydata_sphinx_theme", "sphinxcontrib_mermaid"]
Expand All @@ -65,7 +65,7 @@ target-version = ["py38"]
combine_as_imports = true
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = "hypercorn, tests"
known_first_party = "anycorn, tests"
line_length = 100
multi_line_output = 3
no_lines_before = "LOCALFOLDER"
Expand Down
14 changes: 8 additions & 6 deletions src/hypercorn/trio/__init__.py → src/anycorn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import warnings
from typing import Awaitable, Callable, Literal, Optional

import trio
import anyio

from .config import Config
from .run import worker_serve
from ..config import Config
from ..typing import Framework
from ..utils import wrap_app
from .typing import Framework
from .utils import wrap_app

__all__ = ("Config", "serve")


async def serve(
app: Framework,
config: Config,
*,
shutdown_trigger: Optional[Callable[..., Awaitable[None]]] = None,
task_status: trio._core._run._TaskStatus = trio.TASK_STATUS_IGNORED,
task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED,
mode: Optional[Literal["asgi", "wsgi"]] = None,
) -> None:
"""Serve an ASGI framework app given the config.
Expand All @@ -26,7 +28,7 @@ async def serve(
.. code-block:: python
trio.run(serve, app, config)
anyio.run(serve, app, config)
It is assumed that the event-loop is configured before calling
this function, therefore configuration values that relate to loop
Expand Down
11 changes: 0 additions & 11 deletions src/hypercorn/__main__.py → src/anycorn/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ def main(sys_args: Optional[List[str]] = None) -> int:
parser.add_argument(
"-g", "--group", help="Group to own any unix sockets.", default=sentinel, type=int
)
parser.add_argument(
"-k",
"--worker-class",
dest="worker_class",
help="The type of worker to use. "
"Options include asyncio, uvloop (pip install hypercorn[uvloop]), "
"and trio (pip install hypercorn[trio]).",
default=sentinel,
)
parser.add_argument(
"--keep-alive",
help="Seconds to keep inactive connections alive for",
Expand Down Expand Up @@ -283,8 +274,6 @@ def _convert_verify_mode(value: str) -> ssl.VerifyMode:
config.umask = args.umask
if args.user is not sentinel:
config.user = args.user
if args.worker_class is not sentinel:
config.worker_class = args.worker_class
if args.verify_mode is not sentinel:
config.verify_mode = args.verify_mode
if args.websocket_ping_interval is not sentinel:
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions src/hypercorn/config.py → src/anycorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class Config:
verify_mode: Optional[VerifyMode] = None
websocket_max_message_size = 16 * 1024 * 1024 * BYTES
websocket_ping_interval: Optional[float] = None
worker_class = "asyncio"
workers = 1
wsgi_max_body_size = 16 * 1024 * 1024 * BYTES

Expand Down Expand Up @@ -281,7 +280,7 @@ def response_headers(self, protocol: str) -> List[Tuple[bytes, bytes]]:
if self.include_date_header:
headers.append((b"date", format_date_time(time()).encode("ascii")))
if self.include_server_header:
headers.append((b"server", f"hypercorn-{protocol}".encode("ascii")))
headers.append((b"server", f"anycorn-{protocol}".encode("ascii")))

for alt_svc_header in self.alt_svc_headers:
headers.append((b"alt-svc", alt_svc_header.encode()))
Expand Down Expand Up @@ -338,7 +337,7 @@ def from_pyfile(cls: Type["Config"], filename: FilePath) -> "Config":
.. code-block:: python
Config.from_pyfile('hypercorn_config.py')
Config.from_pyfile('anycorn_config.py')
Arguments:
filename: The filename which gives the path to the file.
Expand Down
File renamed without changes.
Loading

0 comments on commit 07e8ac8

Please sign in to comment.