Skip to content

Commit

Permalink
Merge branch 'main' into sync-sockets-threads
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk authored Oct 25, 2024
2 parents 53b2911 + 48e39cf commit 0ad07bb
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 98 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.12"]
python-version: ["3.9", "3.13"]
include:
- os: windows-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "pypy-3.9"
- os: macos-latest
python-version: "3.10"
- os: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -150,6 +150,7 @@ jobs:
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
with:
dependency_type: minimum
python_version: "3.9"

- name: List installed packages
run: |
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: nightly build and upload
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"

defaults:
run:
shell: bash -eux {0}

jobs:
build:
runs-on: "ubuntu-latest"
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Build
run: |
python -m pip install build
python -m build
- name: Upload wheel
uses: scientific-python/upload-nightly-action@82396a2ed4269ba06c6b2988bb4fd568ef3c3d6b # 0.6.1
with:
artifacts_path: dist
anaconda_nightly_upload_token: ${{secrets.UPLOAD_TOKEN}}
51 changes: 47 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,53 @@

<!-- <START NEW CHANGELOG ENTRY> -->

## 7.0.0a0

([Full Changelog](https://github.com/ipython/ipykernel/compare/v6.29.3...314cc49da6e7d69d74f4741d4ea6568e926d1819))

### Enhancements made

- Detect parent change in more cases on unix [#1271](https://github.com/ipython/ipykernel/pull/1271) ([@bluss](https://github.com/bluss))
- Kernel subshells (JEP91) implementation [#1249](https://github.com/ipython/ipykernel/pull/1249) ([@ianthomas23](https://github.com/ianthomas23))
- Remove control queue [#1210](https://github.com/ipython/ipykernel/pull/1210) ([@ianthomas23](https://github.com/ianthomas23))
- Replace Tornado with AnyIO [#1079](https://github.com/ipython/ipykernel/pull/1079) ([@davidbrochart](https://github.com/davidbrochart))

### Bugs fixed

- Fix eventloop integration with anyio [#1265](https://github.com/ipython/ipykernel/pull/1265) ([@ianthomas23](https://github.com/ianthomas23))
- Explicitly close memory object streams [#1253](https://github.com/ipython/ipykernel/pull/1253) ([@ianthomas23](https://github.com/ianthomas23))
- Fixed error accessing sys.stdout/sys.stderr when those are None [#1247](https://github.com/ipython/ipykernel/pull/1247) ([@gregory-shklover](https://github.com/gregory-shklover))
- Correctly handle with_cell_id in async do_execute [#1227](https://github.com/ipython/ipykernel/pull/1227) ([@ianthomas23](https://github.com/ianthomas23))
- Do not import debugger/debugpy unless needed [#1223](https://github.com/ipython/ipykernel/pull/1223) ([@krassowski](https://github.com/krassowski))
- Allow datetime or str in test_sequential_control_messages [#1219](https://github.com/ipython/ipykernel/pull/1219) ([@ianthomas23](https://github.com/ianthomas23))
- Fix side effect import for pickleutil [#1217](https://github.com/ipython/ipykernel/pull/1217) ([@blink1073](https://github.com/blink1073))

### Maintenance and upkeep improvements

- Remove direct use of asyncio [#1266](https://github.com/ipython/ipykernel/pull/1266) ([@davidbrochart](https://github.com/davidbrochart))
- Specify argtypes when using macos msg [#1264](https://github.com/ipython/ipykernel/pull/1264) ([@ianthomas23](https://github.com/ianthomas23))
- Forward port changelog for 6.29.4 and 5 to main branch [#1263](https://github.com/ipython/ipykernel/pull/1263) ([@ianthomas23](https://github.com/ianthomas23))
- Ignore warning from trio [#1262](https://github.com/ipython/ipykernel/pull/1262) ([@ianthomas23](https://github.com/ianthomas23))
- Build docs on ubuntu [#1257](https://github.com/ipython/ipykernel/pull/1257) ([@blink1073](https://github.com/blink1073))
- Avoid a DeprecationWarning on Python 3.13+ [#1248](https://github.com/ipython/ipykernel/pull/1248) ([@hroncok](https://github.com/hroncok))
- Catch IPython 8.24 DeprecationWarnings [#1242](https://github.com/ipython/ipykernel/pull/1242) ([@s-t-e-v-e-n-k](https://github.com/s-t-e-v-e-n-k))
- Update version to 7.0.0 [#1241](https://github.com/ipython/ipykernel/pull/1241) ([@mlucool](https://github.com/mlucool))
- Add compat with pytest 8 [#1231](https://github.com/ipython/ipykernel/pull/1231) ([@blink1073](https://github.com/blink1073))
- Set all min deps [#1229](https://github.com/ipython/ipykernel/pull/1229) ([@blink1073](https://github.com/blink1073))
- Update Release Scripts [#1221](https://github.com/ipython/ipykernel/pull/1221) ([@blink1073](https://github.com/blink1073))

### Documentation improvements

- Forward port changelog for 6.29.4 and 5 to main branch [#1263](https://github.com/ipython/ipykernel/pull/1263) ([@ianthomas23](https://github.com/ianthomas23))

### Contributors to this release

([GitHub contributors page for this release](https://github.com/ipython/ipykernel/graphs/contributors?from=2024-02-26&to=2024-10-22&type=c))

[@agronholm](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Aagronholm+updated%3A2024-02-26..2024-10-22&type=Issues) | [@blink1073](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Ablink1073+updated%3A2024-02-26..2024-10-22&type=Issues) | [@bluss](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Abluss+updated%3A2024-02-26..2024-10-22&type=Issues) | [@Carreau](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3ACarreau+updated%3A2024-02-26..2024-10-22&type=Issues) | [@davidbrochart](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Adavidbrochart+updated%3A2024-02-26..2024-10-22&type=Issues) | [@gregory-shklover](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Agregory-shklover+updated%3A2024-02-26..2024-10-22&type=Issues) | [@hroncok](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Ahroncok+updated%3A2024-02-26..2024-10-22&type=Issues) | [@ianthomas23](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Aianthomas23+updated%3A2024-02-26..2024-10-22&type=Issues) | [@ivanov](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Aivanov+updated%3A2024-02-26..2024-10-22&type=Issues) | [@krassowski](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Akrassowski+updated%3A2024-02-26..2024-10-22&type=Issues) | [@maartenbreddels](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Amaartenbreddels+updated%3A2024-02-26..2024-10-22&type=Issues) | [@minrk](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Aminrk+updated%3A2024-02-26..2024-10-22&type=Issues) | [@mlucool](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Amlucool+updated%3A2024-02-26..2024-10-22&type=Issues) | [@s-t-e-v-e-n-k](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3As-t-e-v-e-n-k+updated%3A2024-02-26..2024-10-22&type=Issues)

<!-- <END NEW CHANGELOG ENTRY> -->

## 6.29.5

([Full Changelog](https://github.com/ipython/ipykernel/compare/v6.29.4...1e62d48298e353a9879fae99bc752f9bb48797ef))
Expand All @@ -20,8 +67,6 @@

[@blink1073](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Ablink1073+updated%3A2024-03-27..2024-06-29&type=Issues) | [@ianthomas23](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Aianthomas23+updated%3A2024-03-27..2024-06-29&type=Issues)

<!-- <END NEW CHANGELOG ENTRY> -->

## 6.29.4

([Full Changelog](https://github.com/ipython/ipykernel/compare/v6.29.3...1cea5332ffc37f32e8232fd2b8b8ddd91b2bbdcf))
Expand Down Expand Up @@ -67,8 +112,6 @@

[@blink1073](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Ablink1073+updated%3A2024-02-07..2024-02-26&type=Issues) | [@ccordoba12](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Accordoba12+updated%3A2024-02-07..2024-02-26&type=Issues) | [@jdranczewski](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Ajdranczewski+updated%3A2024-02-07..2024-02-26&type=Issues) | [@joouha](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Ajoouha+updated%3A2024-02-07..2024-02-26&type=Issues) | [@krassowski](https://github.com/search?q=repo%3Aipython%2Fipykernel+involves%3Akrassowski+updated%3A2024-02-07..2024-02-26&type=Issues)

<!-- <END NEW CHANGELOG ENTRY> -->

## 6.29.2

([Full Changelog](https://github.com/ipython/ipykernel/compare/v6.29.1...d45fe71990d26c0bd5b7b3b2a4ccd3d1f6609899))
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import os
import shutil
from pathlib import Path
from typing import Any, Dict, List
from typing import Any

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -70,7 +70,7 @@
# built documents.
#

version_ns: Dict[str, Any] = {}
version_ns: dict[str, Any] = {}
here = Path(__file__).parent.resolve()
version_py = Path(here) / os.pardir / "ipykernel" / "_version.py"
with open(version_py) as f:
Expand Down Expand Up @@ -159,7 +159,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path: List[str] = []
html_static_path: list[str] = []

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -226,7 +226,7 @@

# -- Options for LaTeX output ---------------------------------------------

latex_elements: Dict[str, object] = {}
latex_elements: dict[str, object] = {}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
Expand Down
34 changes: 2 additions & 32 deletions examples/embedding/inprocess_qtconsole.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
"""An in-process qt console app."""
import os
import sys

import tornado
from IPython.lib import guisupport
from qtconsole.inprocess import QtInProcessKernelManager
from qtconsole.rich_ipython_widget import RichIPythonWidget

assert tornado.version_info >= (6, 1)


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


def init_asyncio_patch():
"""set default asyncio policy to be compatible with tornado
Tornado 6 (at least) is not compatible with the default
asyncio implementation on Windows
Pick the older SelectorEventLoopPolicy on Windows
if the known-incompatible default policy is in use.
do this as early as possible to make it a low priority and overridable
ref: https://github.com/tornadoweb/tornado/issues/2608
FIXME: if/when tornado supports the defaults in asyncio,
remove and bump tornado requirement for py38
"""
if (
sys.platform.startswith("win")
and sys.version_info >= (3, 8)
and tornado.version_info < (6, 1)
):
import asyncio

try:
from asyncio import WindowsProactorEventLoopPolicy, WindowsSelectorEventLoopPolicy
except ImportError:
pass
# not affected
else:
if type(asyncio.get_event_loop_policy()) is WindowsProactorEventLoopPolicy:
# WindowsProactorEventLoopPolicy is not compatible with tornado 6
# fallback to the pre-3.8 default of Selector
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())


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

init_asyncio_patch()
app = guisupport.get_app_qt4()

# Create an in-process kernel
Expand Down
5 changes: 2 additions & 3 deletions ipykernel/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
store the current version info of the server.
"""
import re
from typing import List

# Version string must appear intact for hatch versioning
__version__ = "7.0.0"
__version__ = "7.0.0a0"

# Build up version_info tuple for backwards compatibility
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)"
match = re.match(pattern, __version__)
assert match is not None
parts: List[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
parts: list[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
if match["rest"]:
parts.append(match["rest"])
version_info = tuple(parts)
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _reset_tcp_pos(self):

def _put_message(self, raw_msg):
self.log.debug("QUEUE - _put_message:")
msg = t.cast(t.Dict[str, t.Any], jsonapi.loads(raw_msg))
msg = t.cast(dict[str, t.Any], jsonapi.loads(raw_msg))
if msg["type"] == "event":
self.log.debug("QUEUE - received event:")
self.log.debug(msg)
Expand Down
4 changes: 1 addition & 3 deletions ipykernel/inprocess/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from typing import List

from jupyter_client.channelsabc import HBChannelABC

# -----------------------------------------------------------------------------
Expand All @@ -15,7 +13,7 @@
class InProcessChannel:
"""Base class for in-process channels."""

proxy_methods: List[object] = []
proxy_methods: list[object] = []

def __init__(self, client=None):
"""Initialize the channel."""
Expand Down
18 changes: 12 additions & 6 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""The IPython kernel implementation"""

from __future__ import annotations

import builtins
import gc
import getpass
Expand All @@ -16,7 +18,7 @@
from IPython.core import release
from IPython.utils.tokenutil import line_at_cursor, token_at_cursor
from jupyter_client.session import extract_header
from traitlets import Any, Bool, HasTraits, Instance, List, Type, observe, observe_compat
from traitlets import Any, Bool, HasTraits, Instance, List, Type, default, observe, observe_compat

from .comm.comm import BaseComm
from .comm.manager import CommManager
Expand Down Expand Up @@ -46,7 +48,7 @@ def _create_comm(*args, **kwargs):

# there can only be one comm manager in a ipykernel process
_comm_lock = threading.Lock()
_comm_manager: t.Optional[CommManager] = None
_comm_manager: CommManager | None = None


def _get_comm_manager(*args, **kwargs):
Expand Down Expand Up @@ -84,7 +86,11 @@ def _user_module_changed(self, change):
if self.shell is not None:
self.shell.user_module = change["new"]

user_ns = Instance(dict, args=None, allow_none=True)
user_ns = Instance("collections.abc.Mapping", allow_none=True)

@default("user_ns")
def _default_user_ns(self):
return dict()

@observe("user_ns")
@observe_compat
Expand Down Expand Up @@ -353,7 +359,7 @@ async def do_execute(

self._forward_input(allow_stdin)

reply_content: t.Dict[str, t.Any] = {}
reply_content: dict[str, t.Any] = {}
if hasattr(shell, "run_cell_async") and hasattr(shell, "should_run_async"):
run_cell = shell.run_cell_async
should_run_async = shell.should_run_async
Expand Down Expand Up @@ -559,7 +565,7 @@ def do_inspect(self, code, cursor_pos, detail_level=0, omit_sections=()):
"""Handle code inspection."""
name = token_at_cursor(code, cursor_pos)

reply_content: t.Dict[str, t.Any] = {"status": "ok"}
reply_content: dict[str, t.Any] = {"status": "ok"}
reply_content["data"] = {}
reply_content["metadata"] = {}
assert self.shell is not None
Expand Down Expand Up @@ -755,7 +761,7 @@ def init_closure(self: threading.Thread, *args, **kwargs):
threading.Thread.run = run_closure # type:ignore[method-assign]

def _clean_thread_parent_frames(
self, phase: t.Literal["start", "stop"], info: t.Dict[str, t.Any]
self, phase: t.Literal["start", "stop"], info: dict[str, t.Any]
):
"""Clean parent frames of threads which are no longer running.
This is meant to be invoked by garbage collector callback hook.
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def _init_asyncio_patch(self):
where asyncio.ProactorEventLoop supports add_reader and friends.
"""
if sys.platform.startswith("win") and sys.version_info >= (3, 8):
if sys.platform.startswith("win"):
import asyncio

try:
Expand Down
Loading

0 comments on commit 0ad07bb

Please sign in to comment.