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

Shallow copy resources and resource factories instead of using context chain lookup #129

Merged
merged 13 commits into from
Dec 12, 2024
Merged
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
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
5 changes: 5 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This library adheres to `Semantic Versioning 2.0 <https://semver.org/>`_.

* Dropped the ``TeardownError`` exception in favor of PEP 654 exception groups
* Dropped the ``Context.loop`` attribute
* Dropped the ``Context.context_chain`` attribute
* Dropped the ``Context.close()`` method (``Context`` objects are now required to be
used as context managers)
* Dropped the deprecated ability to use a ``Context`` as a synchronous context manager
Expand All @@ -59,6 +60,10 @@ This library adheres to `Semantic Versioning 2.0 <https://semver.org/>`_.
resource factories, and optionally waiting for the resource to become available
* ``get_resource_nowait()`` the synchronous counterpart to the above, but incapable
of waiting for resources or triggering asynchronous resource factories
* Contexts now make a shallow copy of the non-generated resources, and resource
factories, from their parents rather than allowing lookup from parents. This was
done to prevent service tasks from using resources added later in the application
startup cycle which would be torn down before the tasks.
- **BACKWARD INCOMPATIBLE** Dropped the deprecated ``Dependency()`` marker
- **BACKWARD INCOMPATIBLE** Changes in the event system:

Expand Down
6 changes: 1 addition & 5 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,
start_service_task,
)
from asphalt.core import Component, run_application, start_service_task


async def handle(stream: SocketStream) -> None:
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +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"
"ASYNC109",
"ASYNC115",
"RUF001",
]

[tool.ruff.lint.isort]
Expand Down
4 changes: 2 additions & 2 deletions src/asphalt/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from ._component import start_component as start_component
from ._concurrent import TaskFactory as TaskFactory
from ._concurrent import TaskHandle as TaskHandle
from ._concurrent import start_background_task_factory as start_background_task_factory
from ._concurrent import start_service_task as start_service_task
from ._context import Context as Context
from ._context import ResourceEvent as ResourceEvent
from ._context import add_resource as add_resource
Expand All @@ -19,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
Loading