allow customized template and static file paths for the notebook web app #1135

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
4 participants
@timo
Contributor

timo commented Dec 9, 2011

Hello,

I'd like to distribute a few notebooks with my library that form kind of an interactive tutorial. I want to use images and styles from my website and do a few other small things. Thus it's very helpful to be able to specify overrides to the paths the notebook web app uses. Since it's buried in the NotebookApp, I thought using a global overrides dictionary might be a more elegant solution than to add parameters everywhere.

Please let me know what you think.

@ellisonbg

This comment has been minimized.

Show comment
Hide comment
@ellisonbg

ellisonbg Dec 9, 2011

Member

This should be handled instead by tying into IPython configuration system. But a question: are you copying over the contents of IPython's template and static dirs to your own?

Member

ellisonbg commented Dec 9, 2011

This should be handled instead by tying into IPython configuration system. But a question: are you copying over the contents of IPython's template and static dirs to your own?

@timo

This comment has been minimized.

Show comment
Hide comment
@timo

timo Dec 9, 2011

Contributor

i was going to do it like this:

  1. put all my changed files into a "overlay" folder distributed with my library
  2. upon launching the tutorial web app, copy all those overlay files to a new temporary folder
  3. symlink all of ipythons own files from static/ and templates/ over to the temporary folder
  4. launch the ipython notebook app

if there's a simpler way (for instance, a handler for static file serving that's aware of such overlay folder semantics and something similar for the template loader), I'd of course use that instead.

i haven't looked at the configuration system yet. If you want me to re-write the functionality with it, can you give me a pointer where to look first?

Contributor

timo commented Dec 9, 2011

i was going to do it like this:

  1. put all my changed files into a "overlay" folder distributed with my library
  2. upon launching the tutorial web app, copy all those overlay files to a new temporary folder
  3. symlink all of ipythons own files from static/ and templates/ over to the temporary folder
  4. launch the ipython notebook app

if there's a simpler way (for instance, a handler for static file serving that's aware of such overlay folder semantics and something similar for the template loader), I'd of course use that instead.

i haven't looked at the configuration system yet. If you want me to re-write the functionality with it, can you give me a pointer where to look first?

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Dec 10, 2011

Member

Two options:

  1. static_path and template_path should be Unicode traits of the NotebookApp, with config=True, a la:

    static_path = Unicode(os.path.join(os.path.dirname(__file__), "static"), config=True,
            help="""The path to static files for the notebook. Should contain all the javascript/css for notebook pages"""
    )
    

    Then NotebookApp should pass self.static_path and self.template_path to the NotebookWebApplication constructor.

  2. add settings=Dict(config=True,help=...) trait, which is empty by default, but can contain any overrides for the tornado settings. Then the NotebookWebApplication would initialize its default settings, and update with the settings of its parent, so that they might override.

I might prefer 2., because it allows further customization that IPython doesn't have to be aware of - the user can talk directly to tornado.

Member

minrk commented Dec 10, 2011

Two options:

  1. static_path and template_path should be Unicode traits of the NotebookApp, with config=True, a la:

    static_path = Unicode(os.path.join(os.path.dirname(__file__), "static"), config=True,
            help="""The path to static files for the notebook. Should contain all the javascript/css for notebook pages"""
    )
    

    Then NotebookApp should pass self.static_path and self.template_path to the NotebookWebApplication constructor.

  2. add settings=Dict(config=True,help=...) trait, which is empty by default, but can contain any overrides for the tornado settings. Then the NotebookWebApplication would initialize its default settings, and update with the settings of its parent, so that they might override.

I might prefer 2., because it allows further customization that IPython doesn't have to be aware of - the user can talk directly to tornado.

@timo

This comment has been minimized.

Show comment
Hide comment
@timo

timo Dec 10, 2011

Contributor

The code now works, with ipython notebook --NotebookApp.webapp_settings="{'static_path':'...'}" custom css files and other static things can be supplied.

I've written a bit of code that merges two folders (a base and an overlay) with as few symlinks as possible into a third, new folder. Should this functionality become part of the notebook app or should I keep it to myself?

Contributor

timo commented Dec 10, 2011

The code now works, with ipython notebook --NotebookApp.webapp_settings="{'static_path':'...'}" custom css files and other static things can be supplied.

I've written a bit of code that merges two folders (a base and an overlay) with as few symlinks as possible into a third, new folder. Should this functionality become part of the notebook app or should I keep it to myself?

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Dec 10, 2011

Member

Thanks, looks good. Thoughts, @ellisonbg?

You might post the extra code to the Cookbook.

Member

minrk commented Dec 10, 2011

Thanks, looks good. Thoughts, @ellisonbg?

You might post the extra code to the Cookbook.

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Dec 10, 2011

Member

Pinging @juliantaylor, as this might help him with packaging that doesn't like static files served from source trees.

Member

minrk commented Dec 10, 2011

Pinging @juliantaylor, as this might help him with packaging that doesn't like static files served from source trees.

@juliantaylor

This comment has been minimized.

Show comment
Hide comment
@juliantaylor

juliantaylor Dec 10, 2011

Contributor

I really like this change.
I even like it to go a little bit further by allowing to set the mathjax path.
this patch could be extended for that:
https://gist.github.com/1456031

Contributor

juliantaylor commented Dec 10, 2011

I really like this change.
I even like it to go a little bit further by allowing to set the mathjax path.
this patch could be extended for that:
https://gist.github.com/1456031

@timo

This comment has been minimized.

Show comment
Hide comment
@timo

timo Dec 10, 2011

Contributor

these changes are essentially untested, but I think they look okay. I'll be unavailable for a couple of hours now.

Contributor

timo commented Dec 10, 2011

these changes are essentially untested, but I think they look okay. I'll be unavailable for a couple of hours now.

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Dec 10, 2011

Member

Now we have a bit of a problem.

Handling mathjax separately means that currently setting the static path and putting mathjax in there will not result in local mathjax being found without separately specifying that mathjax is in there as well.

If you simply replace the hardcoded check in _mathjax_url_default for the old static path with a check for the user-set value (this should be done anyway), the need for the extra MathJax-related handling goes away. I'm not convinced (yet) that we need to handle our static files being spread across the filesystem, when a user-set static-dir covers that case.

Member

minrk commented Dec 10, 2011

Now we have a bit of a problem.

Handling mathjax separately means that currently setting the static path and putting mathjax in there will not result in local mathjax being found without separately specifying that mathjax is in there as well.

If you simply replace the hardcoded check in _mathjax_url_default for the old static path with a check for the user-set value (this should be done anyway), the need for the extra MathJax-related handling goes away. I'm not convinced (yet) that we need to handle our static files being spread across the filesystem, when a user-set static-dir covers that case.

@timo

This comment has been minimized.

Show comment
Hide comment
@timo

timo Dec 10, 2011

Contributor

the commits that were available before are now available in my branch "custom_mathjax_path":

https://github.com/timo/ipython/tree/custom_mathjax_path

Contributor

timo commented Dec 10, 2011

the commits that were available before are now available in my branch "custom_mathjax_path":

https://github.com/timo/ipython/tree/custom_mathjax_path

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Dec 10, 2011

Member

Great, looks good to me, now.

Member

minrk commented Dec 10, 2011

Great, looks good to me, now.

@timo

This comment has been minimized.

Show comment
Hide comment
@timo

timo Dec 11, 2011

Contributor

this last change just adds blocks for the titles to layout.html and notebook.html, so that branding would be easier without overriding the whole layout and notebook templates.

Contributor

timo commented Dec 11, 2011

this last change just adds blocks for the titles to layout.html and notebook.html, so that branding would be easier without overriding the whole layout and notebook templates.

@minrk

This comment has been minimized.

Show comment
Hide comment
@minrk

minrk Dec 11, 2011

Member

Just a note to keep track - the most recent change conflicts with #1125, which replaces the header text with an image, so whichever one of these we merge first will force the other to rebase.

Member

minrk commented Dec 11, 2011

Just a note to keep track - the most recent change conflicts with #1125, which replaces the header text with an image, so whichever one of these we merge first will force the other to rebase.

@ellisonbg

This comment has been minimized.

Show comment
Hide comment
@ellisonbg

ellisonbg Dec 11, 2011

Member

Please submit the changes to the header in a separate pull request. It will require further discussion that is unrelated to this one.

Member

ellisonbg commented Dec 11, 2011

Please submit the changes to the header in a separate pull request. It will require further discussion that is unrelated to this one.

@timo

This comment has been minimized.

Show comment
Hide comment
@timo

timo Dec 11, 2011

Contributor

i've reverted the commit. it wasn't so important anyway, can be done later without trouble

Contributor

timo commented Dec 11, 2011

i've reverted the commit. it wasn't so important anyway, can be done later without trouble

@minrk minrk closed this in f1fd9c8 Dec 12, 2011

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014

Merge PR 1135
settings for tornado web application can now be specified via the
NotebookApp.webapp_settings configurable.  This principally allows
users/admins to serve custom templates, css, and javascript, without
having to modify IPython's shipped sources.

closes #1135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment