fps_akernel_task 0.1.7__tar.gz → 0.2.0__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.
@@ -0,0 +1,2 @@
1
+ __pycache__/
2
+ .ipynb_checkpoints/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fps_akernel_task
3
- Version: 0.1.7
3
+ Version: 0.2.0
4
4
  Summary: An FPS plugin for the kernel task API
5
5
  Project-URL: Homepage, https://github.com/davidbrochart/akernel
6
6
  Author-email: David Brochart <david.brochart@gmail.com>
@@ -8,7 +8,7 @@ License: MIT
8
8
  License-File: LICENSE
9
9
  Keywords: fastapi,jupyter,plugins,server
10
10
  Requires-Python: >=3.10
11
- Requires-Dist: akernel>=0.3.4
11
+ Requires-Dist: akernel>=0.4.0
12
12
  Requires-Dist: anyio
13
13
  Requires-Dist: jupyverse-api<0.16.0,>=0.15.0
14
14
  Description-Content-Type: text/markdown
@@ -16,3 +16,15 @@ Description-Content-Type: text/markdown
16
16
  # fps-akernel-task
17
17
 
18
18
  An FPS plugin for the kernel task API.
19
+
20
+ ## Development installation
21
+
22
+ Install both packages from the repository root, in the environment running Jupyverse:
23
+
24
+ ```bash
25
+ python -m pip install -e . -e plugins/akernel_task
26
+ ```
27
+
28
+ Installing only the plugin can resolve its `akernel` dependency from PyPI instead
29
+ of this checkout. While working on unreleased kernel API changes, the plugin and
30
+ kernel must come from the same checkout. Restart Jupyverse after reinstalling.
@@ -0,0 +1,15 @@
1
+ # fps-akernel-task
2
+
3
+ An FPS plugin for the kernel task API.
4
+
5
+ ## Development installation
6
+
7
+ Install both packages from the repository root, in the environment running Jupyverse:
8
+
9
+ ```bash
10
+ python -m pip install -e . -e plugins/akernel_task
11
+ ```
12
+
13
+ Installing only the plugin can resolve its `akernel` dependency from PyPI instead
14
+ of this checkout. While working on unreleased kernel API changes, the plugin and
15
+ kernel must come from the same checkout. Restart Jupyverse after reinstalling.
@@ -2,14 +2,15 @@ from __future__ import annotations
2
2
 
3
3
  from anyio import TASK_STATUS_IGNORED, create_task_group, sleep_forever
4
4
  from anyio.abc import TaskStatus
5
- from jupyverse_api.kernel import Kernel as _Kernel
5
+ from jupyverse_kernel import Kernel as _Kernel
6
6
 
7
7
  from akernel.kernel import Kernel
8
8
 
9
9
 
10
10
  class AKernelTask(_Kernel):
11
- def __init__(self, *args, **kwargs):
11
+ def __init__(self, *args, execute_in_thread: bool = False, **kwargs):
12
12
  super().__init__()
13
+ self.execute_in_thread = execute_in_thread
13
14
 
14
15
  async def start(self, *, task_status: TaskStatus[None] = TASK_STATUS_IGNORED) -> None:
15
16
  async with (
@@ -37,6 +38,7 @@ class AKernelTask(_Kernel):
37
38
  self._to_stdin_receive_stream,
38
39
  self._from_stdin_send_stream,
39
40
  self._from_iopub_send_stream,
41
+ execute_in_thread=self.execute_in_thread,
40
42
  )
41
43
  self.task_group.start_soon(self.kernel.start)
42
44
  task_status.started()
@@ -47,4 +49,4 @@ class AKernelTask(_Kernel):
47
49
  self.task_group.cancel_scope.cancel()
48
50
 
49
51
  async def interrupt(self) -> None:
50
- pass
52
+ self.kernel.interrupt()
@@ -0,0 +1,30 @@
1
+ from __future__ import annotations
2
+
3
+ from functools import partial
4
+
5
+ from fps import Module
6
+ from jupyverse_kernel import KernelFactory
7
+ from jupyverse_kernels import Kernels
8
+
9
+ from .akernel_task import AKernelTask
10
+ from .models import KernelConfig
11
+
12
+
13
+ class AKernelTaskModule(Module):
14
+ def __init__(self, *args, execute_in_thread: bool = False, **kwargs) -> None:
15
+ super().__init__(*args, **kwargs)
16
+ self.execute_in_thread = KernelConfig(execute_in_thread=execute_in_thread).execute_in_thread
17
+
18
+ async def prepare(self) -> None:
19
+ kernels = await self.get(Kernels)
20
+ kernels.register_kernel_factory(
21
+ "akernel", KernelFactory(partial(AKernelTask, execute_in_thread=self.execute_in_thread))
22
+ )
23
+
24
+
25
+ class AKernelThreadTaskModule(Module):
26
+ async def prepare(self) -> None:
27
+ kernels = await self.get(Kernels)
28
+ kernels.register_kernel_factory(
29
+ "akernel-thread", KernelFactory(partial(AKernelTask, execute_in_thread=True))
30
+ )
@@ -0,0 +1,5 @@
1
+ from pydantic import BaseModel
2
+
3
+
4
+ class KernelConfig(BaseModel):
5
+ execute_in_thread: bool
@@ -4,14 +4,14 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "fps_akernel_task"
7
- version = "0.1.7"
7
+ version = "0.2.0"
8
8
  description = "An FPS plugin for the kernel task API"
9
9
  keywords = ["jupyter", "server", "fastapi", "plugins"]
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
12
  "jupyverse-api >=0.15.0,<0.16.0",
13
13
  "anyio",
14
- "akernel >=0.3.4",
14
+ "akernel >=0.4.0",
15
15
  ]
16
16
 
17
17
  [[project.authors]]
@@ -29,5 +29,5 @@ text = "MIT"
29
29
  Homepage = "https://github.com/davidbrochart/akernel"
30
30
 
31
31
  [project.entry-points]
32
- "fps.modules" = {akernel_task = "fps_akernel_task.main:AKernelTaskModule"}
33
- "jupyverse.modules" = {akernel_task = "fps_akernel_task.main:AKernelTaskModule"}
32
+ "fps.modules" = {akernel_task = "fps_akernel_task.main:AKernelTaskModule", akernelthread_task = "fps_akernel_task.main:AKernelThreadTaskModule"}
33
+ "jupyverse.modules" = {akernel_task = "fps_akernel_task.main:AKernelTaskModule", akernelthread_task = "fps_akernel_task.main:AKernelThreadTaskModule"}
@@ -1,3 +0,0 @@
1
- # fps-akernel-task
2
-
3
- An FPS plugin for the kernel task API.
@@ -1,14 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from fps import Module
4
-
5
- from jupyverse_api.kernel import KernelFactory
6
- from jupyverse_api.kernels import Kernels
7
-
8
- from .akernel_task import AKernelTask
9
-
10
-
11
- class AKernelTaskModule(Module):
12
- async def prepare(self) -> None:
13
- kernels = await self.get(Kernels)
14
- kernels.register_kernel_factory("akernel", KernelFactory(AKernelTask))