11from __future__ import annotations
22
33import json
4- from typing import Optional , cast
4+ from typing import Annotated , cast
55
6- import typer
76from anyio import create_memory_object_stream , create_task_group , run , sleep_forever
7+ from cyclopts import App , Parameter
88
99from .connect import connect_channel
1010from .kernel import Kernel
1111from .kernelspec import write_kernelspec
1212
1313
14- cli = typer . Typer ()
14+ app = App ()
1515
1616
17- @cli .command ()
17+ @app .command ()
1818def install (
19- mode : str = typer .Argument ("" , help = "Mode of the kernel to install." ),
20- cache_dir : Optional [str ] = typer .Option (
21- None , "-c" , help = "Path to the cache directory, if mode is 'cache'."
22- ),
23- ):
19+ mode : str = "" ,
20+ cache_dir : str | None = None ,
21+ ) -> None :
22+ """Install the kernel.
23+
24+ Args:
25+ mode: Mode of the kernel to install.
26+ cache_dir: Path to the cache directory, if mode is 'cache'.
27+ """
2428 kernel_name = "akernel"
2529 if mode :
2630 modes = mode .split ("-" )
@@ -31,20 +35,27 @@ def install(
3135 write_kernelspec (kernel_name , mode , display_name , cache_dir )
3236
3337
34- @cli .command ()
38+ @app .command ()
3539def launch (
36- mode : str = typer .Argument ("" , help = "Mode of the kernel to launch." ),
37- cache_dir : Optional [str ] = typer .Option (
38- None , "-c" , help = "Path to the cache directory, if mode is 'cache'."
39- ),
40- connection_file : str = typer .Option (..., "-f" , help = "Path to the connection file." ),
40+ connection_file : Annotated [str , Parameter (alias = ["-f" ])],
41+ mode : str = "" ,
42+ cache_dir : str | None = None ,
43+ execute_in_thread : bool = False ,
4144):
42- akernel = AKernel (mode , cache_dir , connection_file )
45+ """Launch the kernel.
46+
47+ Args:
48+ mode: Mode of the kernel to launch.
49+ cache_dir: Path to the cache directory, if mode is 'cache'.
50+ connection_file: Path to the connection file.
51+ execute_in_thread: Whether to run user code in a thread.
52+ """
53+ akernel = AKernel (mode , cache_dir , connection_file , execute_in_thread )
4354 run (akernel .start )
4455
4556
4657class AKernel :
47- def __init__ (self , mode , cache_dir , connection_file ):
58+ def __init__ (self , mode , cache_dir , connection_file , execute_in_thread ):
4859 self ._to_shell_send_stream , self ._to_shell_receive_stream = create_memory_object_stream [list [bytes ]]()
4960 self ._from_shell_send_stream , self ._from_shell_receive_stream = create_memory_object_stream [list [bytes ]]()
5061 self ._to_control_send_stream , self ._to_control_receive_stream = create_memory_object_stream [list [bytes ]]()
@@ -62,6 +73,7 @@ def __init__(self, mode, cache_dir, connection_file):
6273 self ._from_iopub_send_stream ,
6374 mode ,
6475 cache_dir ,
76+ execute_in_thread ,
6577 )
6678 with open (connection_file ) as f :
6779 connection_cfg = json .load (f )
@@ -136,4 +148,4 @@ async def from_iopub(self) -> None:
136148
137149
138150if __name__ == "__main__" :
139- cli ()
151+ app ()
0 commit comments