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

Migrated to Asphalt 5 #68

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Create packages
run: python -m build
- name: Archive packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
Expand All @@ -38,7 +38,7 @@ jobs:
id-token: write
steps:
- name: Retrieve packages
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
- name: Upload packages
uses: pypa/gh-action-pypi-publish@release/v1

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.10"]
python-version: ["3.9", "3.10", "3.11", "3.12", "pypy-3.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -23,7 +23,7 @@ jobs:
cache: pip
cache-dependency-path: pyproject.toml
- name: Install dependencies
run: pip install .[test]
run: pip install -e .[test]
- name: Test with pytest
run: coverage run -m pytest -v
- name: Generate coverage report
Expand Down
15 changes: 11 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# * Run "pre-commit install".
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -16,17 +16,24 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
rev: v0.8.4
hooks:
- id: ruff
args: [--fix, --show-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.14.0
hooks:
- id: mypy
additional_dependencies:
- asphalt
- asphalt@git+https://github.com/asphalt-framework/asphalt
- pytest
exclude: ^(examples/|tests/django_app/)

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.9"

sphinx:
configuration: docs/conf.py
Expand Down
6 changes: 3 additions & 3 deletions docs/integrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,21 @@ Litestar has its own dependency injection system which can optionally be used to
Asphalt resources in web endpoints. This can be done by using
:class:`~asphalt.web.litestar.AsphaltProvide` instead of :class:`~litestar.di.Provide`::

from litestar import get
from asphalt.web.litestar import AsphaltProvide
from litestar import get

@get("/endpointname", dependencies={"myresource": AsphaltProvide(SomeConnection)})
async def myendpoint(myresource: SomeConnection) -> None:
...

This would be roughly equivalent to::

from asphalt.core import get_resource_nowait
from litestar import get
from asphalt.core import require_resource

@get("/endpointname")
async def myendpoint() -> None:
myresource = require_resource(SomeConnection)
myresource = get_resource_nowait(SomeConnection)
...

Resources available on the global context:
Expand Down
5 changes: 5 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ Version history

This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.

**UNRELEASED**

- Migrated to Asphalt 5
- Dropped Python 3.8 support

**1.3.1**

- Fixed Starlette/FastAPI request resource being added under the wrong type since
Expand Down
4 changes: 2 additions & 2 deletions examples/aiohttp/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from aiohttp.abc import Request
from aiohttp.web_app import Application
from aiohttp.web_response import Response
from asphalt.core import Component, Context, inject, resource
from asphalt.core import Component, inject, resource


async def root(request: Request) -> Response:
Expand All @@ -10,5 +10,5 @@ async def root(request: Request) -> Response:

class WebRootComponent(Component):
@inject
async def start(self, ctx: Context, app: Application = resource()) -> None:
async def start(self, app: Application = resource()) -> None:
app.router.add_route("GET", "/", root)
10 changes: 9 additions & 1 deletion examples/asgi3/static.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
async def application(scope, receive, send):
"""Trivial example of a raw ASGI 3.0 application without a framework."""
if scope["type"] == "http":
if scope["type"] == "lifespan":
while True:
message = await receive()
if message["type"] == "lifespan.startup":
await send({"type": "lifespan.startup.complete"})
elif message["type"] == "lifespan.shutdown":
await send({"type": "lifespan.shutdown.complete"})
return
elif scope["type"] == "http":
await receive()
await send(
{
Expand Down
4 changes: 2 additions & 2 deletions examples/fastapi/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asphalt.core import Component, Context, inject, resource
from asphalt.core import Component, inject, resource
from fastapi import FastAPI
from fastapi.responses import PlainTextResponse

Expand All @@ -9,5 +9,5 @@ async def root() -> str:

class WebRootComponent(Component):
@inject
async def start(self, ctx: Context, app: FastAPI = resource()) -> None:
async def start(self, app: FastAPI = resource()) -> None:
app.add_api_route("/", root, response_class=PlainTextResponse)
6 changes: 3 additions & 3 deletions examples/litestar/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asphalt.core import Component, Context, require_resource
from asphalt.core import Component, get_resource_nowait
from litestar import Litestar, get


Expand All @@ -8,5 +8,5 @@ async def root() -> str:


class WebRootComponent(Component):
async def start(self, ctx: Context) -> None:
require_resource(Litestar).register(root)
async def start(self) -> None:
get_resource_nowait(Litestar).register(root)
4 changes: 2 additions & 2 deletions examples/starlette/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asphalt.core import Component, Context, inject, resource
from asphalt.core import Component, inject, resource
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import PlainTextResponse, Response
Expand All @@ -10,5 +10,5 @@ async def root(request: Request) -> Response:

class WebRootComponent(Component):
@inject
async def start(self, ctx: Context, app: Starlette = resource()) -> None:
async def start(self, app: Starlette = resource()) -> None:
app.add_route("/", root)
78 changes: 41 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ classifiers = [
"License :: OSI Approved :: Apache Software License",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Environment :: Web Environment",
"Framework :: AsyncIO",
"Framework :: AnyIO",
"Typing :: Typed",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"asphalt ~= 4.8",
"asphalt @ git+https://github.com/asphalt-framework/asphalt",
]
dynamic = ["version"]

Expand All @@ -45,38 +45,39 @@ aiohttp = [
]
asgi3 = [
"asgiref ~= 3.5",
"uvicorn >= 0.17.6",
"hypercorn >= 0.16.0",
]
django = [
"asgiref ~= 3.5",
"Django >= 3.2",
"uvicorn >= 0.17.6",
"hypercorn >= 0.16.0",
]
fastapi = [
"asgiref ~= 3.5",
"fastapi >= 0.75",
"uvicorn >= 0.17.6",
"hypercorn >= 0.16.0",
]
litestar = [
"asgiref ~= 3.5",
"litestar >= 2.2",
"uvicorn >= 0.17.6",
"litestar >= 2.5.5",
"hypercorn >= 0.16.0",
]
starlette = [
"asgiref ~= 3.5",
"starlette >= 0.17",
"uvicorn >= 0.17.6",
"hypercorn >= 0.16.0",
]
test = [
"anyio[trio] >= 4.2",
"asphalt-web[asgi3,fastapi,starlette]",
"coverage >= 7",
"pytest >= 7.4",
"pytest-asyncio",
"httpx",
"websockets",
"aiohttp >= 3.8; python_version < '3.12'",
"httpx-ws",
"aiohttp >= 3.8",
"Django >= 3.2; python_implementation == 'CPython'",
"asphalt-web[asgi3,fastapi,starlette]",
"litestar >= 2.2; python_implementation == 'CPython'",
"litestar >= 2.5.5; python_implementation == 'CPython'",
"pytest >= 7.4",
"websockets >= 14.1",
]
doc = [
"Sphinx >= 7.0",
Expand All @@ -98,31 +99,37 @@ starlette = "asphalt.web.starlette:StarletteComponent"
version_scheme = "post-release"
local_scheme = "dirty-tag"

[tool.pytest.ini_options]
addopts = "-rsx --tb=short"
asyncio_mode = "strict"
testpaths = ["tests"]

[tool.ruff]
line-length = 99

[tool.ruff.lint]
select = [
extend-select = [
"ASYNC", # flake8-async
"E", "F", "W", # default Flake8
"G", # flake8-logging-format
"I", # isort
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"RUF", # Ruff-specific rules
"UP", # pyupgrade
"W", # pycodestyle warnings
]
ignore = [
"RUF003",
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["asphalt.web"]
known-third-party = ["asphalt.core"]

[tool.pytest.ini_options]
addopts = ["-rsfE", "--tb=short"]
testpaths = ["tests"]

[tool.mypy]
python_version = "3.8"
python_version = "3.9"
strict = true
explicit_package_bases = true
mypy_path = ["src", "tests", "examples"]

[tool.coverage.run]
source = ["asphalt.web"]
Expand All @@ -133,17 +140,14 @@ branch = true
show_missing = true

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py38, py39, py310, py311, py312, pypy3
env_list = ["py39", "py310", "py311", "py312", "py313", "pypy3"]
skip_missing_interpreters = true
minversion = 4.0

[testenv]
extras = test
commands = python -m pytest {posargs}
[tool.tox.env_run_base]
commands = [["python", "-m", "pytest", { replace = "posargs", extend = true }]]
package = "editable"
extras = ["test"]

[testenv:docs]
extras = doc
commands = sphinx-build -n docs build/sphinx
"""
[tool.tox.env.docs]
commands = [["sphinx-build", "-W", "-n", "docs", "build/sphinx", { replace = "posargs", extend = true }]]
extras = ["doc"]
12 changes: 12 additions & 0 deletions src/asphalt/web/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from anyio import connect_tcp


async def ensure_server_running(host: str, port: int) -> None:
# Try to connect until we succeed – then we know the server has started
while True:
try:
await connect_tcp(host, port)
except OSError:
pass
else:
break
Loading
Loading