engin 0.1.0b3__tar.gz → 0.1.0b5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {engin-0.1.0b3 → engin-0.1.0b5}/.github/workflows/benchmark.yaml +3 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/.github/workflows/check.yaml +4 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/PKG-INFO +1 -1
- {engin-0.1.0b3 → engin-0.1.0b5}/pyproject.toml +1 -1
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_engin.py +32 -19
- engin-0.1.0b5/tests/acceptance/test_engin_signal_handling.py +28 -0
- engin-0.1.0b5/tests/acceptance/test_error_in_invocation.py +28 -0
- engin-0.1.0b3/tests/acceptance/test_error_in_shutdown.py → engin-0.1.0b5/tests/acceptance/test_error_in_lifecycle_shutdown.py +11 -3
- engin-0.1.0b3/tests/acceptance/test_error_in_start_up.py → engin-0.1.0b5/tests/acceptance/test_error_in_lifecycle_startup.py +17 -1
- engin-0.1.0b5/tests/acceptance/test_error_in_provider.py +35 -0
- engin-0.1.0b3/tests/acceptance/test_error_in_supervised_task.py → engin-0.1.0b5/tests/acceptance/test_error_in_supervisor_task.py +2 -2
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_engin.py +0 -16
- {engin-0.1.0b3 → engin-0.1.0b5}/uv.lock +4 -4
- engin-0.1.0b3/tests/acceptance/test_engin_signal_handling.py +0 -24
- {engin-0.1.0b3 → engin-0.1.0b5}/.github/workflows/publish.yaml +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/.gitignore +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/.readthedocs.yaml +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/CHANGELOG.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/LICENSE +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/README.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/concepts/blocks.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/concepts/engin.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/concepts/invocations.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/concepts/lifecycle.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/concepts/providers.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/concepts/supervisor.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/index.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/integrations/fastapi-graph.png +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/integrations/fastapi.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/js/readthedocs.js +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/overrides/main.html +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/reference.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/docs/tutorial.md +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/app.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/db/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/db/adapaters/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/db/adapaters/memory.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/db/block.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/db/ports.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/starlette/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/common/starlette/endpoint.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/features/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/features/cats/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/features/cats/api/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/features/cats/api/get.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/features/cats/api/post.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/features/cats/block.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/features/cats/domain.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/asgi/main.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/app.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/main.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/cats/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/cats/adapters/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/cats/adapters/repository.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/cats/api.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/cats/block.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/cats/domain.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/fastapi/routes/cats/ports.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/simple/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/examples/simple/main.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/mkdocs.yaml +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_assembler.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_block.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_cli/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_cli/_common.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_cli/_graph.html +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_cli/_graph.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_cli/_inspect.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_dependency.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_graph.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_introspect.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_lifecycle.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_option.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_supervisor.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/_type_utils.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/exceptions.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/extensions/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/extensions/asgi.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/extensions/fastapi.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/src/engin/py.typed +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/acceptance/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/acceptance/test_fastapi.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/benchmarks/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/benchmarks/conftest.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/benchmarks/test_bench_assembler.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/cli/__init__.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/cli/test_graph.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/cli/test_inspect.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/conftest.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/deps.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_assembler.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_block.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_dependencies.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_graph.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_lifecycle.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_supervisor.py +0 -0
- {engin-0.1.0b3 → engin-0.1.0b5}/tests/test_type_id.py +0 -0
@@ -3,6 +3,9 @@ name: Check
|
|
3
3
|
on:
|
4
4
|
push:
|
5
5
|
|
6
|
+
env:
|
7
|
+
UV_FROZEN: "1"
|
8
|
+
|
6
9
|
jobs:
|
7
10
|
check:
|
8
11
|
name: python
|
@@ -40,6 +43,7 @@ jobs:
|
|
40
43
|
run: uv run poe ci-test
|
41
44
|
|
42
45
|
- name: Upload coverage reports to Codecov
|
46
|
+
if: matrix.os == 'ubuntu-latest'
|
43
47
|
uses: codecov/codecov-action@v5
|
44
48
|
with:
|
45
49
|
token: ${{ secrets.CODECOV_TOKEN }}
|
@@ -10,7 +10,7 @@ from itertools import chain
|
|
10
10
|
from types import FrameType
|
11
11
|
from typing import ClassVar
|
12
12
|
|
13
|
-
from anyio import create_task_group,
|
13
|
+
from anyio import create_task_group, open_signal_receiver
|
14
14
|
|
15
15
|
from engin._assembler import AssembledDependency, Assembler
|
16
16
|
from engin._dependency import Invoke, Provide, Supply
|
@@ -149,7 +149,7 @@ class Engin:
|
|
149
149
|
except Exception as err:
|
150
150
|
name = invocation.dependency.name
|
151
151
|
LOG.error(f"invocation '{name}' errored, exiting", exc_info=err)
|
152
|
-
|
152
|
+
raise
|
153
153
|
|
154
154
|
lifecycle = await self._assembler.build(Lifecycle)
|
155
155
|
|
@@ -177,10 +177,11 @@ class Engin:
|
|
177
177
|
try:
|
178
178
|
async with supervisor:
|
179
179
|
await self._stop_requested_event.wait()
|
180
|
-
|
181
|
-
|
180
|
+
await self._shutdown()
|
181
|
+
except BaseException:
|
182
|
+
await self._shutdown()
|
183
|
+
|
182
184
|
tg.cancel_scope.cancel()
|
183
|
-
await self._shutdown()
|
184
185
|
|
185
186
|
async def start(self) -> None:
|
186
187
|
"""
|
@@ -188,13 +189,25 @@ class Engin:
|
|
188
189
|
started to return so it is safe to use immediately after.
|
189
190
|
"""
|
190
191
|
self._async_context_run_task = asyncio.create_task(self.run())
|
192
|
+
wait_tasks = [
|
193
|
+
asyncio.create_task(self._start_complete_event.wait()),
|
194
|
+
asyncio.create_task(self._stop_complete_event.wait()),
|
195
|
+
]
|
191
196
|
await asyncio.wait(
|
192
197
|
[
|
193
|
-
|
194
|
-
|
198
|
+
self._async_context_run_task, # if a provider errors this will return first
|
199
|
+
*wait_tasks,
|
195
200
|
],
|
196
201
|
return_when=asyncio.FIRST_COMPLETED,
|
197
202
|
)
|
203
|
+
for task in wait_tasks:
|
204
|
+
task.cancel()
|
205
|
+
|
206
|
+
# raise the exception from the startup during run
|
207
|
+
if self._async_context_run_task.done():
|
208
|
+
startup_exception = self._async_context_run_task.exception()
|
209
|
+
if startup_exception is not None:
|
210
|
+
raise startup_exception
|
198
211
|
|
199
212
|
async def stop(self) -> None:
|
200
213
|
"""
|
@@ -205,7 +218,8 @@ class Engin:
|
|
205
218
|
started.
|
206
219
|
"""
|
207
220
|
self._stop_requested_event.set()
|
208
|
-
|
221
|
+
if self._state == _EnginState.RUNNING:
|
222
|
+
await self._stop_complete_event.wait()
|
209
223
|
|
210
224
|
def graph(self) -> list[Node]:
|
211
225
|
"""
|
@@ -224,24 +238,23 @@ class Engin:
|
|
224
238
|
return self._state == _EnginState.SHUTDOWN
|
225
239
|
|
226
240
|
async def _shutdown(self) -> None:
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
241
|
+
if self._state == _EnginState.RUNNING:
|
242
|
+
LOG.info("stopping engin")
|
243
|
+
await self._exit_stack.aclose()
|
244
|
+
self._stop_complete_event.set()
|
245
|
+
LOG.info("shutdown complete")
|
246
|
+
self._state = _EnginState.SHUTDOWN
|
232
247
|
|
233
248
|
|
234
249
|
async def _stop_engin_on_signal(stop_requested_event: Event) -> None:
|
235
250
|
"""
|
236
251
|
A task that waits for a stop signal (SIGINT/SIGTERM) and notifies the given event.
|
237
252
|
"""
|
238
|
-
# try to gracefully handle sigint/sigterm
|
239
253
|
if not _OS_IS_WINDOWS:
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
await stop_requested_event.wait()
|
254
|
+
with open_signal_receiver(signal.SIGINT, signal.SIGTERM) as recieved_signals:
|
255
|
+
async for signum in recieved_signals:
|
256
|
+
LOG.debug(f"received {signum.name} signal")
|
257
|
+
stop_requested_event.set()
|
245
258
|
else:
|
246
259
|
should_stop = False
|
247
260
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import asyncio
|
2
|
+
import signal
|
3
|
+
import sys
|
4
|
+
|
5
|
+
import pytest
|
6
|
+
|
7
|
+
from engin import Engin
|
8
|
+
|
9
|
+
|
10
|
+
@pytest.mark.skipif(sys.platform == "win32", reason="`signal.raise_signal` not supported")
|
11
|
+
async def test_engin_signal_handling_when_run():
|
12
|
+
engin = Engin()
|
13
|
+
task = asyncio.create_task(engin.run())
|
14
|
+
await asyncio.sleep(0.1)
|
15
|
+
signal.raise_signal(signal.SIGTERM)
|
16
|
+
await asyncio.sleep(0.1)
|
17
|
+
assert engin.is_stopped()
|
18
|
+
del task
|
19
|
+
|
20
|
+
|
21
|
+
@pytest.mark.skipif(sys.platform == "win32", reason="`signal.raise_signal` not supported")
|
22
|
+
async def test_engin_signal_handling_when_start():
|
23
|
+
engin = Engin()
|
24
|
+
await engin.start()
|
25
|
+
await asyncio.sleep(0.1)
|
26
|
+
signal.raise_signal(signal.SIGTERM)
|
27
|
+
await asyncio.sleep(0.1)
|
28
|
+
assert engin.is_stopped()
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import asyncio
|
2
|
+
|
3
|
+
import pytest
|
4
|
+
|
5
|
+
from engin import Engin, Invoke
|
6
|
+
|
7
|
+
|
8
|
+
async def test_error_in_invocation_when_run():
|
9
|
+
async def main() -> None:
|
10
|
+
raise ValueError("foo")
|
11
|
+
|
12
|
+
engin = Engin(Invoke(main))
|
13
|
+
|
14
|
+
with pytest.raises(ValueError, match="foo"):
|
15
|
+
await asyncio.wait_for(engin.run(), timeout=0.5)
|
16
|
+
|
17
|
+
|
18
|
+
async def test_error_in_invocation_when_start():
|
19
|
+
async def main() -> None:
|
20
|
+
raise ValueError("foo")
|
21
|
+
|
22
|
+
engin = Engin(Invoke(main))
|
23
|
+
|
24
|
+
with pytest.raises(ValueError, match="foo"):
|
25
|
+
await asyncio.wait_for(engin.start(), timeout=0.5)
|
26
|
+
|
27
|
+
# check we can shutdown the app
|
28
|
+
await asyncio.wait_for(engin.stop(), timeout=0.5)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import asyncio
|
1
2
|
from contextlib import asynccontextmanager
|
2
3
|
|
3
4
|
from starlette.applications import Starlette
|
@@ -29,13 +30,20 @@ def b(lifecycle: Lifecycle) -> None:
|
|
29
30
|
lifecycle.append(_b_startup())
|
30
31
|
|
31
32
|
|
32
|
-
async def
|
33
|
+
async def test_error_in_shutdown_when_start():
|
33
34
|
engin = Engin(Invoke(a), Invoke(b))
|
34
35
|
|
35
|
-
await engin.start()
|
36
|
+
await asyncio.wait_for(engin.start(), timeout=0.5)
|
36
37
|
assert B_LIFECYCLE_STATE == 1
|
37
38
|
|
38
|
-
await engin.stop()
|
39
|
+
await asyncio.wait_for(engin.stop(), timeout=0.5)
|
40
|
+
assert B_LIFECYCLE_STATE == 2
|
41
|
+
|
42
|
+
|
43
|
+
async def test_error_in_shutdown_when_run():
|
44
|
+
engin = Engin(Invoke(a), Invoke(b))
|
45
|
+
|
46
|
+
await asyncio.wait_for(engin.run(), timeout=0.5)
|
39
47
|
assert B_LIFECYCLE_STATE == 2
|
40
48
|
|
41
49
|
|
@@ -42,8 +42,11 @@ async def test_error_in_startup_handled_when_start():
|
|
42
42
|
await asyncio.wait_for(engin.start(), timeout=0.5)
|
43
43
|
assert not B_LIFECYCLE_STATE
|
44
44
|
|
45
|
+
# check we can shutdown the app
|
46
|
+
await asyncio.wait_for(engin.stop(), timeout=0.5)
|
45
47
|
|
46
|
-
|
48
|
+
|
49
|
+
async def test_error_in_startup_asgi_handled_when_run():
|
47
50
|
def asgi_type() -> ASGIType:
|
48
51
|
return Starlette()
|
49
52
|
|
@@ -51,3 +54,16 @@ async def test_error_in_startup_asgi():
|
|
51
54
|
|
52
55
|
await engin.run()
|
53
56
|
assert not B_LIFECYCLE_STATE
|
57
|
+
|
58
|
+
|
59
|
+
async def test_error_in_startup_asgi_handled_when_start():
|
60
|
+
def asgi_type() -> ASGIType:
|
61
|
+
return Starlette()
|
62
|
+
|
63
|
+
engin = ASGIEngin(Invoke(a), Invoke(b), Provide(asgi_type))
|
64
|
+
|
65
|
+
await asyncio.wait_for(engin.start(), timeout=0.5)
|
66
|
+
assert not B_LIFECYCLE_STATE
|
67
|
+
|
68
|
+
# check we can shutdown the app
|
69
|
+
await asyncio.wait_for(engin.stop(), timeout=0.5)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import asyncio
|
2
|
+
|
3
|
+
import pytest
|
4
|
+
|
5
|
+
from engin import Engin, Invoke, Provide
|
6
|
+
from engin.exceptions import ProviderError
|
7
|
+
|
8
|
+
|
9
|
+
async def test_error_in_provider_when_run():
|
10
|
+
async def raise_value_error() -> int:
|
11
|
+
raise ValueError("foo")
|
12
|
+
|
13
|
+
async def main(foo: int) -> None:
|
14
|
+
return
|
15
|
+
|
16
|
+
engin = Engin(Provide(raise_value_error), Invoke(main))
|
17
|
+
|
18
|
+
with pytest.raises(ProviderError, match="foo"):
|
19
|
+
await asyncio.wait_for(engin.run(), timeout=0.5)
|
20
|
+
|
21
|
+
|
22
|
+
async def test_error_in_provider_when_start():
|
23
|
+
async def raise_value_error() -> int:
|
24
|
+
raise ValueError("foo")
|
25
|
+
|
26
|
+
async def main(foo: int) -> None:
|
27
|
+
return
|
28
|
+
|
29
|
+
engin = Engin(Provide(raise_value_error), Invoke(main))
|
30
|
+
|
31
|
+
with pytest.raises(ProviderError, match="foo"):
|
32
|
+
await asyncio.wait_for(engin.start(), timeout=0.5)
|
33
|
+
|
34
|
+
# check we can shutdown the app
|
35
|
+
await asyncio.wait_for(engin.stop(), timeout=0.5)
|
@@ -15,7 +15,7 @@ def supervise(supervisor: Supervisor) -> None:
|
|
15
15
|
async def test_error_in_supervised_task_handled_when_run(caplog):
|
16
16
|
caplog.set_level(logging.INFO)
|
17
17
|
engin = Engin(Invoke(supervise))
|
18
|
-
await engin.run()
|
18
|
+
await asyncio.wait_for(engin.run(), timeout=0.5)
|
19
19
|
assert "Process errored" in caplog.text
|
20
20
|
assert engin.is_stopped()
|
21
21
|
|
@@ -23,7 +23,7 @@ async def test_error_in_supervised_task_handled_when_run(caplog):
|
|
23
23
|
async def test_error_in_supervised_task_handled_when_start(caplog):
|
24
24
|
caplog.set_level(logging.INFO)
|
25
25
|
engin = Engin(Invoke(supervise))
|
26
|
-
await engin.start()
|
26
|
+
await asyncio.wait_for(engin.start(), timeout=0.5)
|
27
27
|
await asyncio.sleep(0.1)
|
28
28
|
assert "Process errored" in caplog.text
|
29
29
|
assert engin.is_stopped()
|
@@ -3,10 +3,7 @@ from collections.abc import Iterable
|
|
3
3
|
from contextlib import asynccontextmanager
|
4
4
|
from datetime import datetime
|
5
5
|
|
6
|
-
import pytest
|
7
|
-
|
8
6
|
from engin import Engin, Entrypoint, Invoke, Lifecycle, Provide
|
9
|
-
from engin.exceptions import ProviderError
|
10
7
|
from tests.deps import ABlock
|
11
8
|
|
12
9
|
|
@@ -62,19 +59,6 @@ async def test_engin_with_block():
|
|
62
59
|
await engin.stop()
|
63
60
|
|
64
61
|
|
65
|
-
async def test_engin_error_handling():
|
66
|
-
async def raise_value_error() -> int:
|
67
|
-
raise ValueError("foo")
|
68
|
-
|
69
|
-
async def main(foo: int) -> None:
|
70
|
-
return
|
71
|
-
|
72
|
-
engin = Engin(Provide(raise_value_error), Invoke(main))
|
73
|
-
|
74
|
-
with pytest.raises(ProviderError, match="foo"):
|
75
|
-
await engin.run()
|
76
|
-
|
77
|
-
|
78
62
|
async def test_engin_with_entrypoint():
|
79
63
|
provider_called = False
|
80
64
|
|
@@ -211,7 +211,7 @@ toml = [
|
|
211
211
|
|
212
212
|
[[package]]
|
213
213
|
name = "engin"
|
214
|
-
version = "0.1.
|
214
|
+
version = "0.1.0b5"
|
215
215
|
source = { editable = "." }
|
216
216
|
dependencies = [
|
217
217
|
{ name = "anyio" },
|
@@ -293,16 +293,16 @@ wheels = [
|
|
293
293
|
|
294
294
|
[[package]]
|
295
295
|
name = "fastapi"
|
296
|
-
version = "0.
|
296
|
+
version = "0.116.0"
|
297
297
|
source = { registry = "https://pypi.org/simple" }
|
298
298
|
dependencies = [
|
299
299
|
{ name = "pydantic" },
|
300
300
|
{ name = "starlette" },
|
301
301
|
{ name = "typing-extensions" },
|
302
302
|
]
|
303
|
-
sdist = { url = "https://files.pythonhosted.org/packages/
|
303
|
+
sdist = { url = "https://files.pythonhosted.org/packages/20/38/e1da78736143fd885c36213a3ccc493c384ae8fea6a0f0bc272ef42ebea8/fastapi-0.116.0.tar.gz", hash = "sha256:80dc0794627af0390353a6d1171618276616310d37d24faba6648398e57d687a", size = 296518, upload-time = "2025-07-07T15:09:27.82Z" }
|
304
304
|
wheels = [
|
305
|
-
{ url = "https://files.pythonhosted.org/packages/
|
305
|
+
{ url = "https://files.pythonhosted.org/packages/2f/68/d80347fe2360445b5f58cf290e588a4729746e7501080947e6cdae114b1f/fastapi-0.116.0-py3-none-any.whl", hash = "sha256:fdcc9ed272eaef038952923bef2b735c02372402d1203ee1210af4eea7a78d2b", size = 95625, upload-time = "2025-07-07T15:09:26.348Z" },
|
306
306
|
]
|
307
307
|
|
308
308
|
[[package]]
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
from asyncio import TaskGroup
|
3
|
-
|
4
|
-
from engin import Engin
|
5
|
-
from engin._engin import _EnginState
|
6
|
-
|
7
|
-
|
8
|
-
async def test_engin_signal_handling():
|
9
|
-
engin = Engin()
|
10
|
-
|
11
|
-
async with TaskGroup() as tg:
|
12
|
-
tg.create_task(engin.run())
|
13
|
-
# give it time to startup
|
14
|
-
await asyncio.sleep(0.1)
|
15
|
-
|
16
|
-
assert engin._state == _EnginState.RUNNING
|
17
|
-
|
18
|
-
# closest thing to emulating the actual signal with subprocesses
|
19
|
-
engin._stop_requested_event.set()
|
20
|
-
|
21
|
-
# give it time to shutdown
|
22
|
-
await asyncio.sleep(0.1)
|
23
|
-
|
24
|
-
assert engin._state == _EnginState.SHUTDOWN
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|