Skip to content

Commit

Permalink
Backed out of adding back the ctx parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Dec 12, 2024
1 parent be7d386 commit 1b27d89
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 338 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/snippets/echo1.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# isort: off
from __future__ import annotations

from asphalt.core import Component, run_application, ComponentContext
from asphalt.core import Component, run_application


class ServerComponent(Component):
async def start(self, ctx: ComponentContext) -> None:
async def start(self) -> None:
print("Hello, world!")


Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/contexts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ For example::
class FooComponent(Component):
async def start():
service = SomeService()
await service.start(ctx)
await service.start()
add_teardown_callback(service.stop)
add_resource(service)

Expand Down
9 changes: 4 additions & 5 deletions docs/userguide/snippets/components1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from asphalt.core import (
Component,
ComponentContext,
add_resource,
get_resource,
get_resource_nowait,
Expand All @@ -13,11 +12,11 @@ def __init__(self) -> None:
self.add_component("child1", ChildComponent, name="child1")
self.add_component("child2", ChildComponent, name="child2")

async def prepare(self, ctx: ComponentContext) -> None:
async def prepare(self) -> None:
print("ParentComponent.prepare()")
add_resource("Hello") # adds a `str` type resource by the name `default`

async def start(self, ctx: ComponentContext) -> None:
async def start(self) -> None:
print("ParentComponent.start()")
print(get_resource_nowait(str, "child1_resource"))
print(get_resource_nowait(str, "child2_resource"))
Expand All @@ -30,11 +29,11 @@ class ChildComponent(Component):
def __init__(self, name: str) -> None:
self.name = name

async def prepare(self, ctx: ComponentContext) -> None:
async def prepare(self) -> None:
self.parent_resource = get_resource_nowait(str)
print(f"ChildComponent.prepare() [{self.name}]")

async def start(self, ctx: ComponentContext) -> None:
async def start(self) -> None:
print(f"ChildComponent.start() [{self.name}]")

# Add a `str` type resource, with a name like `childX_resource`
Expand Down
10 changes: 3 additions & 7 deletions examples/tutorial1/echo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

import anyio
from anyio.abc import SocketStream, TaskStatus
from asphalt.core import (
Component,
run_application,
ComponentContext,
)
from asphalt.core import Component, run_application, start_service_task


async def handle(stream: SocketStream) -> None:
Expand All @@ -27,8 +23,8 @@ async def serve_requests(*, task_status: TaskStatus[None]) -> None:


class ServerComponent(Component):
async def start(self, ctx: ComponentContext) -> None:
await ctx.start_service_task(serve_requests, "Echo server")
async def start(self) -> None:
await start_service_task(serve_requests, "Echo server")


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorial2/webnotifier/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Event,
Signal,
add_resource,
ComponentContext,
start_service_task,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -59,10 +59,10 @@ def __init__(self, url: str, delay: int = 10):
self.url = url
self.delay = delay

async def start(self, ctx: ComponentContext) -> None:
async def start(self) -> None:
detector = Detector(self.url, self.delay)
add_resource(detector)
await ctx.start_service_task(detector.run, "Web page change detector")
await start_service_task(detector.run, "Web page change detector")
logging.info(
'Started web page change detector for url "%s" with a delay of %d seconds',
self.url,
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ extend-select = [
"I", # isort
"ISC", # flake8-implicit-str-concat
"PGH", # pygrep-hooks
"RUF100", # unused noqa (yesqa)
"RUF", # Ruff-specific rules
"UP", # pyupgrade
"W", # pycodestyle warnings
]
ignore = [
"ASYNC109",
"ASYNC115"
"ASYNC115",
"RUF001",
]

[tool.ruff.lint.isort]
Expand Down
3 changes: 2 additions & 1 deletion src/asphalt/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ._component import CLIApplicationComponent as CLIApplicationComponent
from ._component import Component as Component
from ._component import ComponentContext as ComponentContext
from ._component import start_component as start_component
from ._concurrent import TaskFactory as TaskFactory
from ._concurrent import TaskHandle as TaskHandle
Expand All @@ -18,6 +17,8 @@
from ._context import get_resources as get_resources
from ._context import inject as inject
from ._context import resource as resource
from ._context import start_background_task_factory as start_background_task_factory
from ._context import start_service_task as start_service_task
from ._event import Event as Event
from ._event import Signal as Signal
from ._event import SignalQueueFull as SignalQueueFull
Expand Down
Loading

0 comments on commit 1b27d89

Please sign in to comment.