Support Jupyter Notebook 7 and enable JupyterLab debugger#81
Open
yufengzjj wants to merge 3 commits into
Open
Conversation
fix a bug when jupyter_core's dispatch to the jupyter-notebook script
fix IDA unexpected exit when shutdown in notebook
Collaborator
|
Hi! Thanks so much your contribution! I just wanted to let you know I've seen your patch and I'll be reviewing within the next two weeks. I quickly glanced at it and it looks good to me, but I'll check in more details as soon as I can. Cheers! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
%open_notebookto work on Notebook 7 (served byjupyter_server)in addition to the existing Notebook 6 path.
IDA's kernel can be debugged from the browser.
jupyter-notebookconsole script sostale scripts left behind by pip downgrades between 6 and 7 don't break
startup.
Notebook 7 compatibility (
ipyida/notebook.py)_list_running_servers()reads fromjupyter_server.serverapponNotebook >= 7 (the
notebook.notebookappmodule was removed) and fromnotebook.notebookappon 6.x._server_root_dir()normalises the root-dir field across servers(
root_diron jupyter_server,notebook_diron Notebook 6)._create_proxy_session()posts a session to/api/sessionsbound to theproxykernel before opening the page. The JupyterLab-based UI inNotebook 7 does not honour the legacy
?kernel_name=query string theway Notebook 6 did, so the kernel is now attached server-side. Harmless
on Notebook 6 (the existing session is reused).
_popen_python_module("notebook", ...)replaces_popen_python_module("jupyter", "notebook", ...). This bypassesjupyter_core's dispatch to thejupyter-notebookscript on PATH —pip downgrades between Notebook 7 and 6 can leave that script pointing
at the wrong module (e.g. 7's
notebook.appafter a downgrade to 6),triggering
ModuleNotFoundError: No module named 'notebook.app'.notebook/__main__.pyexists in both 6 and 7 and routes to the rightentry point.
_popen_python_module()is factored to use a shared_python_executable()helper that derives the real Python interpreter from
sys.prefix(
sys.executablein IDA isida{q,t}.exe, not Python).Debugger support
JupyterLab decides whether to show the Debug button purely from
kernel_info_reply.debugger/ kernelspec metadata, not from adebug_requestprobe. Three changes are needed to make it light up andactually work behind
jupyter_kernel_proxy:ensure_kernelspec_installed): patchmetadata.debugger = trueinto theproxykernelspec. The proxy shipswithout it, so the button stays greyed out.
ipyida/proxy_runner.py, new):jupyter_kernel_proxy.KernelProxyManager._send_proxy_kernel_infois a3s fallback that synthesises a minimal
kernel_info_replylacking thedebuggerfield. When a real kernel is already connected we suppressthe fallback so the front-end always sees the real reply. The proxy
kernelspec
argvis rewritten to launch viapython -m ipyida.proxy_runnerso the patch is applied.debugpy.configure(python=...)(ipyida/kernel.py,_configure_debugpy_python): clicking Debug runsdebugpy.listen(...)inside the kernel, which spawns the DAP adaptervia
subprocess.Popen([sys.executable, adapter_dir, ...]). In IDAsys.executable == idaq.exe, so the spawn launches another IDAinstance instead of the adapter and
endpoints_listener.accept()times out after 30s with
RuntimeError: timed out waiting for adapter to connect. Configuringdebugpy._config["python"]to the realinterpreter at kernel start fixes this.
Packaging (
setup.py)notebook7extra:notebook>=7,jupyter-server>=2,jupyter-client>=7.4.4,jupyter-kernel-proxy.notebookextra now pinsnotebook<7,jupyter-server<2,jupyter-client<7so the 6.x stack installs cleanly.jupyter-clientconstraint relaxed from<6.1.13to!=6.1.13— only the broken release needs to be excluded.Test
Tested on Python 3.12. IDA 9.0+ win11
pip install .[notebook7], run%open_notebookin IDA — browser opens, the cell uses IDA's kernel, and the Debug
toolbar button is enabled.
breakpoint within ~1s (no 30s timeout, no
timed out waiting for adapter to connect).pip install .[notebook]andnotebook==6.5.7,run
%open_notebook— the page loads against IDA's kernel as before(regression check for the 6.x path, including the
python -m notebookchange).
notebookfrom 7 to 6.5.7 in the same env (stalejupyter-notebookscript scenario) and run%open_notebook— nolonger fails with
ModuleNotFoundError: No module named 'notebook.app'.