async-kernel 0.16.0__tar.gz → 0.16.2__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.
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/workflows/ci.yml +2 -1
- {async_kernel-0.16.0 → async_kernel-0.16.2}/CHANGELOG.md +22 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/PKG-INFO +4 -1
- {async_kernel-0.16.0 → async_kernel-0.16.2}/README.md +2 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/_version.py +2 -2
- {async_kernel-0.16.0 → async_kernel-0.16.2}/pyproject.toml +2 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/asyncshell.py +69 -2
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/caller.py +1 -3
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/common.py +11 -10
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/kernel.py +8 -8
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/pending.py +9 -3
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/typing.py +11 -1
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_kernel.py +16 -1
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_typing.py +5 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/uv.lock +12 -1
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/dependabot.yaml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/release.yml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/workflows/enforce-label.yml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/workflows/new_release.yml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/workflows/pre-commit.yml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/workflows/publish-docs.yml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.github/workflows/publish-to-pypi.yml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.gitignore +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.pre-commit-config.yaml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.vscode/launch.json +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.vscode/settings.json +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/.vscode/spellright.dict +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/CONTRIBUTING.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/IPYTHON_LICENSE +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/LICENSE +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/cliff.toml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/about/changelog.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/about/contributing.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/about/index.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/about/license.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/index.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/javascripts/extra.js +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/notebooks/caller.ipynb +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/notebooks/concurrency.ipynb +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/overrides/main.html +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/asyncshell.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/caller.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/comm.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/command.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/common.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/debugger.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/event_loop.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/index.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/interface.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/kernel.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/kernelspec.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/pending.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/typing.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/reference/utils.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/stylesheets/extra.css +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/thread_safety.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/usage/commands.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/docs/usage/index.md +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/hatch_build.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/mkdocs.yml +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/__init__.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/__main__.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/comm.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/command.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/compat/json.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/compiler.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/debugger.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/event_loop/__init__.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/event_loop/asyncio_guest.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/event_loop/qt_host.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/event_loop/run.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/event_loop/tk_host.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/interface/__init__.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/interface/base.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/interface/callable.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/interface/zmq.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/iostream.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/kernelspec.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/py.typed +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/resources/logo-32x32.png +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/resources/logo-64x64.png +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/resources/logo-svg.svg +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/src/async_kernel/utils.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/__init__.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/conftest.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/references.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_callable_kernel_interface.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_caller.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_comm.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_command.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_common.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_compat.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_debugger.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_enter_kernel.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_event_loop.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_iostream.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_kernel_subclass.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_kernelspec.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_message_spec.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_pending.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_utils.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/test_zmq_messaging.py +0 -0
- {async_kernel-0.16.0 → async_kernel-0.16.2}/tests/utils.py +0 -0
|
@@ -39,6 +39,7 @@ jobs:
|
|
|
39
39
|
- "3.12"
|
|
40
40
|
- "3.13"
|
|
41
41
|
- "3.14t"
|
|
42
|
+
- "3.15"
|
|
42
43
|
steps:
|
|
43
44
|
- name: Checkout
|
|
44
45
|
uses: actions/checkout@v6
|
|
@@ -53,7 +54,7 @@ jobs:
|
|
|
53
54
|
- name: Install the project
|
|
54
55
|
run: uv sync --locked --dev
|
|
55
56
|
|
|
56
|
-
- if: ${{ startsWith(matrix.os, 'windows') && !endsWith(matrix.python-version, 't')}}
|
|
57
|
+
- if: ${{ startsWith(matrix.os, 'windows') && !endsWith(matrix.python-version, 't') && !startsWith(matrix.python-version, '3.15')}}
|
|
57
58
|
# Pyside does not have free-threaded binary
|
|
58
59
|
run: uv sync --locked --dev --group gui
|
|
59
60
|
|
|
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.16.2] - 2026-04-12
|
|
9
|
+
|
|
10
|
+
### <!-- 1 --> 🚀 Features
|
|
11
|
+
|
|
12
|
+
- Provide async line magic support [#424](https://github.com/fleming79/async-kernel/pull/424)
|
|
13
|
+
|
|
14
|
+
## [0.16.1] - 2026-04-08
|
|
15
|
+
|
|
16
|
+
### <!-- 1 --> 🚀 Features
|
|
17
|
+
|
|
18
|
+
- Add shield option to Pending.cancel_wait. [#421](https://github.com/fleming79/async-kernel/pull/421)
|
|
19
|
+
|
|
20
|
+
### <!-- 6 --> 🌀 Miscellaneous
|
|
21
|
+
|
|
22
|
+
- Prepare for release v0.16.1 [#423](https://github.com/fleming79/async-kernel/pull/423)
|
|
23
|
+
|
|
24
|
+
- Test against Python 3.15 [#422](https://github.com/fleming79/async-kernel/pull/422)
|
|
25
|
+
|
|
8
26
|
## [0.16.0] - 2026-04-06
|
|
9
27
|
|
|
10
28
|
### <!-- 0 --> 🏗️ Breaking changes
|
|
@@ -27,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
27
45
|
|
|
28
46
|
### <!-- 6 --> 🌀 Miscellaneous
|
|
29
47
|
|
|
48
|
+
- Prepare for release v0.16.0 [#420](https://github.com/fleming79/async-kernel/pull/420)
|
|
49
|
+
|
|
30
50
|
- Caller refactoring [#419](https://github.com/fleming79/async-kernel/pull/419)
|
|
31
51
|
|
|
32
52
|
- Convert Caller._get_task_factory to a function [#416](https://github.com/fleming79/async-kernel/pull/416)
|
|
@@ -1145,6 +1165,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
1145
1165
|
|
|
1146
1166
|
- Bump the actions group across 1 directory with 2 updates [#3](https://github.com/fleming79/async-kernel/pull/3)
|
|
1147
1167
|
|
|
1168
|
+
[0.16.2]: https://github.com/fleming79/async-kernel/compare/v0.16.1..v0.16.2
|
|
1169
|
+
[0.16.1]: https://github.com/fleming79/async-kernel/compare/v0.16.0..v0.16.1
|
|
1148
1170
|
[0.16.0]: https://github.com/fleming79/async-kernel/compare/v0.15.0..v0.16.0
|
|
1149
1171
|
[0.15.0]: https://github.com/fleming79/async-kernel/compare/v0.14.0..v0.15.0
|
|
1150
1172
|
[0.14.0]: https://github.com/fleming79/async-kernel/compare/v0.13.3..v0.14.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: async-kernel
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.2
|
|
4
4
|
Summary: A concurrent python kernel for Jupyter supporting AnyIO, AsyncIO and Trio.
|
|
5
5
|
Project-URL: Homepage, https://fleming79.github.io/async-kernel
|
|
6
6
|
Project-URL: Documentation, https://fleming79.github.io/async-kernel
|
|
@@ -29,6 +29,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
29
29
|
Classifier: Programming Language :: Python :: 3.12
|
|
30
30
|
Classifier: Programming Language :: Python :: 3.13
|
|
31
31
|
Classifier: Programming Language :: Python :: 3.14
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
32
33
|
Classifier: Programming Language :: Python :: Free Threading :: 1 - Unstable
|
|
33
34
|
Classifier: Typing :: Typed
|
|
34
35
|
Requires-Python: >=3.11
|
|
@@ -73,6 +74,7 @@ The kernel provides two external interfaces:
|
|
|
73
74
|
|
|
74
75
|
- [IPython shell](https://ipython.readthedocs.io/en/stable/overview.html#enhanced-interactive-python-shell)
|
|
75
76
|
- top-level await ('asyncio' or 'trio' backend) in cells
|
|
77
|
+
- async magic function support in cells
|
|
76
78
|
- [anyio](https://pypi.org/project/anyio/) compatible asynchronous backend ([`asyncio`](https://docs.python.org/3/library/asyncio.html) (default) or [`trio`](https://pypi.org/project/trio/))
|
|
77
79
|
- [aiologic](https://aiologic.readthedocs.io/latest/) thread-safe synchronisation primitives
|
|
78
80
|
- [Backend agnostic multi-thread / multi-event loop management](https://fleming79.github.io/async-kernel/latest/reference/caller/#async_kernel.caller.Caller)
|
|
@@ -84,6 +86,7 @@ The kernel provides two external interfaces:
|
|
|
84
86
|
- [x] qt host and asyncio[^2] or trio[^3] backend running as a guest
|
|
85
87
|
- [Experimental](https://github.com/fleming79/echo-kernel) support for
|
|
86
88
|
[Jupyterlite](https://github.com/jupyterlite/jupyterlite) (try it online [here](https://fleming79.github.io/echo-kernel/) 👈)
|
|
89
|
+
- `%pip install` magic (using micropip)
|
|
87
90
|
- [Debugger client](https://jupyterlab.readthedocs.io/en/latest/user/debugger.html#debugger)
|
|
88
91
|
|
|
89
92
|
[^1]:
|
|
@@ -23,6 +23,7 @@ The kernel provides two external interfaces:
|
|
|
23
23
|
|
|
24
24
|
- [IPython shell](https://ipython.readthedocs.io/en/stable/overview.html#enhanced-interactive-python-shell)
|
|
25
25
|
- top-level await ('asyncio' or 'trio' backend) in cells
|
|
26
|
+
- async magic function support in cells
|
|
26
27
|
- [anyio](https://pypi.org/project/anyio/) compatible asynchronous backend ([`asyncio`](https://docs.python.org/3/library/asyncio.html) (default) or [`trio`](https://pypi.org/project/trio/))
|
|
27
28
|
- [aiologic](https://aiologic.readthedocs.io/latest/) thread-safe synchronisation primitives
|
|
28
29
|
- [Backend agnostic multi-thread / multi-event loop management](https://fleming79.github.io/async-kernel/latest/reference/caller/#async_kernel.caller.Caller)
|
|
@@ -34,6 +35,7 @@ The kernel provides two external interfaces:
|
|
|
34
35
|
- [x] qt host and asyncio[^2] or trio[^3] backend running as a guest
|
|
35
36
|
- [Experimental](https://github.com/fleming79/echo-kernel) support for
|
|
36
37
|
[Jupyterlite](https://github.com/jupyterlite/jupyterlite) (try it online [here](https://fleming79.github.io/echo-kernel/) 👈)
|
|
38
|
+
- `%pip install` magic (using micropip)
|
|
37
39
|
- [Debugger client](https://jupyterlab.readthedocs.io/en/latest/user/debugger.html#debugger)
|
|
38
40
|
|
|
39
41
|
[^1]:
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.16.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 16,
|
|
21
|
+
__version__ = version = '0.16.2'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 16, 2)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -31,6 +31,7 @@ classifiers = [
|
|
|
31
31
|
"Programming Language :: Python :: 3.12",
|
|
32
32
|
"Programming Language :: Python :: 3.13",
|
|
33
33
|
"Programming Language :: Python :: 3.14",
|
|
34
|
+
"Programming Language :: Python :: 3.15",
|
|
34
35
|
"Programming Language :: Python :: Free Threading :: 1 - Unstable",
|
|
35
36
|
]
|
|
36
37
|
requires-python = ">=3.11"
|
|
@@ -92,6 +93,7 @@ uvloop = ["uvloop; python_version <= '3.13' and sys_platform != 'win32' and impl
|
|
|
92
93
|
dev = [
|
|
93
94
|
"debugpy",
|
|
94
95
|
"ipykernel; implementation_name == 'cpython'",
|
|
96
|
+
"pip; implementation_name == 'cpython'",
|
|
95
97
|
{include-group = "uvloop"},
|
|
96
98
|
{include-group = "test"},
|
|
97
99
|
]
|
|
@@ -8,7 +8,7 @@ import pathlib
|
|
|
8
8
|
import sys
|
|
9
9
|
import time
|
|
10
10
|
from collections.abc import Callable
|
|
11
|
-
from typing import TYPE_CHECKING, Any, Literal, Self, overload
|
|
11
|
+
from typing import TYPE_CHECKING, Any, Literal, Self, TextIO, overload
|
|
12
12
|
|
|
13
13
|
import anyio
|
|
14
14
|
import IPython.core.release
|
|
@@ -37,6 +37,7 @@ from async_kernel.typing import Channel, Content, Message, NoValue, Tags
|
|
|
37
37
|
if TYPE_CHECKING:
|
|
38
38
|
from collections.abc import Callable, Generator
|
|
39
39
|
|
|
40
|
+
from anyio.abc import ByteReceiveStream
|
|
40
41
|
from traitlets.config import Configurable
|
|
41
42
|
|
|
42
43
|
from async_kernel import Kernel
|
|
@@ -45,6 +46,13 @@ if TYPE_CHECKING:
|
|
|
45
46
|
__all__ = ["AsyncInteractiveShell"]
|
|
46
47
|
|
|
47
48
|
|
|
49
|
+
async def _forward_transport_stream(transport_stream: ByteReceiveStream, out: TextIO, /) -> None:
|
|
50
|
+
from anyio.streams.text import TextReceiveStream # noqa: PLC0415
|
|
51
|
+
|
|
52
|
+
async for text in TextReceiveStream(transport_stream):
|
|
53
|
+
out.write(text)
|
|
54
|
+
|
|
55
|
+
|
|
48
56
|
class AsyncDisplayHook(DisplayHook):
|
|
49
57
|
"""
|
|
50
58
|
A displayhook subclass that publishes data using [iopub_send][async_kernel.kernel.Kernel.iopub_send].
|
|
@@ -168,6 +176,7 @@ class AsyncInteractiveShell(InteractiveShell):
|
|
|
168
176
|
Notable differences:
|
|
169
177
|
- Supports a soft timeout specified via tags `timeout=<value in seconds>`[^1].
|
|
170
178
|
- `user_ns` and `user_global_ns` are same dictionary which is a fixed [dict][].
|
|
179
|
+
- Supports async magic functions (See [KernelMagics.pip][]).
|
|
171
180
|
|
|
172
181
|
[^1]: When the execution time exceeds the timeout value, the code execution will "move on".
|
|
173
182
|
"""
|
|
@@ -320,6 +329,14 @@ class AsyncInteractiveShell(InteractiveShell):
|
|
|
320
329
|
def ns_table(self) -> dict[str, dict[Any, Any] | dict[str, Any]]:
|
|
321
330
|
return {"user_global": self.user_global_ns, "user_local": self.user_ns, "builtin": builtins.__dict__}
|
|
322
331
|
|
|
332
|
+
async def run_line_magic_async(self, magic_name: str, line: str, _stack_depth=1) -> Any:
|
|
333
|
+
"Call and awaits [run_line_magic][IPython.core.interactiveshell.InteractiveShell.run_line_magic]."
|
|
334
|
+
result = self.run_line_magic(magic_name, line, _stack_depth)
|
|
335
|
+
try:
|
|
336
|
+
return await result # pyright: ignore[reportGeneralTypeIssues]
|
|
337
|
+
except TypeError:
|
|
338
|
+
return result
|
|
339
|
+
|
|
323
340
|
async def _execute_request(
|
|
324
341
|
self,
|
|
325
342
|
code: str = "",
|
|
@@ -378,7 +395,9 @@ class AsyncInteractiveShell(InteractiveShell):
|
|
|
378
395
|
raw_cell=code,
|
|
379
396
|
store_history=store_history,
|
|
380
397
|
silent=silent,
|
|
381
|
-
transformed_cell=self.transform_cell(code)
|
|
398
|
+
transformed_cell=self.transform_cell(code).replace(
|
|
399
|
+
"get_ipython().run_line_magic(", "await get_ipython().run_line_magic_async("
|
|
400
|
+
),
|
|
382
401
|
shell_futures=True,
|
|
383
402
|
cell_id=cell_id,
|
|
384
403
|
)
|
|
@@ -774,5 +793,53 @@ class KernelMagics(Magics):
|
|
|
774
793
|
)
|
|
775
794
|
print(f"Current shell:\t{self.shell}\n\n{subshell_list}")
|
|
776
795
|
|
|
796
|
+
@line_magic
|
|
797
|
+
async def pip(self, line: str) -> Any | None:
|
|
798
|
+
"""Run the pip package manager for the current environment.
|
|
799
|
+
|
|
800
|
+
Usage:
|
|
801
|
+
%pip install [pkgs]
|
|
802
|
+
"""
|
|
803
|
+
if sys.platform == "emscripten":
|
|
804
|
+
import micropip # noqa: PLC0415
|
|
805
|
+
|
|
806
|
+
match line.split(maxsplit=1)[0]:
|
|
807
|
+
case "install":
|
|
808
|
+
requirements = [
|
|
809
|
+
f"emfs:{n}" if n.startswith(".") else n for n in line.removeprefix("install").split()
|
|
810
|
+
]
|
|
811
|
+
return await micropip.install(requirements, verbose=True)
|
|
812
|
+
case "uninstall":
|
|
813
|
+
return micropip.uninstall(line.removeprefix("uninstall").split(), verbose=True)
|
|
814
|
+
case "freeze":
|
|
815
|
+
return micropip.freeze()
|
|
816
|
+
case "list":
|
|
817
|
+
return micropip.list()
|
|
818
|
+
case _ as name:
|
|
819
|
+
print("Unsupported command:", name)
|
|
820
|
+
else:
|
|
821
|
+
cmd = [sys.executable, "-m", "pip", *line.split()]
|
|
822
|
+
async with await anyio.open_process(cmd) as process, anyio.create_task_group() as tg:
|
|
823
|
+
if process.stdout:
|
|
824
|
+
tg.start_soon(_forward_transport_stream, process.stdout, sys.stdout)
|
|
825
|
+
if process.stderr:
|
|
826
|
+
tg.start_soon(_forward_transport_stream, process.stderr, sys.stderr)
|
|
827
|
+
|
|
828
|
+
return None
|
|
829
|
+
|
|
830
|
+
@line_magic
|
|
831
|
+
async def uv(self, line) -> None:
|
|
832
|
+
"""Run the uv package manager for the current environment.
|
|
833
|
+
|
|
834
|
+
Usage:
|
|
835
|
+
%uv pip install [pkgs]
|
|
836
|
+
"""
|
|
837
|
+
cmd = ["uv", *line.split()]
|
|
838
|
+
async with await anyio.open_process(cmd) as process, anyio.create_task_group() as tg:
|
|
839
|
+
if process.stdout:
|
|
840
|
+
tg.start_soon(_forward_transport_stream, process.stdout, sys.stdout)
|
|
841
|
+
if process.stderr:
|
|
842
|
+
tg.start_soon(_forward_transport_stream, process.stderr, sys.stdout)
|
|
843
|
+
|
|
777
844
|
|
|
778
845
|
InteractiveShellABC.register(AsyncInteractiveShell)
|
|
@@ -1042,13 +1042,11 @@ class Caller(anyio.AsyncContextManagerMixin):
|
|
|
1042
1042
|
pen_.result()
|
|
1043
1043
|
finally:
|
|
1044
1044
|
queue.stop()
|
|
1045
|
-
pen_.cancel()
|
|
1046
1045
|
for pen in unfinished:
|
|
1047
1046
|
pen.remove_done_callback(queue.append)
|
|
1048
1047
|
if cancel_unfinished:
|
|
1049
1048
|
pen.cancel("Cancelled by as_completed")
|
|
1050
|
-
|
|
1051
|
-
await pen_.wait(result=False)
|
|
1049
|
+
await pen_.cancel_wait(shield=True)
|
|
1052
1050
|
|
|
1053
1051
|
async def wait(
|
|
1054
1052
|
self,
|
|
@@ -202,16 +202,17 @@ class SingleAsyncQueue(Generic[T]):
|
|
|
202
202
|
queue = self.queue
|
|
203
203
|
try:
|
|
204
204
|
while self._active:
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
205
|
+
if queue:
|
|
206
|
+
yield queue.popleft()
|
|
207
|
+
await checkpoint()
|
|
208
|
+
else:
|
|
209
|
+
event = create_async_event()
|
|
210
|
+
self._resume = event.set
|
|
211
|
+
if not queue and self._active:
|
|
212
|
+
await event
|
|
213
|
+
self._resume = noop
|
|
214
|
+
except IndexError:
|
|
215
|
+
pass
|
|
215
216
|
finally:
|
|
216
217
|
self._resume = noop
|
|
217
218
|
self.stop()
|
|
@@ -505,16 +505,16 @@ class Kernel(traitlets.HasTraits, anyio.AsyncContextManagerMixin):
|
|
|
505
505
|
# return RunMode(run_mode)
|
|
506
506
|
if msg_type is MsgType.execute_request:
|
|
507
507
|
if content := job["msg"].get("content", {}):
|
|
508
|
-
if code := content.get("code")
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
except ValueError:
|
|
513
|
-
pass
|
|
508
|
+
if (code := content.get("code")) and (
|
|
509
|
+
mode := RunMode.to_runmode(code.strip().split("\n", maxsplit=1)[0])
|
|
510
|
+
):
|
|
511
|
+
return mode
|
|
514
512
|
if content.get("silent"):
|
|
515
513
|
return RunMode.task
|
|
516
|
-
|
|
517
|
-
return
|
|
514
|
+
try:
|
|
515
|
+
return next(mode for tag in utils.get_tags(job) if (mode := RunMode.to_runmode(tag)))
|
|
516
|
+
except Exception:
|
|
517
|
+
pass
|
|
518
518
|
return RunMode.queue
|
|
519
519
|
|
|
520
520
|
async def kernel_info_request(self, job: Job[Content], /) -> Content:
|
|
@@ -612,12 +612,18 @@ class Pending(Awaitable[T]):
|
|
|
612
612
|
canceller(msg)
|
|
613
613
|
return self._cancelled is not None
|
|
614
614
|
|
|
615
|
-
async def cancel_wait(self, msg: str | None, *, timeout: float | None = None) -> None:
|
|
616
|
-
"
|
|
615
|
+
async def cancel_wait(self, msg: str | None = None, *, timeout: float | None = None, shield: bool = False) -> None:
|
|
616
|
+
"""
|
|
617
|
+
Cancel the pending and wait for it to be done.
|
|
618
|
+
|
|
619
|
+
Args:
|
|
620
|
+
timeout: Timeout in seconds.
|
|
621
|
+
shield: Shield from external cancellation.
|
|
622
|
+
"""
|
|
617
623
|
if not self._done:
|
|
618
624
|
self.cancel(msg)
|
|
619
625
|
if not self._done:
|
|
620
|
-
await self.wait(result=False, timeout=timeout)
|
|
626
|
+
await self.wait(result=False, timeout=timeout, shield=shield)
|
|
621
627
|
|
|
622
628
|
def cancelled(self) -> bool:
|
|
623
629
|
"""
|
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import enum
|
|
4
4
|
from collections.abc import Awaitable, Callable
|
|
5
|
-
from typing import TYPE_CHECKING, Any, Generic, Literal, NotRequired, ParamSpec, TypedDict, TypeVar
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Generic, Literal, NotRequired, ParamSpec, Self, TypedDict, TypeVar
|
|
6
6
|
|
|
7
7
|
from typing_extensions import Sentinel, override
|
|
8
8
|
|
|
@@ -113,6 +113,16 @@ class RunMode(enum.StrEnum):
|
|
|
113
113
|
def __hash__(self) -> int:
|
|
114
114
|
return hash(self.name)
|
|
115
115
|
|
|
116
|
+
@classmethod
|
|
117
|
+
def to_runmode(cls, value: Any, default: T = None, /) -> Self | T:
|
|
118
|
+
"Converts value to `Runmode` or default where it is not possible."
|
|
119
|
+
try:
|
|
120
|
+
return cls(value)
|
|
121
|
+
except ValueError:
|
|
122
|
+
if isinstance(value, str) and value.startswith(("# ", "##")):
|
|
123
|
+
return cls.to_runmode(value[2:], default)
|
|
124
|
+
return default
|
|
125
|
+
|
|
116
126
|
queue = "queue"
|
|
117
127
|
"Run the message handler using [async_kernel.caller.Caller.queue_call][]."
|
|
118
128
|
|
|
@@ -420,7 +420,16 @@ async def test_debug_static_richInspectVariables(client: AsyncKernelClient, vari
|
|
|
420
420
|
assert reply["content"]["status"] == "ok"
|
|
421
421
|
|
|
422
422
|
|
|
423
|
-
@pytest.mark.parametrize(
|
|
423
|
+
@pytest.mark.parametrize(
|
|
424
|
+
"code",
|
|
425
|
+
argvalues=[
|
|
426
|
+
"%connect_info",
|
|
427
|
+
"%callers",
|
|
428
|
+
"%subshell",
|
|
429
|
+
"%pip install anyio",
|
|
430
|
+
"%uv pip install anyio",
|
|
431
|
+
],
|
|
432
|
+
)
|
|
424
433
|
async def test_magic(client: AsyncKernelClient, code: str, kernel: Kernel, monkeypatch):
|
|
425
434
|
await utils.clear_iopub(client)
|
|
426
435
|
monkeypatch.setenv("JUPYTER_RUNTIME_DIR", str(pathlib.Path(kernel.connection_file).parent))
|
|
@@ -431,6 +440,12 @@ async def test_magic(client: AsyncKernelClient, code: str, kernel: Kernel, monke
|
|
|
431
440
|
assert stdout
|
|
432
441
|
|
|
433
442
|
|
|
443
|
+
@pytest.mark.parametrize("code", argvalues=["%connect_info"])
|
|
444
|
+
async def test_magic_sync(client: AsyncKernelClient, code: str, kernel: Kernel, monkeypatch):
|
|
445
|
+
result = kernel.main_shell.run_cell(code)
|
|
446
|
+
assert result.success
|
|
447
|
+
|
|
448
|
+
|
|
434
449
|
async def test_shell_enable_gui(kernel: Kernel):
|
|
435
450
|
# used by ipython AutoMagicChecker via is_shadowed (requires 'builitin')
|
|
436
451
|
assert set(kernel.shell.ns_table) == {"user_global", "user_local", "builtin"}
|
|
@@ -17,6 +17,11 @@ class TestRunMode:
|
|
|
17
17
|
assert list(RunMode) == ["# queue", "# task", "# thread"]
|
|
18
18
|
assert list(RunMode) == ["<RunMode.queue: 'queue'>", "<RunMode.task: 'task'>", "<RunMode.thread: 'thread'>"]
|
|
19
19
|
|
|
20
|
+
def test_is_runmode(self):
|
|
21
|
+
assert RunMode.to_runmode("# thread") is RunMode.thread
|
|
22
|
+
assert not RunMode.to_runmode(1)
|
|
23
|
+
assert RunMode.to_runmode(1, RunMode.queue) is RunMode.queue
|
|
24
|
+
|
|
20
25
|
|
|
21
26
|
class TestMsgType:
|
|
22
27
|
def test_all_names(self):
|
|
@@ -139,6 +139,7 @@ dependencies = [
|
|
|
139
139
|
dev = [
|
|
140
140
|
{ name = "debugpy" },
|
|
141
141
|
{ name = "ipykernel", marker = "implementation_name == 'cpython'" },
|
|
142
|
+
{ name = "pip", marker = "implementation_name == 'cpython'" },
|
|
142
143
|
{ name = "pytest" },
|
|
143
144
|
{ name = "pytest-cov" },
|
|
144
145
|
{ name = "pytest-mock" },
|
|
@@ -212,6 +213,7 @@ requires-dist = [
|
|
|
212
213
|
dev = [
|
|
213
214
|
{ name = "debugpy" },
|
|
214
215
|
{ name = "ipykernel", marker = "implementation_name == 'cpython'" },
|
|
216
|
+
{ name = "pip", marker = "implementation_name == 'cpython'" },
|
|
215
217
|
{ name = "pytest", specifier = ">=8.4,<9" },
|
|
216
218
|
{ name = "pytest-cov", specifier = ">=7.0.0" },
|
|
217
219
|
{ name = "pytest-mock" },
|
|
@@ -2126,7 +2128,7 @@ name = "pexpect"
|
|
|
2126
2128
|
version = "4.9.0"
|
|
2127
2129
|
source = { registry = "https://pypi.org/simple" }
|
|
2128
2130
|
dependencies = [
|
|
2129
|
-
{ name = "ptyprocess" },
|
|
2131
|
+
{ name = "ptyprocess", marker = "sys_platform != 'emscripten' and sys_platform != 'win32'" },
|
|
2130
2132
|
]
|
|
2131
2133
|
sdist = { url = "https://files.pythonhosted.org/packages/42/92/cc564bf6381ff43ce1f4d06852fc19a2f11d180f23dc32d9588bee2f149d/pexpect-4.9.0.tar.gz", hash = "sha256:ee7d41123f3c9911050ea2c2dac107568dc43b2d3b0c7557a33212c398ead30f", size = 166450, upload-time = "2023-11-25T09:07:26.339Z" }
|
|
2132
2134
|
wheels = [
|
|
@@ -2220,6 +2222,15 @@ wheels = [
|
|
|
2220
2222
|
{ url = "https://files.pythonhosted.org/packages/bc/60/5382c03e1970de634027cee8e1b7d39776b778b81812aaf45b694dfe9e28/pillow-12.2.0-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:bfa9c230d2fe991bed5318a5f119bd6780cda2915cca595393649fc118ab895e", size = 7080946, upload-time = "2026-04-01T14:46:11.734Z" },
|
|
2221
2223
|
]
|
|
2222
2224
|
|
|
2225
|
+
[[package]]
|
|
2226
|
+
name = "pip"
|
|
2227
|
+
version = "26.0.1"
|
|
2228
|
+
source = { registry = "https://pypi.org/simple" }
|
|
2229
|
+
sdist = { url = "https://files.pythonhosted.org/packages/48/83/0d7d4e9efe3344b8e2fe25d93be44f64b65364d3c8d7bc6dc90198d5422e/pip-26.0.1.tar.gz", hash = "sha256:c4037d8a277c89b320abe636d59f91e6d0922d08a05b60e85e53b296613346d8", size = 1812747, upload-time = "2026-02-05T02:20:18.702Z" }
|
|
2230
|
+
wheels = [
|
|
2231
|
+
{ url = "https://files.pythonhosted.org/packages/de/f0/c81e05b613866b76d2d1066490adf1a3dbc4ee9d9c839961c3fc8a6997af/pip-26.0.1-py3-none-any.whl", hash = "sha256:bdb1b08f4274833d62c1aa29e20907365a2ceb950410df15fc9521bad440122b", size = 1787723, upload-time = "2026-02-05T02:20:16.416Z" },
|
|
2232
|
+
]
|
|
2233
|
+
|
|
2223
2234
|
[[package]]
|
|
2224
2235
|
name = "platformdirs"
|
|
2225
2236
|
version = "4.9.4"
|
|
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
|