Mode variable in the Resources class

I am still trying to figure out how to build the documentation locally such that it uses my locally built js library…

In that effort I was setting the environment variable BOKEH_RESOURCES to various modes of ‘inline’, ‘relative’, and ‘relative-div’ in addition to the environment variable BOKEH_ROOTDIR. Even though I had the BOKEH_RESOURCES set to ‘relative-dev’, I received an error from the console telling me that the setting of the root directory only makes sense if the resources mode is set to either ‘relative’ or ‘relative-dev’. In this case I had and the error was not making sense. I took a look at the Resources class and noticed that the error logic was using the function parameter vice the instance variable to do its logic. This does not seem correct. I have placed a smipplet of the relevant code below.

///// BEGIN SNIP (https://github.com/bokeh/bokeh/blob/master/bokeh/resources.py, line 110)

raise ValueError("wrong value for ‘mode’ parameter, expected ", “‘inline’, ‘cdn’, ‘server(-dev)’, ‘relative(-dev)’ or ‘absolute(-dev)’, got %r” % self.mode)

if self.root_dir and not mode.startswith(“relative”):

raise ValueError(“setting ‘root_dir’ makes sense only when ‘mode’ is set to ‘relative’”)

if self.version and not mode.startswith(‘cdn’):

raise ValueError(“setting ‘version’ makes sense only when ‘mode’ is set to ‘cdn’”)

if root_url and not mode.startswith(‘server’):

raise ValueError(“setting ‘root_url’ makes sense only when ‘mode’ is set to ‘server’”)

////// END SNIP

Should all of the cases of ‘mode’ in the above be replaced with ‘self.mode’? I would have made this an issue right away but I wanted to make sure there was no black magic at play here. If there is in fact an issue here, I will create an issue and then make a small pull request.

Also, as an aside, if anybody here can tell me how to build the docs using a the local version of the js library I would be very grateful. Setting the env var BOKEH_RESOURCES to ‘inline’ does not seem to do the trick.

Justace

Justace,

I apologize I was traveling out of the country yesterday I missed that this was about the built docs. We currently have a sphinx plugin that generates the plots, and it actually uses monkey patching to override the user-specified resources to always use CDN (because otherwise inline resources with alot of plots makes pages impossibly large). So the short answer is that there is no easy way to do that. Here are the places that the overriding happens:

  https://github.com/bokeh/bokeh/blob/master/bokeh/sphinxext/bokeh_plot.py#L285

  https://github.com/bokeh/bokeh/blob/master/bokeh/sphinxext/bokeh_plot.py#L301

As a short term fix you can edit that file to use whatever resources you want (probably relative). It would be great to make this a configurable option to the bokeh-plot Sphinx directive. It's not something I will be able to look at while I am traveling, but if you'd care to work on a PR that does that it would be very welcome.

Thanks,

Bryan

···

On Oct 20, 2015, at 5:18 AM, Justace Clutter <[email protected]> wrote:

I am still trying to figure out how to build the documentation locally such that it uses my locally built js library....

In that effort I was setting the environment variable BOKEH_RESOURCES to various modes of 'inline', 'relative', and 'relative-div' in addition to the environment variable BOKEH_ROOTDIR. Even though I had the BOKEH_RESOURCES set to 'relative-dev', I received an error from the console telling me that the setting of the root directory only makes sense if the resources mode is set to either 'relative' or 'relative-dev'. In this case I had and the error was not making sense. I took a look at the Resources class and noticed that the error logic was using the function parameter vice the instance variable to do its logic. This does not seem correct. I have placed a smipplet of the relevant code below.

///// BEGIN SNIP (https://github.com/bokeh/bokeh/blob/master/bokeh/resources.py, line 110)
raise ValueError("wrong value for 'mode' parameter, expected ", "'inline', 'cdn', 'server(-dev)', 'relative(-dev)' or 'absolute(-dev)', got %r" % self.mode)

if self.root_dir and not mode.startswith("relative"):
    raise ValueError("setting 'root_dir' makes sense only when 'mode' is set to 'relative'")

if self.version and not mode.startswith('cdn'):
    raise ValueError("setting 'version' makes sense only when 'mode' is set to 'cdn'")

if root_url and not mode.startswith('server'):
    raise ValueError("setting 'root_url' makes sense only when 'mode' is set to 'server'")
////// END SNIP

Should all of the cases of 'mode' in the above be replaced with 'self.mode'? I would have made this an issue right away but I wanted to make sure there was no black magic at play here. If there is in fact an issue here, I will create an issue and then make a small pull request.

Also, as an aside, if anybody here can tell me how to build the docs using a the local version of the js library I would be very grateful. Setting the env var BOKEH_RESOURCES to 'inline' does not seem to do the trick.

Justace

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected]o.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6701b9b8-0420-41d3-8bd7-bbe009866a8d%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Ahh, got it. Thanks for the pointer. I will look into that once I get this other PR finished.

As an aside. One of the functions that I generated to aid with my SegmentedColorMapper class takes a list of colors which can be a combination of tuple definitions, named colors, and even hes strings. It takes this input and then processes each entity into a hex string which can be passed to the JS in a consistent way. The function also checks to see if the palette is passed a single string if it is a named pre-defined palette, which it would then do the sane thing which is return the named palette in hex string mode. I think that this could be used anywhere that a palette is needed. To implement that I would suggest that the function be added to the palette.py file (I think that is the name of it). That would be a separate PR as well. I thought I would get your comments on that before I attempted to generate an issue and then fill it with a PR. The code is basically written as it already a part of my current PR.

Pros: the user has great flexibility in specifying a palette

Cons: the user has great flexibility in specifying a palette

example usage:

LinearColorMapper(palette = [black, ‘red’, ‘#ff00ee’, (100, 10, 37))

The LinearColorMapper class would then of course push this through the conversion function and the result would be equivalaltent to the following:

LinearColorMapper(palette = [’#000000’, ‘#ff0000’, ‘#ff00ee’, ‘#640A25’])

···

On Tue, Oct 20, 2015 at 2:38 PM, Bryan Van de Ven [email protected] wrote:

Justace,

I apologize I was traveling out of the country yesterday I missed that this was about the built docs. We currently have a sphinx plugin that generates the plots, and it actually uses monkey patching to override the user-specified resources to always use CDN (because otherwise inline resources with alot of plots makes pages impossibly large). So the short answer is that there is no easy way to do that. Here are the places that the overriding happens:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/sphinxext/bokeh_plot.py#L285](https://github.com/bokeh/bokeh/blob/master/bokeh/sphinxext/bokeh_plot.py#L285)



    [https://github.com/bokeh/bokeh/blob/master/bokeh/sphinxext/bokeh_plot.py#L301](https://github.com/bokeh/bokeh/blob/master/bokeh/sphinxext/bokeh_plot.py#L301)

As a short term fix you can edit that file to use whatever resources you want (probably relative). It would be great to make this a configurable option to the bokeh-plot Sphinx directive. It’s not something I will be able to look at while I am traveling, but if you’d care to work on a PR that does that it would be very welcome.

Thanks,

Bryan

On Oct 20, 2015, at 5:18 AM, Justace Clutter [email protected] wrote:

I am still trying to figure out how to build the documentation locally such that it uses my locally built js library…

In that effort I was setting the environment variable BOKEH_RESOURCES to various modes of ‘inline’, ‘relative’, and ‘relative-div’ in addition to the environment variable BOKEH_ROOTDIR. Even though I had the BOKEH_RESOURCES set to ‘relative-dev’, I received an error from the console telling me that the setting of the root directory only makes sense if the resources mode is set to either ‘relative’ or ‘relative-dev’. In this case I had and the error was not making sense. I took a look at the Resources class and noticed that the error logic was using the function parameter vice the instance variable to do its logic. This does not seem correct. I have placed a smipplet of the relevant code below.

///// BEGIN SNIP (https://github.com/bokeh/bokeh/blob/master/bokeh/resources.py, line 110)

raise ValueError("wrong value for ‘mode’ parameter, expected ", “‘inline’, ‘cdn’, ‘server(-dev)’, ‘relative(-dev)’ or ‘absolute(-dev)’, got %r” % self.mode)

if self.root_dir and not mode.startswith(“relative”):

raise ValueError("setting 'root_dir' makes sense only when 'mode' is set to 'relative'")

if self.version and not mode.startswith(‘cdn’):

raise ValueError("setting 'version' makes sense only when 'mode' is set to 'cdn'")

if root_url and not mode.startswith(‘server’):

raise ValueError("setting 'root_url' makes sense only when 'mode' is set to 'server'")

////// END SNIP

Should all of the cases of ‘mode’ in the above be replaced with ‘self.mode’? I would have made this an issue right away but I wanted to make sure there was no black magic at play here. If there is in fact an issue here, I will create an issue and then make a small pull request.

Also, as an aside, if anybody here can tell me how to build the docs using a the local version of the js library I would be very grateful. Setting the env var BOKEH_RESOURCES to ‘inline’ does not seem to do the trick.

Justace

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/6701b9b8-0420-41d3-8bd7-bbe009866a8d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/95F9452F-E36D-4980-A3A4-5AAF394365CF%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.