Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server example doesn't work out of the box #151

Closed
DianeHu opened this issue Feb 24, 2021 · 15 comments · Fixed by #152
Closed

Server example doesn't work out of the box #151

DianeHu opened this issue Feb 24, 2021 · 15 comments · Fixed by #152

Comments

@DianeHu
Copy link

DianeHu commented Feb 24, 2021

Problem

I'm trying to write a server extension and followed the example of the server extension. I ran into some issues so I instead tried cloning this repo and directly installing the server extension example following the instructions in the README, but I'm still seeing the same errors.

Error

I'm getting 404s on the example endpoints:
image

Is there any additional setup that the README is missing to get the basic example working?

@fcollonval
Copy link
Member

Hey @DianeHu

Heads up: I assume you are using JupyterLab 3

404 is quite typical when the server extension is not enabled. You can check that by running jupyter server extension list.

If the extension is not listed, you need to enable it jupyter server extension enable --sys-prefix <python package name>.

If you want to develop your own server extension, I highly recommend you start it using the cookiecutter template (https://github.com/jupyterlab/extension-cookiecutter-ts) rather than copying the example. The template will ensure the naming coherence across the configuration files.

@DianeHu
Copy link
Author

DianeHu commented Feb 24, 2021

@fcollonval I just checked and it is enabled. I actually started my server extension with the cookiecutter template and copied over code from this example, which is why I thought maybe I'd gotten some config stuff wrong and tried using the example out the box. If the server extension is enabled, are there other common problems that could cause the 404s?

@DianeHu
Copy link
Author

DianeHu commented Feb 24, 2021

@fcollonval correction--the extension shows as enabled when I run jupyter server extension list, but when I run jupyter server extension enable --py --syx-prefix <package name> I get "The Python module tos_server_ext does not include any valid server extensions". This is true for both my own extension and the example extension.

@DianeHu
Copy link
Author

DianeHu commented Feb 24, 2021

It seems this is raised in https://github.com/jupyter/notebook/blob/master/notebook/serverextensions.py by if not hasattr(m, '_jupyter_server_extension_paths'):. This seems to be a method intended to be defined in __init__.py, which defines only

  • _jupyter_labextension_paths
  • _jupyter_server_extension_points
  • _load_jupyter_server_extension

right now. I defined the function as return [{"module": <package_name>}], copying _jupyter_server_extension_points, and was able to run the enable command. However, the 404 is still there.

@DianeHu
Copy link
Author

DianeHu commented Feb 24, 2021

I've found the problem. It seems running jlpm run build is insufficient, you have to run jupyter lab build before starting up the notebook again to get things to work properly.

@jld23
Copy link

jld23 commented Feb 25, 2021

@fcollonval, I'm having the same issues as @DianeHu (their tip on jupyter lab build saved me from pulling all my hair out). I started with the cookiecutter and based my extension off of this example.

(base) dsw@t7a397:~/source/github/sas_kernel_ext/jlab_sas_2_nb$ jupyter server extension list
\Config dir: /home/dsw/.jupyter

Config dir: /home/dsw/miniconda3/etc/jupyter
    jlab_ext_example enabled
    - Validating jlab_ext_example...
      jlab_ext_example 0.1.0 OK
    jlab_sas_2_nb enabled
    - Validating jlab_sas_2_nb...
      jlab_sas_2_nb 0.3.0 OK
    jupyterlab enabled
    - Validating jupyterlab...
      jupyterlab 3.0.7 OK
    nbclassic enabled
    - Validating nbclassic...
      nbclassic  OK

My extension throws 404 for every get and post request.

serverconnection.js:207 GET http://localhost:8888/jlab-sas-2-nb/convert?1614236560075 404 (Not Found)
index.js:31 TEST:::::Error on GET /jlab-sas-2-nb/convert.
SyntaxError: Unexpected token < in JSON at position 0

Do you have any tips on how to debug between the typescript and python or the common things that can be wrong given, the server extension is valid and I've run:
pip install -e . && jupyter labextension develop . --overwrite && jlpm run build && jupyter lab build --minimize=False

@jld23
Copy link

jld23 commented Feb 25, 2021

@DianeHu, My cookiecutter had the def _jupyter_server_extension_paths(): defined in __init__.py
If you don't answer the has_server_ext question as yes, the then function isn't included in __init__.py

@fcollonval
Copy link
Member

First of, small answer to @DianeHu

jupyter server extension enable --py --sys-prefix <package name> I get "The Python module tos_server_ext does not include any valid server extensions".

You should drop the --py.


jupyter lab build is not be needed any more. As you can see in the cookiecutter template test:

https://github.com/jupyterlab/extension-cookiecutter-ts/blob/a161a92deee694d42f52a9769ff76bacc969175f/.github/workflows/main.yml#L80

@DianeHu without the trace of the command you are running I won't be able to help you. Could you provide the full details: OS, Python version, JupyterLab version, command use to run the server and its trace?


@jld23 you are not using the latest cookiecutter version as the entry point should be _jupyter_server_extension_points (_jupyter_server_extension_paths is for JupyterLab < 3). So please be sure to use the latest cookiecutter

cookiecutter https://github.com/jupyterlab/extension-cookiecutter-ts --checkout 3.0

@DianeHu
Copy link
Author

DianeHu commented Feb 25, 2021

@fcollonval I'm not sure if there's some other issue then but jupyter lab build was the only thing that got it to work for me. I'm running MacOS Catalina 10.15.7, Python 3.9.2, JupyterLab 3.0.9. I can't seem to reproduce the error anymore, but here are the steps I ran previously:

  1. Create a new conda environment with conda create -n jupyterlab-ext --override-channels --strict-channel-priority -c conda-forge -c anaconda jupyterlab=3 cookiecutter nodejs jupyter-packaging git, per https://jupyterlab.readthedocs.io/en/stable/extension/extension_tutorial.html#extension-tutorial
  2. Activate the environment
  3. Go to server-extension (the directory for this example extension), or a plain cookiecutter extension with has_server_ext = yes (both produced this error yesterday but seem to be fine today?)
  4. Run pip install -e .
  5. Run jupyter labextension develop . --overwrite
  6. Run jlpm run build
  7. Run jupyter lab in the same conda environment
  8. In the jupyterlab instance that opens up, in the console it showed the 404s in the image I linked in my original question up top. These went away after I stopped the notebook, ran jupyter lab build, and then restarted the notebook.

Maybe @jld23 has a stack trace? His error is the exact same as the one I got with the unexpected JSON token etc.

@jld23
Copy link

jld23 commented Feb 26, 2021

@fcollonval Thank you so much for the help! When I created a new extension cookiecutter and copied my code everything worked locally. I'm still getting the 404 inside of binder

The server extension is installed, inside binder, so I'm not sure where to go next.

dsw@d5598019d7d3:~$ jupyter server extension list
Config dir: /home/dsw/.jupyter

Config dir: /srv/conda/envs/notebook/etc/jupyter
    jupyterlab enabled
    - Validating jupyterlab...
      jupyterlab 3.0.5 OK
    nbclassic enabled
    - Validating nbclassic...
      nbclassic  OK
    sas2nb enabled
    - Validating sas2nb...
      sas2nb 0.1.0 OK

Config dir: /usr/local/etc/jupyter

@DianeHu, I don't have a stack trace. If you can't reproduce, does that mean it is working as designed?

@DianeHu
Copy link
Author

DianeHu commented Feb 26, 2021

@jld23 another engineer on my team noticed that the MANIFEST.in file for this example isn't exporting the public directory--maybe check that?

@fcollonval
Copy link
Member

@jld23 There is some troubles with binder and JupyterLab 3. Binder does not support the new Jupyter server used by JupyterLab 3 by default. You can support binder by adding old entry points. See that PR for an example: jupyterlab/jupyterlab-git#863

@fcollonval
Copy link
Member

I can't seem to reproduce the error anymore

Thanks for taking the time to details your steps @DianeHu. I'm happy you got it working, just sad that we did not nail the reason.

@DianeHu
Copy link
Author

DianeHu commented Feb 28, 2021

@fcollonval I think the issue might be the MANIFEST.in--if you use pip install -e . the symlink makes it so it isn't an issue, but I think if you do pip install ., then because it's missing exporting the public directory, you get the 404s

@fcollonval
Copy link
Member

@fcollonval I think the issue might be the MANIFEST.in--if you use pip install -e . the symlink makes it so it isn't an issue, but I think if you do pip install ., then because it's missing exporting the public directory, you get the 404s

Ho yes you are right. Thank you for nailing that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants