In order to help automate and simplify the generation of Bokeh documentation, several Sphinx extensions have been created. Most of these will not be of general interest, except for bokeh.sphinxext.bokeh_plot, which allows anyone to include and embed bokeh plots directly in their own Sphinx docs.
Integrate Bokeh extensions into Sphinx autodoc.
Ensures that autodoc directives such as autoclass
automatically
use Bokeh-specific directives (e.g., bokeh-prop
and bokeh-model
)
when appropriate.
Generate a gallery of Bokeh plots from a configuration file.
Simplify linking to Bokeh Github resources.
This module proved four new roles that can be uses to easily link to various resources in the Bokeh Github repository:
:bokeh-commit:
: link to a specific commit
:bokeh-issue:
: link to an issue
:bokeh-milestone:
: link to a milestone page
:bokeh-pull:
: link to a pull request
Examples
The following code:
The repo history shows that :bokeh-commit:`bf19bcb` was made in
in :bokeh-pull:`1698`,which closed :bokeh-issue:`1694` as part of
:bokeh-milestone:`0.8`.
yields the output:
The repo history shows that commit bf19bcb was made in in pull request 1698,which closed issue 1694 as part of milestone 0.8.
Thoroughly document Bokeh model classes.
The bokeh-model
directive will automatically document
all the attributes (including Bokeh properties) of a Bokeh
model class. A JSON prototype showing all the possible
JSON fields will also be generated.
This directive takes the path to a Bokeh model class as an argument:
.. bokeh-model:: bokeh.sphinxext.sample.Foo
Examples
For the following definition of bokeh.sphinxext.sample.Foo
:
class Foo(PlotObject):
''' This is a Foo model. '''
index = Either(Auto, Enum('abc', 'def', 'xzy'), help="doc for index")
value = Tuple(Float, Float, help="doc for value")
the above usage yields the output:
- class
Foo
(**kwargs)¶Bases:
bokeh.plot_object.PlotObject
This is a Foo model.
[ { "attributes": { "doc": null, "id": "cf95ef02-eaad-4b74-b849-a86d28843a09", "index": "auto", "name": null, "tags": [], "value": null }, "id": "cf95ef02-eaad-4b74-b849-a86d28843a09", "type": "Foo" } ]
Generate color representations of all known Bokeh palettes.
This directive takes no arguments.
Include Bokeh plots in Sphinx HTML documentation.
For other output types, the placeholder text [graph]
will
be generated.
The bokeh-plot
directive can be used by either supplying:
A path to a source file as the argument to the directive:
.. bokeh-plot:: path/to/plot.py
Inline code as the content of the directive:
.. bokeh-plot::
from bokeh.plotting import figure, output_file, show
output_file("example.html")
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
p = figure(title="example", plot_width=300, plot_height=300)
p.line(x, y, line_width=2)
p.circle(x, y, size=10, fill_color="white")
show(p)
This directive also works in conjunction with Sphinx autodoc, when used in docstrings.
The bokeh-plot
directive accepts the following options:
Examples
The inline example code above produces the following output:
from bokeh.plotting import figure, output_file, show
output_file("example.html")
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
p = figure(title="example", plot_width=300, plot_height=300)
p.line(x, y, line_width=2)
p.circle(x, y, size=10, fill_color="white")
show(p)
Thoroughly document Bokeh property attributes.
The bokeh-prop
directive generates useful type information
for the property attribute, including cross links to the relevant
property types. Additionally, any per-attribute docstrings are
also displayed.
This directive takes the path to an attribute on a Bokeh model class as an argument:
.. bokeh-prop:: bokeh.sphinxext.sample.Bar.thing
Examples
For the following definition of bokeh.sphinxext.sample.Bar
:
class Bar(PlotObject):
''' This is a Bar model. '''
thing = List(Int, help="doc for thing")
the above usage yields the output:
Display code blocks in collapsible sections when outputting to HTML.
This directive takes a heading to use for the collapsible code block:
.. collapsible-code-block:: python
:heading: Some Code
from __future__ import print_function
print("Hello, Bokeh!")
This directive is identical to the standard code-block
directive
that Sphinx supplies, with the addition of one new option:
Examples
The inline example code above produces the following output:
from __future__ import print_function
print("Hello, Bokeh!")