Skip to content

Commit 36368c7

Browse files
authored
chore: konsole (#9)
1 parent fcfd84c commit 36368c7

File tree

5 files changed

+63
-45
lines changed

5 files changed

+63
-45
lines changed

README.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,38 @@ pip install jupyter_kernel_client
3232

3333
### Kernel Client
3434

35-
1. Start a jupyter server (or JupyterLab or Jupyter Notebook)
35+
1. Start a Jupyter Server (or JupyterLab or Jupyter Notebook)
3636

3737
```sh
3838
jupyter server
39+
# ...
40+
# To access the server, open this file in a browser:
41+
# file:///home/echarles/.local/share/jupyter/runtime/jpserver-910631-open.html
42+
# Or copy and paste one of these URLs:
43+
# http://localhost:8888/?token=aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b
44+
# http://127.0.0.1:8888/?token=aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b
3945
```
4046

41-
2. Note down the URL (usually `http://localhost:8888`) and the server token
47+
2. Note down the URL (usually `http://localhost:8888`) and the Server Token (in the above example it will be `aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b`)
4248

43-
3. Open a Python terminal
49+
3. Launch `python` in a terminal.
4450

4551
4. Execute the following snippet
4652

4753
```py
4854
import os
55+
4956
from platform import node
5057
from jupyter_kernel_client import KernelClient
5158

52-
with KernelClient(server_url="http://localhost:8888", token="...") as kernel:
59+
60+
with KernelClient(server_url="http://localhost:8888", token="aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b") as kernel:
5361
reply = kernel.execute(
5462
"""import os
5563
from platform import node
5664
print(f"Hey {os.environ.get('USER', 'John Smith')} from {node()}.")
5765
"""
5866
)
59-
6067
assert reply["execution_count"] == 1
6168
assert reply["outputs"] == [
6269
{
@@ -72,31 +79,37 @@ print(f"Hey {os.environ.get('USER', 'John Smith')} from {node()}.")
7279

7380
This package can be used to open a Jupyter Console to a Jupyter Kernel through HTTP 🐣.
7481

75-
1. Install the optional dependencies:
82+
1. Install the optional dependencies.
7683

7784
```sh
78-
pip install jupyter-kernel-client[console]
85+
pip install jupyter-kernel-client[konsole]
7986
```
8087

81-
82-
2. Start a jupyter server (or JupyterLab or Jupyter Notebook)
88+
2. Start a Jupyter Server (or JupyterLab or Jupyter Notebook).
8389

8490
```sh
8591
jupyter server
92+
# ...
93+
# To access the server, open this file in a browser:
94+
# file:///home/echarles/.local/share/jupyter/runtime/jpserver-910631-open.html
95+
# Or copy and paste one of these URLs:
96+
# http://localhost:8888/?token=aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b
97+
# http://127.0.0.1:8888/?token=aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b
8698
```
8799

88-
3. Note down the URL (usually `http://localhost:8888`) and the server token
89-
4. Start the console
100+
3. Note down the URL (usually `http://localhost:8888`) and the Server Token (in the above example it will be `aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b`)
101+
102+
4. Start the console.
90103

91104
```sh
92-
jupyter-connect --url http://localhost:8888 --token abcdef...
105+
jupyter-konsole --url http://localhost:8888 --token aed1fef59f754b9bfc99017e1dcf4d5602fc1a97d331069b
93106
```
94107

95-
Example of console session:
108+
Example of console session.
96109

97-
```
98-
❯ jupyter-connect --token 0d2004a3f836e3dbb01a035c66a43b6fa06e44b004599835
99-
[ConsoleApp] KernelHttpManager created a new kernel: ...
110+
```bash
111+
❯ jupyter-konsole --url http://localhost:8888 --token 0d2004a3f836e3dbb01a035c66a43b6fa06e44b004599835
112+
[KonsoleApp] KernelHttpManager created a new kernel: ...
100113
Jupyter Kernel console 0.2.0
101114

102115
Python 3.12.7 | packaged by conda-forge | (main, Oct 4 2024, 16:05:46) [GCC 13.3.0]
@@ -117,15 +130,6 @@ To remove the extension, execute:
117130
pip uninstall jupyter_kernel_client
118131
```
119132

120-
## Troubleshoot
121-
122-
If you are seeing the frontend extension, but it is not working, check
123-
that the server extension is enabled:
124-
125-
```bash
126-
jupyter server extension list
127-
```
128-
129133
## Contributing
130134

131135
### Development install

jupyter_kernel_client/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
"""Jupyter Kernel Client through websocket."""
66

77
from .client import KernelClient
8+
from .konsoleapp import KonsoleApp
89
from .manager import KernelHttpManager
910
from .wsclient import KernelWebSocketClient
1011

11-
__version__ = "0.3.1"
1212

13-
__all__ = ["KernelClient", "KernelHttpManager", "KernelWebSocketClient"]
13+
__all__ = [
14+
"KernelClient",
15+
"KernelHttpManager",
16+
"KernelWebSocketClient",
17+
"KonsoleApp",
18+
]

jupyter_kernel_client/__version__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2023-2024 Datalayer, Inc.
2+
#
3+
# BSD 3-Clause License
4+
5+
"""Jupyter Kernel Client through websocket."""
6+
7+
8+
__version__ = "0.3.1"

jupyter_kernel_client/consoleapp.py renamed to jupyter_kernel_client/konsoleapp.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@
1616
from .manager import KernelHttpManager
1717
from .shell import WSTerminalInteractiveShell
1818

19+
1920
# -----------------------------------------------------------------------------
2021
# Globals
2122
# -----------------------------------------------------------------------------
2223

2324
_examples = """
2425
# Start a console connected to a local Jupyter Server running at http://localhost:8888 with a new python kernel.
25-
jupyter connect --token <server_token>
26+
jupyter konsole --token <server_token>
2627
2728
# Start a console connected to a distant Jupyter Server with a new python kernel.
28-
jupyter connect --url https://my.jupyter-server.xzy --token <server_token>
29+
jupyter konsole --url https://my.jupyter-server.xzy --token <server_token>
2930
"""
3031

3132
# -----------------------------------------------------------------------------
@@ -37,16 +38,16 @@
3738
flags.update(
3839
boolean_flag(
3940
"confirm-exit",
40-
"ConsoleApp.confirm_exit",
41+
"KonsoleApp.confirm_exit",
4142
"""Set to display confirmation dialog on exit. You can always use 'exit' or
4243
'quit', to force a direct exit without any confirmation. This can also
4344
be set in the config file by setting
44-
`c.ConsoleApp.confirm_exit`.
45+
`c.KonsoleApp.confirm_exit`.
4546
""",
4647
"""Don't prompt the user when exiting. This will terminate the kernel
4748
if it is owned by the frontend, and leave it alive if it is external.
4849
This can also be set in the config file by setting
49-
`c.ConsoleApp.confirm_exit`.
50+
`c.KonsoleApp.confirm_exit`.
5051
""",
5152
)
5253
)
@@ -63,10 +64,10 @@
6364
aliases = dict(base_aliases)
6465
aliases.update(
6566
{
66-
"existing": "ConsoleApp.existing",
67-
"kernel": "ConsoleApp.kernel_name",
68-
"token": "ConsoleApp.token",
69-
"url": "ConsoleApp.server_url",
67+
"existing": "KonsoleApp.existing",
68+
"kernel": "KonsoleApp.kernel_name",
69+
"token": "KonsoleApp.token",
70+
"url": "KonsoleApp.server_url",
7071
}
7172
)
7273

@@ -75,10 +76,10 @@
7576
# -----------------------------------------------------------------------------
7677

7778

78-
class ConsoleApp(JupyterApp):
79+
class KonsoleApp(JupyterApp):
7980
"""Start a terminal frontend to a kernel."""
8081

81-
name = "jupyter-connect"
82+
name = "jupyter-konsole"
8283
version = __version__
8384

8485
description = """
@@ -93,7 +94,7 @@ class ConsoleApp(JupyterApp):
9394
single-process Terminal IPython shell, such as connecting to an
9495
existing jupyter kernel, via:
9596
96-
jupyter connect --token <server token> --existing <kernel_id>
97+
jupyter konsole --token <server token> --existing <kernel_id>
9798
9899
where the previous session could have been created by another jupyter
99100
console, or by opening a notebook.
@@ -218,7 +219,7 @@ def start(self):
218219
self.kernel_client.client.stop_channels()
219220

220221

221-
main = launch_new_instance = ConsoleApp.launch_instance
222+
main = launch_new_instance = KonsoleApp.launch_instance
222223

223224

224225
if __name__ == "__main__":

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ classifiers = [
2323
dependencies = ["jupyter_core", "jupyter_client>=7.4.4", "requests", "traitlets>=5.3", "websocket-client"]
2424

2525
[project.optional-dependencies]
26-
console = ["jupyter_console"]
26+
konsole = ["jupyter_console"]
2727
test = ["ipykernel", "jupyter_server>=1.6,<3", "pytest>=7.0"]
2828
lint = ["mdformat>0.7", "mdformat-gfm>=0.3.5", "ruff"]
2929
typing = ["mypy>=0.990"]
3030

31+
[project.scripts]
32+
jupyter-konsole = "jupyter_kernel_client.konsoleapp:main"
33+
3134
[project.license]
3235
file = "LICENSE"
3336

34-
[project.scripts]
35-
jupyter-connect = "jupyter_kernel_client.consoleapp:main"
36-
3737
[project.urls]
3838
Home = "https://github.com/datalayer/jupyter-kernel-client"
3939

4040
[tool.hatch.version]
41-
path = "jupyter_kernel_client/__init__.py"
41+
path = "jupyter_kernel_client/__version__.py"
4242

4343
[tool.pytest.ini_options]
4444
filterwarnings = [

0 commit comments

Comments
 (0)