Skip to content

Commit

Permalink
adjust the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pkucmus committed Oct 13, 2024
1 parent 4b6394b commit 9d455fc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ sequenceDiagram
STAR->>STAR: Lookup handlers by path
STAR->>+PROC: Send event and context
alt "Process is cold"
PROC<<->>HAND: Import handler
end
PROC->>+HAND: Invoke handler
HAND->>-PROC: Result
PROC->>-STAR: Result
Expand Down
12 changes: 7 additions & 5 deletions docs/user_guide/custom_entrypoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ Here's an example `smyth_conf.py` file:

```python title="my_project/etc/smyth_conf.py" linenums="1"
import uvicorn
from starlette.requests import Request
from smyth.smyth import Smyth
from smyth.server.app import SmythStarlette
from smyth.smyth import Smyth
from starlette.requests import Request


def my_handler(event, context):
return {"statusCode": 200, "body": "Hello, World!"}
Expand All @@ -46,16 +47,17 @@ smyth = Smyth()
smyth.add_handler(
name="hello",
path="/hello",
lambda_handler=my_handler,
lambda_handler_path="smyth_run.my_handler",
timeout=1,
concurrency=1,
event_data_generator=my_event_data_generator,
event_data_function=my_event_data_generator,
)

app = SmythStarlette(smyth=smyth, smyth_path_prefix="/smyth")

if __name__ == "__main__":
uvicorn.run("smyth_conf:app", host="0.0.0.0", port=8080, reload=True)
uvicorn.run("smyth_run:app", host="0.0.0.0", port=8080, reload=True)

```

Normally, the handler would be imported, but including the custom event generator in this file is a good use case. Use the `SmythStarlette` subclass of `Starlette` - it ensures all subprocesses are run at server start and killed on stop (using ASGI Lifetime). Create a Smyth instance and pass it to your `SmythStarlette` instance. Here, you can fine-tune logging, change Uvicorn settings, etc.
Expand Down
5 changes: 3 additions & 2 deletions docs/user_guide/non_http.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ In your `etc` directory, create a `smyth_run.py` file.
smyth.add_handler(
name="hello",
path="/hello",
lambda_handler=my_handler,
lambda_handler_path="smyth_run.my_handler",
timeout=60,
concurrency=10,
strategy_generator=round_robin,
Expand All @@ -65,6 +65,7 @@ In your `etc` directory, create a `smyth_run.py` file.
if __name__ == "__main__":
with smyth:
asyncio.run(main())

```

### Import and Declare the Basics
Expand Down Expand Up @@ -118,7 +119,7 @@ smyth = Smyth()
smyth.add_handler(
name="hello",
path="/hello",
lambda_handler=my_handler,
lambda_handler_path="smyth_run.my_handler",
timeout=60,
concurrency=10,
strategy_generator=round_robin,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Source = "https://github.com/mirumee/smyth"
[project.optional-dependencies]
dev = ["ipdb"]
types = ["mypy>=1.0.0", "pytest", "types-toml", "pytest-asyncio"]
docs = ["mkdocs-material"]
docs = ["mkdocs-material", "termynal"]

[tool.hatch.version]
path = "src/smyth/__about__.py"
Expand Down Expand Up @@ -156,7 +156,7 @@ docstring-code-line-length = 80

[tool.ruff.lint]
select = ["E", "F", "G", "I", "N", "Q", "UP", "C90", "T20", "TID"]
unfixable = ["UP007"] # typer does not handle PEP604 annotations
unfixable = ["UP007"] # typer does not handle PEP604 annotations

[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"
Expand Down
6 changes: 0 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

@pytest.fixture(autouse=True)
def anyio_backend():
# uvloop is not available for Python 3.13
# https://github.com/MagicStack/uvloop/issues/622
# waiting for 0.21.0 release
# import sys
# if sys.version_info < (3, 13):
# return "asyncio"
return "asyncio", {"use_uvloop": True}


Expand Down

0 comments on commit 9d455fc

Please sign in to comment.