Notebook: Question rather than issue: how is `static_path` implemented?

Created on 28 Sep 2019  路  4Comments  路  Source: jupyter/notebook

For a tornado application like Jupyter notebook, static_path usually refers to the location where Tornado searches for static files, using static_url and web.StaticFileHandler.

However, it is apparently impossible to have multiple static paths using the static_path setting. https://stackoverflow.com/questions/39388641/several-static-directories-for-tornado

Yet NotebookApp seems somehow able to use multiple static file paths:
https://github.com/jupyter/notebook/blob/70d74d21ac051fbeaa81d4ef4fff9fa759de96d7/notebook/notebookapp.py#L229
https://github.com/jupyter/notebook/blob/70d74d21ac051fbeaa81d4ef4fff9fa759de96d7/notebook/notebookapp.py#L1039

since its value is a list of strings, and not a single list.

I tried creating a traitlets-based Tornado application and set static_path to similarly be a List(Unicode()), but this lead to the error:
TypeError: expected str, bytes, or os.PathLike object, not list

which seems to confirm the claim that normally Tornado applications can only have one static directory. But in any case I was attempting to use the same workaround that Jupyter Notebook uses, but of course somehow Jupyter Notebook's workaround works, whereas this one doesn't.

Could I get a pointer to the relevant lines of code where support for multiple static paths is implemented in Jupyter notebook?

Searching with GitHub for static_path only returns the lines from notebookapp.py only returns the lines mentioned above, which would suggest that Notebook is passing this setting off to Tornado for direct consumption. However, my attempt to replicate this suggests that such a thing would not be possible, as does Ben Darnell's answer.

For the record I am trying to figure out a way to implement a similar feature in NBViewer, in case my motivation for wanting to understand how this is implemented in Notebook is relevant.

Most helpful comment

All 4 comments

Is it related somehow to this line in init_handlers?
https://github.com/jupyter/notebook/blob/70d74d21ac051fbeaa81d4ef4fff9fa759de96d7/notebook/notebookapp.py#L336

That seems similar to this StackOverflow answer here: https://stackoverflow.com/a/43560973/10634604 as well as Tornado developer Ben Darnell's answer mentioned already above.

I'll look into this more, but this looks like the right thing. Thank you so much for finding it for me! I really appreciate it!

Yes, it works perfectly! Thank you so much! I am very glad I don't have to reinvent the wheel for this.

Was this page helpful?
0 / 5 - 0 ratings