├── .github └── workflows │ ├── enforce-label.yml │ └── test.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.rst ├── echo_kernel ├── __init__.py ├── __main__.py └── kernel.py ├── hatch_build.py ├── pyproject.toml └── test_echo.py /.github/workflows/enforce-label.yml: -------------------------------------------------------------------------------- 1 | name: Enforce PR label 2 | 3 | on: 4 | pull_request: 5 | types: [labeled, unlabeled, opened, edited, synchronize] 6 | jobs: 7 | enforce-label: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | pull-requests: write 11 | steps: 12 | - name: enforce-triage-label 13 | uses: jupyterlab/maintainer-tools/.github/actions/enforce-label@v1 14 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a variety of Python versions 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Python package 5 | 6 | on: 7 | push: 8 | pull_request: 9 | schedule: 10 | - cron: "0 8 * * *" 11 | 12 | concurrency: 13 | group: >- 14 | ${{ github.workflow }}- 15 | ${{ github.ref_type }}- 16 | ${{ github.event.pull_request.number || github.sha }} 17 | cancel-in-progress: true 18 | 19 | jobs: 20 | build: 21 | runs-on: ${{ matrix.os }} 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | os: [ubuntu-latest, windows-latest, macos-latest] 26 | python-version: ["3.8", "3.12"] 27 | include: 28 | - os: windows-latest 29 | python-version: "3.10" 30 | - os: ubuntu-latest 31 | python-version: "pypy-3.9" 32 | - os: macos-latest 33 | python-version: "3.11" 34 | steps: 35 | - uses: actions/checkout@v2 36 | - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 37 | - name: Install dependencies 38 | run: | 39 | pip install -e ".[test]" 40 | - name: Test with kernel tester 41 | run: | 42 | python -m unittest -v 43 | - name: Check Kernel 44 | run: | 45 | cd $HOME 46 | jupyter kernelspec list | grep echo 47 | 48 | check_release: 49 | runs-on: ubuntu-latest 50 | steps: 51 | - name: Checkout 52 | uses: actions/checkout@v2 53 | - name: Base Setup 54 | uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 55 | - name: Install Dependencies 56 | run: | 57 | pip install -e . 58 | - name: Check Release 59 | uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2 60 | with: 61 | token: ${{ secrets.GITHUB_TOKEN }} 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | MANIFEST 2 | build 3 | dist 4 | _build 5 | *.py[co] 6 | __pycache__ 7 | *.egg-info 8 | *~ 9 | *.bak 10 | .ipynb_checkpoints 11 | .tox 12 | .DS_Store 13 | \#*# 14 | .#* 15 | .coverage 16 | htmlcov 17 | .cache 18 | .idea 19 | data_kernelspec 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changes in echo kernel 2 | 3 | 4 | 5 | ## 1.1 6 | 7 | [on 8 | GitHub](https://github.com/jupyter/jupyter_core/releases/tag/1.1) 9 | 10 | - Add ``--sys-prefix`` argument 11 | 12 | 13 | 14 | ## 1.0 15 | 16 | - Packaging, README, fixes 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2017, Project Jupyter Contributors 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | echo_kernel 2 | =========== 3 | 4 | ``echo_kernel`` is a simple example of a Jupyter kernel. This repository 5 | complements the documentation on wrapper kernels here: 6 | 7 | http://jupyter-client.readthedocs.io/en/latest/wrapperkernels.html 8 | 9 | Installation 10 | ------------ 11 | 12 | From PyPI 13 | ~~~~~~~~~ 14 | 15 | To install ``echo_kernel`` from PyPI:: 16 | 17 | pip install echo_kernel 18 | 19 | From Git using Conda 20 | ~~~~~~~~~~~~~~~~~~~~ 21 | 22 | To install ``echo_kernel`` from git into a Conda environment:: 23 | 24 | git clone https://github.com/jupyter/echo_kernel 25 | cd echo_kernel 26 | conda create -n ker jupyter 27 | conda activate ker 28 | pip install . 29 | 30 | 31 | Using the Echo kernel 32 | --------------------- 33 | **Notebook**: The *New* menu in the notebook should show an option for an Echo notebook. 34 | 35 | **Console frontends**: To use it with the console frontends, add ``--kernel echo`` to 36 | their command line arguments. 37 | -------------------------------------------------------------------------------- /echo_kernel/__init__.py: -------------------------------------------------------------------------------- 1 | """An example Jupyter kernel""" 2 | 3 | __version__ = '1.1' 4 | 5 | from .kernel import EchoKernel 6 | -------------------------------------------------------------------------------- /echo_kernel/__main__.py: -------------------------------------------------------------------------------- 1 | from ipykernel.kernelapp import IPKernelApp 2 | from . import EchoKernel 3 | 4 | IPKernelApp.launch_instance(kernel_class=EchoKernel) 5 | -------------------------------------------------------------------------------- /echo_kernel/kernel.py: -------------------------------------------------------------------------------- 1 | from ipykernel.kernelbase import Kernel 2 | 3 | class EchoKernel(Kernel): 4 | implementation = 'Echo' 5 | implementation_version = '1.0' 6 | language = 'no-op' 7 | language_version = '0.1' 8 | language_info = { 9 | 'name': 'echo', 10 | 'mimetype': 'text/plain', 11 | 'file_extension': '.txt', 12 | } 13 | banner = "Echo kernel - as useful as a parrot" 14 | 15 | def do_execute(self, code, silent, store_history=True, user_expressions=None, 16 | allow_stdin=False): 17 | if not silent: 18 | stream_content = {'name': 'stdout', 'text': code} 19 | self.send_response(self.iopub_socket, 'stream', stream_content) 20 | 21 | return {'status': 'ok', 22 | # The base class increments the execution count 23 | 'execution_count': self.execution_count, 24 | 'payload': [], 25 | 'user_expressions': {}, 26 | } 27 | -------------------------------------------------------------------------------- /hatch_build.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | from hatchling.builders.hooks.plugin.interface import BuildHookInterface 4 | 5 | 6 | import argparse 7 | import json 8 | import os 9 | import sys 10 | import shutil 11 | 12 | from jupyter_client.kernelspec import KernelSpecManager 13 | from tempfile import TemporaryDirectory 14 | 15 | kernel_json = { 16 | "argv": [sys.executable, "-m", "echo_kernel", "-f", "{connection_file}"], 17 | "display_name": "Echo", 18 | "language": "text", 19 | } 20 | 21 | class CustomHook(BuildHookInterface): 22 | def initialize(self, version, build_data): 23 | here = os.path.abspath(os.path.dirname(__file__)) 24 | sys.path.insert(0, here) 25 | prefix = os.path.join(here, 'data_kernelspec') 26 | 27 | with TemporaryDirectory() as td: 28 | os.chmod(td, 0o755) # Starts off as 700, not user readable 29 | with open(os.path.join(td, 'kernel.json'), 'w') as f: 30 | json.dump(kernel_json, f, sort_keys=True) 31 | print('Installing Jupyter kernel spec') 32 | 33 | # Requires logo files in kernel root directory 34 | cur_path = os.path.dirname(os.path.realpath(__file__)) 35 | for logo in ["logo-32x32.png", "logo-64x64.png"]: 36 | try: 37 | shutil.copy(os.path.join(cur_path, logo), td) 38 | except FileNotFoundError: 39 | print("Custom logo files not found. Default logos will be used.") 40 | 41 | KernelSpecManager().install_kernel_spec(td, 'echo', user=False, prefix=prefix) 42 | 43 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "hatchling>=1.10.0", "ipykernel" 4 | ] 5 | build-backend = "hatchling.build" 6 | 7 | [project] 8 | name = "echo-kernel" 9 | dynamic = [ 10 | "version", 11 | ] 12 | description = "Simple example kernel for Jupyter" 13 | readme = "README.rst" 14 | license = { file = "LICENSE" } 15 | authors = [ 16 | { name = "Jupyter Development Team", email = "jupyter@googlegroups.com" }, 17 | ] 18 | classifiers = [ 19 | "Intended Audience :: Developers", 20 | "License :: OSI Approved :: BSD License", 21 | "Programming Language :: Python :: 3", 22 | ] 23 | requires-python = ">=3.8" 24 | dependencies = [ 25 | "ipykernel", 26 | "jupyter_client", 27 | ] 28 | 29 | [project.optional-dependencies] 30 | test = [ 31 | "jupyter_kernel_test", 32 | ] 33 | 34 | [project.urls] 35 | Homepage = "https://github.com/jupyter/echo_kernel" 36 | 37 | [tool.hatch.version] 38 | path = "echo_kernel/__init__.py" 39 | 40 | # Used to call hatch_build.py 41 | [tool.hatch.build.hooks.custom] 42 | 43 | 44 | [tool.hatch.build.targets.sdist] 45 | include = [ 46 | "/echo_kernel", 47 | ] 48 | 49 | [tool.hatch.build.targets.wheel.shared-data] 50 | "data_kernelspec/share" = "share" 51 | -------------------------------------------------------------------------------- /test_echo.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example use of jupyter_kernel_test, with tests for the default python3 kernel 3 | (IPyKernel). This includes all the currently available tests. 4 | """ 5 | 6 | import unittest 7 | 8 | import jupyter_kernel_test as jkt 9 | 10 | 11 | class EchoKernelTests(jkt.KernelTests): 12 | 13 | # REQUIRED 14 | 15 | # the kernel to be tested 16 | # this is the normally the name of the directory containing the 17 | # kernel.json file - you should be able to do 18 | # `jupyter console --kernel KERNEL_NAME` 19 | kernel_name = "echo" 20 | 21 | # Everything else is OPTIONAL 22 | 23 | # the name of the language the kernel executes 24 | # checked against language_info.name in kernel_info_reply 25 | language_name = "echo" 26 | 27 | # the normal file extension (including the leading dot) for this language 28 | # checked against language_info.file_extension in kernel_info_reply 29 | file_extension = ".txt" 30 | 31 | # code which should write the exact string `hello, world` to STDOUT 32 | code_hello_world = "hello, world" 33 | 34 | 35 | if __name__ == "__main__": 36 | unittest.main() 37 | --------------------------------------------------------------------------------