Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Specify that the debug messages follow the debug adapter protocol #502

Open
wants to merge 180 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
d67c82a
Make a start on kernel discovery framework
takluyver May 18, 2017
6406393
Undeprecate KernelManager.kernel_cmd, add extra_env
takluyver May 19, 2017
6ca3ec7
Use entry points to find kernel finders
takluyver Jul 26, 2017
dddda32
Tests for kernel discovery machinery
takluyver Jul 26, 2017
1509dac
Use older ABC definition style with metaclass
takluyver Jul 26, 2017
38ccbdc
Rename kernel finders -> kernel providers
takluyver Oct 9, 2017
3c09a57
Missed a rename
takluyver Oct 9, 2017
e92e5c1
Add dependency on entrypoints
takluyver Oct 9, 2017
aad40cb
Document new kernel providers system
takluyver Oct 10, 2017
c09b8ac
Break it up a bit with a subheading
takluyver Oct 10, 2017
cc8176b
Update doc with Carol's suggestions
takluyver Oct 10, 2017
1f74c5f
Fix variable name
takluyver Oct 10, 2017
8f7a865
Merge pull request #261 from takluyver/discovery
takluyver Oct 16, 2017
16608fc
Fix typo in documentation.
Oct 19, 2017
4776e8c
Merge pull request #299 from didiercrunch/patch-1
takluyver Oct 19, 2017
936dfe0
Updated URL for Jupyter Kernels
frelon Nov 1, 2017
2822872
Merge pull request #300 from frelon/patch-1
blink1073 Nov 1, 2017
aca5f70
tornado 5 support
minrk Nov 10, 2017
172d6cd
Configure interrupt mode via spec.
filmor Sep 21, 2017
f0e33ba
Update docs.
filmor Oct 30, 2017
21b9569
Bump protocol version.
filmor Nov 6, 2017
6674afa
disable pyzmq zero-copy optimizations during session tests
minrk Nov 13, 2017
7a0278a
Merge pull request #304 from minrk/tornado-5
takluyver Nov 13, 2017
e2772bd
Fix signal name.
filmor Nov 13, 2017
0d7d00f
Merge pull request #294 from filmor/interrupt
takluyver Nov 13, 2017
948d653
extend special handling of sys.executable to pythonX[.Y]
minrk Nov 22, 2017
250178f
Add 'jupyter kernel' command
takluyver Feb 10, 2017
9359b33
Use native kernel by default
takluyver Dec 11, 2017
ae03ddd
More description
takluyver Dec 11, 2017
7e6d167
Add test of 'jupyter kernel'
takluyver Dec 11, 2017
28f908f
Workaround lack of timeout on Py2
takluyver Dec 11, 2017
aa8b184
Restrict to older pytest on Python 3.3
takluyver Dec 11, 2017
5291f94
Another go at fixing pytest dependency on Python 3.3
takluyver Dec 11, 2017
7bbb56d
Merge pull request #240 from takluyver/jupyter-kernel-cmd
minrk Dec 12, 2017
16d8122
Merge pull request #306 from minrk/pythonX
takluyver Dec 13, 2017
ed05107
Tolerate invalid kernel specs in get_all_specs()
takluyver Dec 15, 2017
dd4a2d6
Improve performance of get_kernel_spec
takluyver Dec 15, 2017
22092fa
kill process group when killing kernel
minrk Dec 15, 2017
5f076b7
Start writing release notes for 5.2
takluyver Dec 15, 2017
98a4323
Merge pull request #314 from minrk/process-groups
takluyver Dec 15, 2017
6689764
Add PR #314 to changelog
takluyver Dec 15, 2017
adb8335
Merge pull request #311 from takluyver/get-kernel-spec-performance
Carreau Dec 15, 2017
cf36849
Merge pull request #310 from takluyver/get-all-specs-tolerant
Carreau Dec 15, 2017
6251cf6
Add PRs #310 and #311 to changelog
takluyver Dec 16, 2017
a9bd197
Merge pull request #315 from takluyver/changelog-5.2
takluyver Dec 18, 2017
a8b4745
require tornado
minrk Dec 19, 2017
4d1ee2a
Merge pull request #322 from minrk/require-tornado
takluyver Dec 19, 2017
072a087
Parenthesize conditional requirement in setup.py
Carreau Dec 30, 2017
c85f8ac
Merge pull request #325 from Carreau/fix-324
minrk Jan 2, 2018
e426a64
Exclude build docs from sdist.
Carreau Jan 3, 2018
77784a6
Merge pull request #328 from Carreau/no-bundle-docs
blink1073 Jan 3, 2018
41c5954
more complete error message
stonebig Jan 6, 2018
36751d3
Merge pull request #330 from stonebig/patch-1
Carreau Jan 6, 2018
c658076
Tell Travis not to test the push from MrMeeseeks
Carreau Jan 6, 2018
78951c3
Merge pull request #332 from Carreau/ignore-travis-meeseeks
Carreau Jan 7, 2018
6b03b81
Migrate SSH tunneling from pyzmq
dmanikowski-reef Jan 9, 2018
cd73530
handle classes having been torn down in atexit
minrk Jan 16, 2018
162cf6f
Merge pull request #336 from minrk/atexit-teardown
takluyver Jan 17, 2018
ca73a87
avoid calling private method in subclasses of KernelSpecManager
minrk Jan 23, 2018
7dfa6c4
test that KernelSpecManager subclasses work if they don't implement g…
minrk Jan 23, 2018
07d02be
Merge pull request #339 from minrk/fix-backward-incompat
takluyver Jan 23, 2018
43d329b
changelog for 5.2.2
minrk Jan 24, 2018
d1b08d6
Merge pull request #341 from minrk/5.2.2-changes
takluyver Jan 24, 2018
f05abf7
Convert to relative import
dmanikowski-reef Jan 25, 2018
2840d26
fix testing patch for pyzmq < 17
minrk Jan 31, 2018
a6ffbd0
Merge pull request #349 from minrk/zmq-mock
takluyver Feb 1, 2018
d9832e0
Merge pull request #335 from reef-technologies/migrate_ssh_tunneling_…
minrk Feb 7, 2018
7b45731
ThreadedClient: schedule IOLoop.stop in IOLoop thread
minrk Mar 8, 2018
64aca4d
threadsafety in IOLoopThread
minrk Mar 8, 2018
4bfb5c4
Merge pull request #352 from minrk/threadsafe-shutdown
willingc Mar 9, 2018
238314d
Wrap setting of kernel_id with method that can then be overridden in …
kevin-bates Mar 9, 2018
5f167de
Changelog for 5.2.3
minrk Mar 11, 2018
85ca084
Merge pull request #354 from minrk/changes-5.2.3
willingc Mar 11, 2018
ac9c2e9
Add metadata for new pypi.org
willingc Mar 11, 2018
bcede57
Changes from @takluyver @minrk review
willingc Mar 12, 2018
f498173
Fix OS classifier
willingc Mar 12, 2018
bad02e9
Fix Python version
willingc Mar 12, 2018
08a9f65
one more time
willingc Mar 12, 2018
8617c25
Merge pull request #357 from willingc/update-meta
minrk Mar 12, 2018
f23b71a
Fix memory leak of kernel Popen object
kevin-bates Mar 13, 2018
06e8167
Fix leak of IOLoopKernelManager object
kevin-bates Mar 13, 2018
8f62a36
Merge pull request #361 from kevin-bates/fix-leak-ioloopkernelmanager
minrk Mar 22, 2018
5108f62
Merge pull request #360 from kevin-bates/fix-leak-kernel-proc
minrk Mar 23, 2018
12da5fb
Changed kernel_id generation method name and calling scenario
kevin-bates Mar 23, 2018
25fd085
Merge pull request #353 from kevin-bates/enable-control-over-kernel-id
minrk Mar 26, 2018
dd50d58
master is 6.0-dev
minrk Mar 26, 2018
3058347
Merge pull request #368 from minrk/6.0-dev
minrk Mar 26, 2018
bf57d23
Prevent creating new console on Windows
nanoant Jan 30, 2018
b754994
Merge pull request #346 from nanoant/master
takluyver Apr 12, 2018
0e1a218
Update gitignore configuration
lresende May 4, 2018
375ea01
make KernelManager configurable for all who inherit JupyterConsoleApp
mpacer May 15, 2018
f1d8a95
Explicitly require a pytest that knows how to yield
mpacer May 15, 2018
2fae25b
Merge pull request #379 from mpacer/config_kernel_manager
Carreau May 17, 2018
889f822
update python version testing
Carreau May 16, 2018
6c7a8ab
dash-dot
Carreau May 16, 2018
d62626e
remove other places that are py3.3 specific, min py version is now py3.4
mpacer May 16, 2018
01fc51b
Merge pull request #380 from Carreau/bump-testing
Carreau May 18, 2018
da6d97d
don't include extra buffers in message signature
twavv Jun 6, 2018
3c5a8be
Include LICENSE file in wheels
toddrme2178 Jun 8, 2018
44980c1
Merge pull request #385 from toddrme2178/patch-1
minrk Jun 13, 2018
b680593
Clarify what “session” means in the kernel message headers from the c…
jasongrout Jul 13, 2018
49aabf9
Clarify the implied required busy/idle messages.
jasongrout Jul 13, 2018
9dabc43
Deprecate sending the shutdown_request message on the shell channel.
jasongrout Jul 13, 2018
4f7c825
Clarify the status message.
jasongrout Jul 13, 2018
4da4251
Merge pull request #384 from travigd/master
minrk Jul 13, 2018
86a347d
Merge pull request #377 from lresende/gitignore
minrk Jul 14, 2018
e899ef1
Send the shutdown message over the control channel in client.py.
jasongrout Jul 18, 2018
c4d2414
Clarify the session ids in message headers.
jasongrout Jul 18, 2018
c369247
Fix control channel copy/paste error.
jasongrout Jul 19, 2018
846354e
Move shutdown request to its own section to emphasize the message is …
jasongrout Jul 19, 2018
5bac5e5
Percolate a control connection throughout the code.
jasongrout Jul 19, 2018
00812c3
Remove commented debug statement that used old API.
Carreau Aug 13, 2018
cfe57c9
Allow third-party kernels to get additional args
Aug 28, 2018
34f96d7
Merge pull request #396 from dsblank/patch-1
minrk Sep 3, 2018
3a06e63
Merge pull request #393 from Carreau/clean-debug
minrk Oct 15, 2018
72e9fc4
try to fix coverage
Carreau Oct 20, 2018
50ddc22
Merge pull request #403 from Carreau/fix-cov
Carreau Oct 20, 2018
7a46b6b
set close_fds=False when starting kernels on Windows
minrk Nov 30, 2018
1d807c2
Merge pull request #408 from minrk/close-fds-windows
minrk Dec 1, 2018
ddcfb5a
add long_description to setup.py
minrk Dec 10, 2018
7a1793b
Fix documentation error.
twavv Dec 18, 2018
63caabf
Merge pull request #411 from minrk/long-description
rgbkrk Feb 9, 2019
1e9194a
Replace sleep by wait
Feb 11, 2019
e206315
Merge pull request #414 from travigd/travigd-patch-1
minrk Feb 14, 2019
5828261
remove pytest-warnings
minrk Feb 14, 2019
cd9532c
eager upgrade strategy
minrk Feb 14, 2019
d9ff831
Clarify stop_on_error documentation.
twavv Feb 14, 2019
3fbd4c6
Merge pull request #421 from minrk/pytest-up
minrk Feb 15, 2019
cf7cdb8
Merge pull request #422 from travigd/clarify-stop_on_error-documentation
minrk Feb 15, 2019
e813086
Merge pull request #420 from impact27/master
minrk Feb 15, 2019
4638b74
Remove ambiguity in the startup description
ericdill Mar 6, 2019
f2f0e63
Consider removing word for clarity
ericdill Mar 6, 2019
b7bc293
Remove some warning in test, create all dates as UTC.
Carreau Mar 26, 2019
1375c94
Disambiguate client startup and kernel startup
ericdill Mar 30, 2019
7b9c834
Set the default connection_file such that it preserves an existing co…
SpencerPark Apr 1, 2019
9ceaed5
Merge pull request #431 from Carreau/less-warnings-in-tests
Carreau Apr 17, 2019
6c206e4
Merge pull request #426 from ericdill/docs-suggestions
minrk Apr 23, 2019
56533ff
Build docs with Python 3.7 on conda
takluyver Apr 25, 2019
043c0e6
Merge pull request #435 from jupyter/docs-env-py37
takluyver Apr 25, 2019
0658a7b
Demonstrate kernel failures with multiple processes
alexrudy May 8, 2019
b65f96f
Merge pull request #432 from SpencerPark/fix-381
minrk May 13, 2019
d3ddee0
drop Python 3.4 support
minrk May 13, 2019
1cec386
Merge pull request #437 from alexrudy/fix-zmq-parallel
MSeal May 13, 2019
ddd945d
Add xeus to the documentation on how to write a kernel for Jupyter
martinRenou May 21, 2019
f1ad17d
Merge pull request #440 from martinRenou/add_xeus_to_documentation
blink1073 May 21, 2019
9263e49
update wrapper kernel docs
blink1073 Jun 1, 2019
f0683b1
Merge pull request #444 from blink1073/metakernel
rgbkrk Jun 5, 2019
7eee55f
Exposes control channel in public API
JohanMabille Jun 12, 2019
5f06a7a
Changed zmqContext to not reuse instances
MSeal Jun 13, 2019
eaa039e
Added multi-kernelmanager tests for parallel managers
MSeal Jun 13, 2019
f083570
Merge pull request #448 from jupyter/zmqContextIsolation
rgbkrk Jun 26, 2019
51d1d7a
Merge pull request #447 from JohanMabille/control
rgbkrk Jun 26, 2019
3968ab0
Harmonize “status” field
flying-sheep Jul 8, 2019
af4a9a2
call _create_connected_socket to instantiate _control_socket in Kerne…
JohanMabille Jul 9, 2019
43c9c2f
Merge pull request #456 from JohanMabille/control
SylvainCorlay Jul 9, 2019
c3231ac
Merge pull request #454 from flying-sheep/patch-1
MSeal Jul 9, 2019
614ade1
Reduce count of warnings
Jamim Jul 12, 2019
2e2e5da
Merge pull request #460 from Jamim/fix/warnings
minrk Jul 12, 2019
a004d92
Declare support for Python 2.7, 3.5, 3.6, and 3.7
Jamim Jul 12, 2019
4d8a115
Clarify that iopub error message doesn't include execution_count
takluyver Jul 17, 2019
18bf345
Clarify that execute_reply messages have execution_count for any status
takluyver Jul 17, 2019
2b1a6e7
Merge pull request #461 from Jamim/feature/python-classifiers
minrk Jul 22, 2019
4738e6a
Merge pull request #462 from takluyver/exec-count-ambiguities
minrk Jul 22, 2019
5f0a21b
Revert status message updates to revert back to exactly three status …
jasongrout Jul 26, 2019
4def2a2
Merge pull request #388 from jasongrout/update
SylvainCorlay Jul 27, 2019
0bfcaeb
Document debug_[request|reply] and debug_event
SylvainCorlay Jul 29, 2019
24d97af
CoCalc is no longer affected by the unicode offset issue (see https:/…
williamstein Aug 16, 2019
ffdc127
add an example of an astral plane unicode identifier
williamstein Aug 17, 2019
2b1beeb
Merge pull request #468 from williamstein/master
MSeal Aug 19, 2019
2a43817
Merge pull request #464 from SylvainCorlay/debug-messages
MSeal Aug 19, 2019
fe30ee1
Add support for templated env entries
kevin-bates Aug 31, 2019
5d37a3a
Update kernelspec env bullet in docs
kevin-bates Sep 3, 2019
dc213de
Merge pull request #472 from kevin-bates/templated-env
blink1073 Sep 5, 2019
3279597
Prevent two kernels to have the same ports
martinRenou Oct 10, 2019
f6ceeaa
Merge pull request #490 from martinRenou/workaround_port_issue
SylvainCorlay Oct 10, 2019
54a6be5
Only cache ports if the cache_ports flag is set to True
martinRenou Oct 15, 2019
fb91900
Merge pull request #492 from martinRenou/cache_ports
SylvainCorlay Oct 17, 2019
8b60325
changed Session.msg_id() property to
tomoboy Oct 20, 2019
650fd75
Merge pull request #493 from tomoboy/session_msg_id_optimization
minrk Nov 5, 2019
492efc6
Specify that the debug messages follow the debug adapter protocol
SylvainCorlay Dec 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
MANIFEST
build
dist
_build
docs/gh-pages
*.py[co]
__pycache__
*.egg-info
Expand All @@ -16,3 +14,16 @@ __pycache__
.coverage
.cache
absolute.json
htmlcov/

# Sphinx documentation
_build
docs/_build/
docs/gh-pages

# PyBuilder
target/

# PyCharm
.idea/
*.iml
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
dist: xenial
language: python
python:
- "nightly"
- '3.6-dev'
- 3.5
- 3.4
- 3.3
- 2.7
sudo: false
- "3.8-dev"
- "3.7"
- "3.6"
- "3.5"
- "2.7"
install:
- pip install --upgrade setuptools pip
- pip install --upgrade --pre -e .[test] pytest-cov pytest-warnings codecov
- pip install --upgrade --upgrade-strategy eager --pre -e .[test] pytest-cov codecov 'coverage<5'
- pip freeze
script:
- py.test --cov jupyter_client jupyter_client
after_success:
- codecov
matrix:
allow_failures:
- python: nightly
branches:
except:
- /^auto-backport-of-pr-[0-9]+$/
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include README.md
# Documentation
graft docs
exclude docs/\#*
exclude docs/_*

# Examples
graft examples
Expand Down
76 changes: 76 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,82 @@
Changes in Jupyter Client
=========================

5.2.3
=====

`5.2.3 on GitHub <https://github.com/jupyter/jupyter_client/milestones/5.2.3>`__

- Fix hang on close in :class:`.ThreadedKernelClient` (used in QtConsole)
when using tornado with asyncio
(default behavior of tornado 5, see :ghpull:`352`).
- Fix errors when using deprecated :attr:`.KernelManager.kernel_cmd`
(:ghpull:`343`, :ghpull:`344`).

5.2.2
=====

`5.2.2 on GitHub <https://github.com/jupyter/jupyter_client/milestones/5.2.2>`__

- Fix :meth:`.KernelSpecManager.get_all_specs` method in subclasses
that only override :meth:`.KernelSpecManager.find_kernel_specs`
and :meth:`.KernelSpecManager.get_kernel_spec`.
See :ghissue:`338` and :ghpull:`339`.
- Eliminate occasional error messages during process exit (:ghpull:`336`).
- Improve error message when attempting to bind on invalid address (:ghpull:`330`).
- Add missing direct dependency on tornado (:ghpull:`323`).


5.2.1
=====

`5.2.1 on GitHub <https://github.com/jupyter/jupyter_client/milestones/5.2.1>`__

- Add parenthesis to conditional pytest requirement to work around a bug in the
``wheel`` package, that generate a ``.whl`` which otherwise always depends on
``pytest`` see :ghissue:`324` and :ghpull:`325`.

5.2
===

`5.2 on GitHub <https://github.com/jupyter/jupyter_client/milestones/5.2>`__

- Define Jupyter protocol version 5.3:

- Kernels can now opt to be interrupted by a message sent on the control channel
instead of a system signal. See :ref:`kernelspecs` and :ref:`msging_interrupt`
(:ghpull:`294`).

- New ``jupyter kernel`` command to launch an installed kernel by name
(:ghpull:`240`).
- Kernelspecs where the command starts with e.g. ``python3`` or
``python3.6``—matching the version ``jupyter_client`` is running on—are now
launched with the same Python executable as the launching process (:ghpull:`306`).
This extends the special handling of ``python`` added in 5.0.
- Command line arguments specified by a kernelspec can now include
``{resource_dir}``, which will be substituted with the kernelspec resource
directory path when the kernel is launched (:ghpull:`289`).
- Kernelspecs now have an optional ``metadata`` field to hold arbitrary metadata
about kernels—see :ref:`kernelspecs` (:ghpull:`274`).
- Make the ``KernelRestarter`` class used by a ``KernelManager`` configurable
(:ghpull:`290`).
- When killing a kernel on Unix, kill its process group (:ghpull:`314`).
- If a kernel dies soon after starting, reassign random ports before restarting
it, in case one of the previously chosen ports has been bound by another
process (:ghpull:`279`).
- Avoid unnecessary filesystem operations when finding a kernelspec with
:meth:`.KernelSpecManager.get_kernel_spec` (:ghpull:`311`).
- :meth:`.KernelSpecManager.get_all_specs` will no longer raise an exception on
encountering an invalid ``kernel.json`` file. It will raise a warning and
continue (:ghpull:`310`).
- Check for non-contiguous buffers before trying to send them through ZMQ
(:ghpull:`258`).
- Compatibility with upcoming Tornado version 5.0 (:ghpull:`304`).
- Simplify setup code by always using setuptools (:ghpull:`284`).
- Soften warnings when setting the sticky bit on runtime files fails
(:ghpull:`286`).
- Various corrections and improvements to documentation.


5.1
===

Expand Down
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinxcontrib_github_alt',
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -55,6 +56,8 @@
copyright = '2015, Jupyter Development Team'
author = 'Jupyter Development Team'

github_project_url = "https://github.com/jupyter/jupyter_client"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
Expand Down
4 changes: 3 additions & 1 deletion docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ channels:
- conda-forge
dependencies:
- pyzmq
- python==3.5
- python==3.7
- traitlets>=4.1
- jupyter_core
- sphinx>=1.3.6
- sphinx_rtd_theme
- pip:
- sphinxcontrib_github_alt
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with Jupyter kernels.

kernels
wrapperkernels
kernel_providers

.. toctree::
:maxdepth: 2
Expand Down
156 changes: 156 additions & 0 deletions docs/kernel_providers.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
================
Kernel providers
================

.. note::
This is a new interface under development, and may still change.
Not all Jupyter applications use this yet.
See :ref:`kernelspecs` for the established way of discovering kernel types.

Creating a kernel provider
==========================

By writing a kernel provider, you can extend how Jupyter applications discover
and start kernels. For example, you could find kernels in an environment system
like conda, or kernels on remote systems which you can access.

To write a kernel provider, subclass
:class:`jupyter_client.discovery.KernelProviderBase`, giving your provider an ID
and overriding two methods.

.. class:: MyKernelProvider

.. attribute:: id

A short string identifying this provider. Cannot contain forward slash
(``/``).

.. method:: find_kernels()

Get the available kernel types this provider knows about.
Return an iterable of 2-tuples: (name, attributes).
*name* is a short string identifying the kernel type.
*attributes* is a dictionary with information to allow selecting a kernel.

.. method:: make_manager(name)

Prepare and return a :class:`~jupyter_client.KernelManager` instance
ready to start a new kernel instance of the type identified by *name*.
The input will be one of the names given by :meth:`find_kernels`.

For example, imagine we want to tell Jupyter about kernels for a new language
called *oblong*::

# oblong_provider.py
from jupyter_client.discovery import KernelProviderBase
from jupyter_client import KernelManager
from shutil import which

class OblongKernelProvider(KernelProviderBase):
id = 'oblong'

def find_kernels(self):
if not which('oblong-kernel'):
return # Check it's available

# Two variants - for a real kernel, these could be something like
# different conda environments.
yield 'standard', {
'display_name': 'Oblong (standard)',
'language': {'name': 'oblong'},
'argv': ['oblong-kernel'],
}
yield 'rounded', {
'display_name': 'Oblong (rounded)',
'language': {'name': 'oblong'},
'argv': ['oblong-kernel'],
}

def make_manager(self, name):
if name == 'standard':
return KernelManager(kernel_cmd=['oblong-kernel'],
extra_env={'ROUNDED': '0'})
elif name == 'rounded':
return KernelManager(kernel_cmd=['oblong-kernel'],
extra_env={'ROUNDED': '1'})
else:
raise ValueError("Unknown kernel %s" % name)

You would then register this with an *entry point*. In your ``setup.py``, put
something like this::

setup(...
entry_points = {
'jupyter_client.kernel_providers' : [
# The name before the '=' should match the id attribute
'oblong = oblong_provider:OblongKernelProvider',
]
})

Finding kernel types
====================

To find and start kernels in client code, use
:class:`jupyter_client.discovery.KernelFinder`. This uses multiple kernel
providers to find available kernels. Like a kernel provider, it has methods
``find_kernels`` and ``make_manager``. The kernel names it works
with have the provider ID as a prefix, e.g. ``oblong/rounded`` (from the example
above).

::

from jupyter_client.discovery import KernelFinder
kf = KernelFinder.from_entrypoints()

## Find available kernel types
for name, attributes in kf.find_kernels():
print(name, ':', attributes['display_name'])
# oblong/standard : Oblong (standard)
# oblong/rounded : Oblong(rounded)
# ...

## Start a kernel by name
manager = kf.make_manager('oblong/standard')
manager.start_kernel()

.. module:: jupyter_client.discovery

.. autoclass:: KernelFinder

.. automethod:: from_entrypoints

.. automethod:: find_kernels

.. automethod:: make_manager

Kernel providers included in ``jupyter_client``
===============================================

``jupyter_client`` includes two kernel providers:

.. autoclass:: KernelSpecProvider

.. seealso:: :ref:`kernelspecs`

.. autoclass:: IPykernelProvider

Glossary
========

Kernel instance
A running kernel, a process which can accept ZMQ connections from frontends.
Its state includes a namespace and an execution counter.

Kernel type
The software to run a kernel instance, along with the context in which a
kernel starts. One kernel type allows starting multiple, initially similar
kernel instances. For instance, one kernel type may be associated with one
conda environment containing ``ipykernel``. The same kernel software in
another environment would be a different kernel type. Another software package
for a kernel, such as ``IRkernel``, would also be a different kernel type.

Kernel provider
A Python class to discover kernel types and allow a client to start instances
of those kernel types. For instance, one kernel provider might find conda
environments containing ``ipykernel`` and allow starting kernel instances in
these environments.
31 changes: 26 additions & 5 deletions docs/kernels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@ Making kernels for Jupyter

A 'kernel' is a program that runs and introspects the user's code. IPython
includes a kernel for Python code, and people have written kernels for
`several other languages <https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages>`_.
`several other languages <https://github.com/jupyter/jupyter/wiki/Jupyter-kernels>`_.

When Jupyter starts a kernel, it passes it a connection file. This specifies
At kernel startup, Jupyter passes the kernel a connection file. This specifies
how to set up communications with the frontend.

There are two options for writing a kernel:
There are three options for writing a kernel:

1. You can reuse the IPython kernel machinery to handle the communications, and
just describe how to execute your code. This is much simpler if the target
language can be driven from Python. See :doc:`wrapperkernels` for details.
2. You can implement the kernel machinery in your target language. This is more
work initially, but the people using your kernel might be more likely to
contribute to it if it's in the language they know.
3. You can use the `xeus <https://github.com/QuantStack/xeus>`_ library that is
a C++ implementation of the Jupyter kernel protocol. Kernel authors only need to
implement the language-specific logic in their implementation
(execute code, auto-completion...). This is the simplest
solution if your target language can be driven from C or C++: e.g. if it has
a C-API like most scripting languages. Check out the
`xeus documentation <https://xeus.readthedocs.io/>`_ for more details.
Examples of kernels based on xeus include:
- `xeus-cling <https://github.com/QuantStack/xeus-cling>`_
- `xeus-python <https://github.com/QuantStack/xeus-python>`_
- `JuniperKernel <https://github.com/JuniperKernel/JuniperKernel>`_

Connection files
================
Expand Down Expand Up @@ -132,11 +143,21 @@ JSON serialised dictionary containing the following keys and values:
is found, a kernel with a matching `language` will be used.
This allows a notebook written on any Python or Julia kernel to be properly associated
with the user's Python or Julia kernel, even if they aren't listed under the same name as the author's.
- **interrupt_mode** (optional): May be either ``signal`` or ``message`` and
specifies how a client is supposed to interrupt cell execution on this kernel,
either by sending an interrupt ``signal`` via the operating system's
signalling facilities (e.g. `SIGINT` on POSIX systems), or by sending an
``interrupt_request`` message on the control channel (see
:ref:`msging_interrupt`). If this is not specified
the client will default to ``signal`` mode.
- **env** (optional): A dictionary of environment variables to set for the kernel.
These will be added to the current environment variables before the kernel is
started.
started. Existing environment variables can be referenced using ``${<ENV_VAR>}`` and
will be substituted with the corresponding value. Administrators should note that use
of ``${<ENV_VAR>}`` can expose sensitive variables and should use only in controlled
circumstances.
- **metadata** (optional): A dictionary of additional attributes about this
kernel; used by clients to aid clients in kernel selection. Metadata added
kernel; used by clients to aid in kernel selection. Metadata added
here should be namespaced for the tool reading and writing that metadata.

For example, the kernel.json file for IPython looks like this::
Expand Down
Loading