Skip to content

Commit

Permalink
Merge f1cb0ff into 092545b
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Dec 25, 2022
2 parents 092545b + f1cb0ff commit f477d63
Show file tree
Hide file tree
Showing 14 changed files with 1,758 additions and 279 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: tests


on:
push:
branches: [ master ]
pull_request:
branches: [ master ]


jobs:
pylama:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup python3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Cache virtualenv
id: venv-cache
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ github.job }}-${{ github.ref }}
- run: python -m pip install poetry
- run: poetry install
- run: poetry run pylama
env:
FORCE_COLOR: 1
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup python3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Cache virtualenv
id: venv-cache
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ github.job }}-${{ github.ref }}
- run: python -m pip install poetry
- run: poetry install
- run: poetry run mypy
env:
FORCE_COLOR: 1

tests:
runs-on: ubuntu-latest

strategy:
fail-fast: false

matrix:
python:
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11'
steps:
- uses: actions/checkout@v2
- name: Setup python${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: "${{ matrix.python }}"
- name: Cache virtualenv
id: venv-cache
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ github.job }}-${{ github.ref }}-${{ matrix.python }}
- run: python -m pip install poetry
- run: poetry install --with=uvloop
- name: pytest
run: >-
poetry run pytest \
-vv \
--cov=aiohttp_asgi \
--cov-report=term-missing \
--doctest-modules \
tests
env:
FORCE_COLOR: 1
- run: poetry run coveralls
env:
COVERALLS_PARALLEL: 'true'
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

finish:
needs:
- tests
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
56 changes: 0 additions & 56 deletions .github/workflows/tox.yml

This file was deleted.

22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from starlette.requests import Request as ASGIRequest

from aiohttp_asgi import ASGIResource


asgi_app = FastAPI()


Expand All @@ -30,24 +31,13 @@ aiohttp_app = web.Application()

# Create ASGIResource which handle
# any request startswith "/asgi"
asgi_resource = ASGIResource(
asgi_app,
root_path="/asgi"
)
asgi_resource = ASGIResource(asgi_app, root_path="/asgi")

# Register resource
aiohttp_app.router.register_resource(
asgi_resource
)

# [Optional]
asgi_resource.lifespan_mount(
aiohttp_app,
startup=True,
# By default starlette didn't
# handle "lifespan.shutdown"
shutdown=False,
)
aiohttp_app.router.register_resource(asgi_resource)

# Mount startup and shutdown events from aiohttp to ASGI app
asgi_resource.lifespan_mount(aiohttp_app)

# Start the application
web.run_app(aiohttp_app)
Expand Down
11 changes: 6 additions & 5 deletions aiohttp_asgi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import logging
import socket
from argparse import ArgumentParser, ArgumentTypeError
from typing import Any

import aiohttp.web

from aiohttp_asgi import ASGIResource

from aiohttp_asgi.resource import ASGIApplicationType

parser = ArgumentParser(prog="aiohttp-asgi")
group = parser.add_argument_group("HTTP options")
Expand All @@ -23,7 +24,7 @@
)


def parse_app(app):
def parse_app(app: str) -> ASGIApplicationType:
try:
module_name, asgi_app = app.split(":", 1)
except ValueError:
Expand All @@ -49,9 +50,9 @@ def parse_app(app):


def bind_socket(
*args, address: str, port: int,
*args: Any, address: str, port: int,
reuse_addr: bool = True, reuse_port: bool = False
):
) -> socket.socket:
if not args:
if ":" in address:
args = (socket.AF_INET6, socket.SOCK_STREAM)
Expand All @@ -78,7 +79,7 @@ def bind_socket(
return sock


def main():
def main() -> None:
arguments = parser.parse_args()
logging.basicConfig(level=getattr(logging, arguments.log_level.upper()))

Expand Down
Loading

0 comments on commit f477d63

Please sign in to comment.