jupyterlab / extension-cookiecutter-ts

A cookiecutter recipe for JupyterLab extensions in Typescript
BSD 3-Clause "New" or "Revised" License
183 stars 88 forks source link

Creating a server extension with cookiecutter doesn't work #145

Closed raulotaolea closed 3 years ago

raulotaolea commented 3 years ago

Description

When I create a new extension with a server extension using typescript based cookiecutter in a new python environment, the example doesn't work. I don't know if I should do something in addition to build and install it.

Reproduce

I create a new python env:

conda create -n test -c conda-forge python=3.8 jupyterlab cookiecutter -y 
conda activate test

then I create a new extension using typescript cookiecutter:

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

with the following info:

author_name []: Author
author_email []: author@mail.com
python_name [myextension]: myextension
labextension_name [myextension]: myextension
project_short_description [A JupyterLab extension.]: 
has_server_extension [n]: y
has_binder [n]: n
repository [https://github.com/github_username/myextension]: 

Then I build the extension:

cd myextension
yarn build

and install it locally for development:

jupyter labextension develop --overwrite

And finally I start jupyterlab:

jupyter lab

When a new tab is created in the browser with the lab, I see the following error in the browser's console:

JupyterLab extension myextension is activated!
myextension/get_example?1620061204704:1 Failed to load resource: the server responded with a status of 404 (Not Found)

and this one in the server console:

[W 2021-05-03 19:00:07.593 ServerApp] 404 GET /api/contents/Untitled.ipynb?content=0&1620061207590 (::1): No such file or directory: Untitled.ipynb

Is this something wrong in the example? or I am not installing the server extension correctly?

Expected behavior

I was expecting the server extension being installed after doing:

jupyter labextension develop --overwrite

and returning:

This is /myextension/get_example endpoint!

Context

welcome[bot] commented 3 years ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

fcollonval commented 3 years ago

Hey, if you look at the readme generated for the extension, you have the development installation procedure described see that section.

From your description, you are missing the python package installation and the activation of the server extension.

You can also have a look at the example.

raulotaolea commented 3 years ago

thanks @fcollonval ! I am so used to the fact that in the prebuilt extensions you don't have to manually activate the extension, that I have taken it for granted.

One more question, is it necessary to do thepip install -e? I thought that with jupyter labextension develop was not necessary.

fcollonval commented 3 years ago

For a server extension, there are two parts: Typescript files for the frontend and Python for the backend (the server). You need pip install -e to install the server extension in dev mode. But the pip install logic will copy the frontend files. What you probably would like is to have the folder symlinked to your dev folder. This is what jupyter labextension develop does (you can look at the share/jupyter/labextensions content to see the difference); cf. documentation.

raulotaolea commented 3 years ago

oh, yes, what I wanted to say is that jupyter labextension develop calls internally to pip install -e and then creates the symlink.

fcollonval commented 3 years ago

Indeed I checked the code, you are correct pip install -e is called if the python package is not found when running jupyter labextension develop. I was not aware of that - thanks for pointing it to me.

fcollonval commented 3 years ago

I close this as answered. Regarding the call of pip install -e by jupyter labextension develop, it is best to ask the user to do first pip install -e as jupyter labextension develop will not work on Windows and because it is good to not hide too much what is going on.