Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: |
hatch run typing:test
hatch run lint:style
pipx run 'validate-pyproject[all]' pyproject.toml
pipx run interrogate -vv .
pipx run doc8 --max-line-length=200

check_release:
Expand All @@ -89,7 +89,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}

test_docs:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
Expand Down
13 changes: 8 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-ast
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: forbid-new-submodules
- id: check-builtin-literals
- id: debug-statements
exclude: ipykernel/kernelapp.py
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
Expand All @@ -33,7 +36,7 @@ repos:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.177
rev: v0.0.189
hooks:
- id: ruff
args: ["--fix"]
8 changes: 8 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
"sphinxcontrib_github_alt",
]

try:
import enchant # noqa

extensions += ["sphinxcontrib.spelling"]
except ImportError:
pass


github_project_url = "https://github.com/ipython/ipykernel"

# Add any paths that contain templates here, relative to this directory.
Expand Down
3 changes: 3 additions & 0 deletions examples/embedding/inprocess_qtconsole.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""An in-process qt console app."""
import os
import sys

Expand All @@ -8,6 +9,7 @@


def print_process_id():
"""Print the process id."""
print("Process ID is:", os.getpid())


Expand Down Expand Up @@ -42,6 +44,7 @@ def init_asyncio_patch():


def main():
"""The main entry point."""
# Print the ID of the main process
print_process_id()

Expand Down
3 changes: 3 additions & 0 deletions examples/embedding/inprocess_terminal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""An in-process terminal example."""
import os
import sys

Expand All @@ -8,6 +9,7 @@


def print_process_id():
"""Print the process id."""
print("Process ID is:", os.getpid())


Expand Down Expand Up @@ -42,6 +44,7 @@ def init_asyncio_patch():


def main():
"""The main function."""
print_process_id()

# Create an in-process kernel
Expand Down
8 changes: 7 additions & 1 deletion examples/embedding/internal_ipkernel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""An internal ipykernel example."""
# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -26,8 +27,10 @@ def mpl_kernel(gui):


class InternalIPKernel:
"""An internal ipykernel class."""

def init_ipkernel(self, backend):
# Start IPython kernel with GUI event loop and mpl support
"""Start IPython kernel with GUI event loop and mpl support."""
self.ipkernel = mpl_kernel(backend)
# To create and track active qt consoles
self.consoles = []
Expand All @@ -41,6 +44,7 @@ def init_ipkernel(self, backend):
# self.namespace['ipkernel'] = self.ipkernel # dbg

def print_namespace(self, evt=None):
"""Print the namespace."""
print("\n***Variables in User namespace***")
for k, v in self.namespace.items():
if not k.startswith("_"):
Expand All @@ -52,8 +56,10 @@ def new_qt_console(self, evt=None):
return connect_qtconsole(self.ipkernel.abs_connection_file, profile=self.ipkernel.profile)

def count(self, evt=None):
"""Get the app counter value."""
self.namespace["app_counter"] += 1

def cleanup_consoles(self, evt=None):
"""Clean up the consoles."""
for c in self.consoles:
c.kill()
4 changes: 4 additions & 0 deletions examples/embedding/ipkernel_qtapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
# Functions and classes
# -----------------------------------------------------------------------------
class SimpleWindow(Qt.QWidget, InternalIPKernel):
"""A custom Qt widget for IPykernel."""

def __init__(self, app):
"""Initialize the widget."""
Qt.QWidget.__init__(self)
self.app = app
self.add_widgets()
self.init_ipkernel("qt")

def add_widgets(self):
"""Add the widget."""
self.setGeometry(300, 300, 400, 70)
self.setWindowTitle("IPython in your app")

Expand Down
4 changes: 4 additions & 0 deletions examples/embedding/ipkernel_wxapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class MyFrame(wx.Frame, InternalIPKernel):
"""

def __init__(self, parent, title):
"""Initialize the frame."""
wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 285))

# Create the menubar
Expand Down Expand Up @@ -99,7 +100,10 @@ def OnTimeToClose(self, evt):


class MyApp(wx.App):
"""A custom wx app."""

def OnInit(self):
"""Initialize app."""
frame = MyFrame(None, "Simple wxPython App")
self.SetTopWindow(frame)
frame.Show(True)
Expand Down
4 changes: 4 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""A custom hatch build hook for ipykernel."""
import os
import shutil
import sys
Expand All @@ -6,7 +7,10 @@


class CustomHook(BuildHookInterface):
"""The IPykernel build hook."""

def initialize(self, version, build_data):
"""Initialize the hook."""
here = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, here)
from ipykernel.kernelspec import make_ipkernel_cmd, write_kernel_spec
Expand Down
1 change: 1 addition & 0 deletions ipykernel/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The cli entry point for ipykernel."""
if __name__ == "__main__":
from ipykernel import kernelapp as app

Expand Down
3 changes: 3 additions & 0 deletions ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

# this is the class that will be created if we do comm.create_comm
class BaseComm(comm.base_comm.BaseComm):
"""The base class for comms."""

kernel: Optional[Kernel] = None

def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
Expand Down Expand Up @@ -69,6 +71,7 @@ def _default_comm_id(self):
return uuid.uuid4().hex

def __init__(self, target_name='', data=None, metadata=None, buffers=None, **kwargs):
"""Initialize a comm."""
# Handle differing arguments between base classes.
had_kernel = 'kernel' in kwargs
kernel = kwargs.pop('kernel', None)
Expand Down
2 changes: 2 additions & 0 deletions ipykernel/comm/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@


class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable):
"""A comm manager."""

kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")
comms = traitlets.Dict()
targets = traitlets.Dict()

def __init__(self, **kwargs):
"""Initialize the manager."""
# CommManager doesn't take arguments, so we explicitly forward arguments
comm.base_comm.CommManager.__init__(self)
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
9 changes: 9 additions & 0 deletions ipykernel/compiler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Compiler helpers for the debugger."""
import os
import sys
import tempfile
Expand All @@ -6,6 +7,7 @@


def murmur2_x86(data, seed):
"""Get the murmur2 hash."""
m = 0x5BD1E995
data = [chr(d) for d in str.encode(data, "utf8")]
length = len(data)
Expand Down Expand Up @@ -70,17 +72,20 @@ def _convert_to_long_pathname(filename):


def get_tmp_directory():
"""Get a temp directory."""
tmp_dir = convert_to_long_pathname(tempfile.gettempdir())
pid = os.getpid()
return tmp_dir + os.sep + "ipykernel_" + str(pid)


def get_tmp_hash_seed():
"""Get a temp hash seed."""
hash_seed = 0xC70F6907
return hash_seed


def get_file_name(code):
"""Get a file name."""
cell_name = os.environ.get("IPYKERNEL_CELL_NAME")
if cell_name is None:
name = murmur2_x86(code, get_tmp_hash_seed())
Expand All @@ -89,9 +94,13 @@ def get_file_name(code):


class XCachingCompiler(CachingCompiler):
"""A custom caching compiler."""

def __init__(self, *args, **kwargs):
"""Initialize the compiler."""
super().__init__(*args, **kwargs)
self.log = None

def get_code_name(self, raw_code, code, number):
"""Get the code name."""
return get_file_name(raw_code)
5 changes: 5 additions & 0 deletions ipykernel/control.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
"""A thread for a control channel."""
from threading import Thread

from tornado.ioloop import IOLoop


class ControlThread(Thread):
"""A thread for a control channel."""

def __init__(self, **kwargs):
"""Initialize the thread."""
Thread.__init__(self, name="Control", **kwargs)
self.io_loop = IOLoop(make_current=False)
self.pydev_do_not_trace = True
self.is_pydev_daemon_thread = True

def run(self):
"""Run the thread."""
self.name = "Control"
try:
self.io_loop.start()
Expand Down
1 change: 1 addition & 0 deletions ipykernel/datapub.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@


class ZMQDataPublisher(Configurable):
"""A zmq data publisher."""

topic = topic = CBytes(b"datapub")
session = Instance(Session, allow_none=True)
Expand Down
Loading