jupyter-server / jupyter_server

The backend—i.e. core services, APIs, and REST endpoints—to Jupyter web applications.
https://jupyter-server.readthedocs.io
BSD 3-Clause "New" or "Revised" License
484 stars 293 forks source link

running an `ExtensionApp` module as main (eg `python -m foo.fooapp`) results in keyerror #821

Open telamonian opened 2 years ago

telamonian commented 2 years ago

Description

launching jupyterlab via

python -m jupyterlab.labapp --myargfoo --myargbar

used to work. Now it doesn't.

The problem traces back to the initialize function:

https://github.com/jupyter-server/jupyter_server/blob/6d84507500878236ea451ac040264ce641fd17ae/jupyter_server/serverapp.py#L2389-L2393

In my case, starter_extension == "lab". Starting lab using the jupyter lab entry point correctly populates the self.extension_manager.extension_points dict with a lab key. However, starting lab using the python -m jupyterlab.labapp ... cmd populates the self.extension_manager.extension_points dict with a __main__ key (same value either way).

Reproduce

Install jlab and try running the above python -m ... command

Expected behavior

Launching an ExtensionApp via python -m ... and related methods should work as previously

Context

Here's the relevant output from my terminal

(jup-venv) tels_macbook:jup-venv tel$ python -m jupyterlab.labapp --dev-mode --watch
[W 2022-04-29 20:48:21.423 ServerApp] The module 'lab' could not be found. Are you sure the extension is installed?
[W 2022-04-29 20:48:21.424 ServerApp] The module 'nbclassic' could not be found. Are you sure the extension is installed?
[I 2022-04-29 20:48:21.853 ServerApp] notebook_shim | extension was successfully linked.
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/tel/usr/venv/jup-venv/git/jup-venv/jupyterlab/labapp.py", line 758, in <module>
    main()
  File "/Users/tel/usr/venv/jup-venv/lib/python3.9/site-packages/jupyter_server/extension/application.py", line 587, in launch_instance
    serverapp = cls.initialize_server(argv=args)
  File "/Users/tel/usr/venv/jup-venv/lib/python3.9/site-packages/jupyter_server/extension/application.py", line 557, in initialize_server
    serverapp.initialize(
  File "/Users/tel/usr/venv/jup-venv/lib/python3.9/site-packages/traitlets/config/application.py", line 88, in inner
    return method(app, *args, **kwargs)
  File "/Users/tel/usr/venv/jup-venv/lib/python3.9/site-packages/jupyter_server/serverapp.py", line 2402, in initialize
    point = self.extension_manager.extension_points[starter_extension]
KeyError: 'lab'
mpderbec commented 1 year ago

Is there a workaround for this issue? Is there any other way to launch Jupyter Lab server in a debugger like IntelliJ?

mpderbec commented 1 year ago

I was able to get past this by explicitly enabling the jupyterlab extension (via terminal) before launching:

jupyter server extension enable jupyterlab