TIL search: asgi

asgi Writing tests for the ASGI lifespan protocol with HTTPX - 2020-06-29

Uvicorn silently ignores exceptions that occur during startup against the ASGI lifespan protocol - see [starlette/issues/486](https://github.com/encode/starlette/issues/486).

You can disable this feature using the `lifespan="on"` parameter to `uvicorn.run()` - which Datasette now does as-of [16f592247a2a0e140ada487e9972645406dcae69](https://github.com/simonw/datasette/commit/16f592247a2a0e140ada487e9972645406dcae69)

This exposed a bug in `datasette-debug-asgi`: it...

pytest Code coverage using pytest and codecov.io - 2020-08-15

I got my [asgi-csrf](https://github.com/simonw/asgi-csrf) Python package up to 100% code coverage. Here's [the pull request](https://github.com/simonw/asgi-csrf/issues/13).

I started by installing and using the [pytest-cov](https://pypi.org/project/pytest-cov/) pytest plugin.

pip install pytest-cov
pytest --cov=asgi_csrf
This shows the current...

zeit-now Running a Python ASGI app on Vercel - 2020-04-19

...It turns out you can subvert that model entirely and route all of your traffic through a single function - great for serving up Python WSGI or ASGI apps that handle traffic routing themselves.

the trick is to use the `"routes"` key in a `now.json` file like this:

    "version": 2,
    "builds": [
            "src": "json_head.py",
            "use": "@now/python"

datasette Redirects for Datasette - 2020-11-25

...I configured the redirects using a one-off Datasette plugin called `redirects.py` which I dropped into the `plugins/` directory for the Datasette instance:

from datasette import hookimpl
from datasette.utils.asgi import Response

def register_routes():
    return (
        (r"^/til/til/(?P<topic>[^_]+)_(?P<slug>[^\.]+)\.md$", lambda request: Response.redirect(
            "/{topic}/{slug}".format(**request.url_vars), status=301...

cloudrun Use labels on Cloud Run services for a billing breakdown - 2020-04-21

...service \
    --region=$region --platform=managed \
    --update-labels service=$service

It runs the equivalent of this for each service:
gcloud run services update asgi-log-demo --region=us-central1 --platform=managed --update-labels service=asgi-log-demo

I saved that as a `runme.sh` script, run `chmod 755 runme.sh` and then  `./runme.sh` to run it.

The output...

homebrew Packaging a Python CLI tool for Homebrew - 2020-08-11

...poet [-h] [--single package [package ...] | --formula package | --resources package] [--also package] [-V]
(d) $ poet datasette
  resource "aiofiles" do
    url "https://files.pythonhosted.org/packages/2b/64/437053d6a4ba3b3eea1044131a25b458489320cb9609e19ac17261e4dc9b/aiofiles-0.5.0.tar.gz"
    sha256 "98e6bcfd1b50f97db4980e182ddd509b7cc35909e903a8fe50d8849e02d815af"

  resource "asgi-csrf" do
    url "https://files.pythonhosted.org/packages/20/19/60188a9d88e5af17cfb91dac465f898d8eccf69bc215ac731d64c49fea5c/asgi-csrf-0.6.1.tar.gz"
    sha256 "4045b8b45c330e068b8b96f914e585ea69228efbfe574ab4a4be2d8c6009a19f"

sqlite Using LD_PRELOAD to run any version of SQLite with Python - 2020-06-17

...Uvicorn running on (Press CTRL+C to quit)

And now reports the following:

    "python": {
        "version": "3.8.2",
        "full": "3.8.2 (default, Apr 27 2020, 15:53:34) \n[GCC 9.3.0]"
    "datasette": {
        "version": "0.44"
    "asgi": "3.0",
    "uvicorn": "0.11.5",