Skip to content

Commit

Permalink
Bryanv/sphinxext (bokeh#8665)
Browse files Browse the repository at this point in the history
* clean up bokeh_enum.py

* add bokeh.sphinxext.bokeh_color to refguide

* clean up bokeh_autodoc.py

* clean up bokeh_color.py

* clean up bokeh_directive.py

* clean up bokeh_github.py

* clean up and add bokeh_jinja.py

* clean up bokeh_model.py

* clean up and add bokeh_options.py

* update outdated intersphinx URLs

* clean up bokeh_palette_group.py

* clean up bokeh_palette.py

* clean up bokeh_prop.py

* clean up bokeh_releases.py

* clean up bokeh_sitemap.py

* clean up collapsible_code_block.py

* clean up example_handler.py

* clean up sample.py

* don't use PackageLoader for templates

* remove cruft from makefile

* update bokeh_gallery to generate .rst detail files at startup

* simplify bokeh-plot and always use relative links to scripts

* migration notes
  • Loading branch information
bryevdv authored Feb 18, 2019
1 parent 4c61163 commit b8b604c
Show file tree
Hide file tree
Showing 29 changed files with 364 additions and 354 deletions.
3 changes: 2 additions & 1 deletion bokeh/core/has_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,12 +656,13 @@ def _clone(self):
'''

# The "../../" is needed for bokeh-plot to construct the correct path to examples
_EXAMPLE_TEMPLATE = '''
Example
-------
.. bokeh-plot:: ../%(path)s
.. bokeh-plot:: ../../%(path)s
:source-position: below
'''
Expand Down
10 changes: 10 additions & 0 deletions bokeh/sphinxext/_templates/gallery_detail.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:orphan:

.. index::
single: examples; {{ filename }}

{{ filename }}
{{ '-' * filename|length }}

.. bokeh-plot:: {{ source_path }}
:source-position: below
1 change: 1 addition & 0 deletions bokeh/sphinxext/_templates/jinja_detail.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.. data:: {{ name }}
:module: {{ module }}
:annotation: = {{ objrepr }}
{% if noindex %}:noindex:{% endif %}

{% if doc %}{{ doc|indent(4) }}{% endif %}

Expand Down
22 changes: 17 additions & 5 deletions bokeh/sphinxext/bokeh_autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
""" Integrate Bokeh extensions into Sphinx autodoc.
''' 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.
Ensures that autodoc directives such as ``autoclass`` automatically make use of
Bokeh-specific directives when appropriate. The following Bokeh extensions are
configured:
"""
* :ref:`bokeh.sphinxext.bokeh_color`
* :ref:`bokeh.sphinxext.bokeh_enum`
* :ref:`bokeh.sphinxext.bokeh_model`
* :ref:`bokeh.sphinxext.bokeh_prop`
'''

#-----------------------------------------------------------------------------
# Boilerplate
Expand Down Expand Up @@ -65,6 +70,12 @@ class ColorDocumenter(ModuleLevelDocumenter):
def can_document_member(cls, member, membername, isattr, parent):
return isinstance(member, Color)

# We don't need/want anything from the actual NamedColor class
def add_content(self, more_content, no_docstring=False):
pass
def get_object_members(self, want_all):
return False, []

class EnumDocumenter(ModuleLevelDocumenter):
directivetype = 'bokeh-enum'
objtype = 'enum'
Expand Down Expand Up @@ -94,6 +105,7 @@ def can_document_member(cls, member, membername, isattr, parent):
return isinstance(member, class_types) and issubclass(member, Model)

def setup(app):
''' Required Sphinx extension setup function. '''
app.add_autodocumenter(ColorDocumenter)
app.add_autodocumenter(EnumDocumenter)
app.add_autodocumenter(PropDocumenter)
Expand Down
25 changes: 18 additions & 7 deletions bokeh/sphinxext/bokeh_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
""" Document Bokeh color objects.
''' Document Bokeh named colors.
The ``bokeh-color`` directive generates a color swatch for named colors
in the ``bokeh.colors`` module:
The ``bokeh-color`` directive accepts a named color as its argument:
.. code-block:: rest
.. bokeh-color:: aliceblue
and generates a labeled color swatch as output.
.. bokeh-color:: aliceblue
"""
The ``bokeh-color`` direction may be used explicitly, but it can also be used
in conjunction with the :ref:`bokeh.sphinxext.bokeh_autodoc` extension.
'''

#-----------------------------------------------------------------------------
# Boilerplate
Expand All @@ -29,6 +37,7 @@

# External imports
from docutils import nodes
from docutils.parsers.rst.directives import unchanged

# Bokeh imports
from bokeh.colors import named
Expand All @@ -55,19 +64,21 @@

class BokehColorDirective(BokehDirective):

has_content = True
has_content = False
required_arguments = 1
optional_arguments = 2
option_spec = {
'module': unchanged,
}

def run(self):

color = self.arguments[0]

html = COLOR_DETAIL.render(color=getattr(named, color).to_css(), text=color)
node = nodes.raw('', html, format="html")
return [node]

def setup(app):
''' Required Sphinx extension setup function. '''
app.add_directive_to_domain('py', 'bokeh-color', BokehColorDirective)

#-----------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions bokeh/sphinxext/bokeh_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
'''
''' Provide a base class and useful functions for Bokeh Sphinx directives.
'''

Expand Down Expand Up @@ -41,7 +41,7 @@
r'''^ ([\w.]*\.)? # class name(s)
(\w+) \s* # thing name
(?: \((.*)\) # optional: arguments
(?:\s* -> \s* (.*))? # return annotation
(?:\s* -> \s* (.*))? # return annotation
)? $ # and nothing more
''', re.VERBOSE)

Expand Down
48 changes: 27 additions & 21 deletions bokeh/sphinxext/bokeh_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,42 @@
#
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------
""" Thoroughly document Bokeh enumerations
''' Thoroughly document Bokeh enumerations
The ``bokeh-enum`` directive generates useful type information
for the enumeration, including all the allowable values. If the
number of values is large, the full list is put in a collapsible
code block.
The ``bokeh-enum`` directive generates useful documentation for enumerations,
including all the allowable values. If the number of values is large, the full
list is put in a collapsible code block.
This directive takes the name of a Bokeh enum variable and the
module to find the value as an argument::
This directive takes the name of a Bokeh enum variable as the argument and the
module name as an option. An optional description may be added as content:
.. code-block:: rest
.. bokeh-enum:: baz
:module: bokeh.sphinxext.sample
Specify a baz style
Examples
--------
For the following definition of ``bokeh.sphinxext.sample.Bar``::
baz = enumeration("a", "b", "c")
the above usage yields the output:
The directive above will generate the following output:
.. bokeh-enum:: baz
:module: bokeh.sphinxext.sample
"""
Specify a baz style
Although ``bokeh-enum`` may be used explicitly, it is more often convenient in
conjunction with the :ref:`bokeh.sphinxext.bokeh_autodoc` extension. Together,
the same output above will be generated directly from the following code:
.. code-block:: python
#: Specify a baz style
baz = enumeration("a", "b", "c")
'''

#-----------------------------------------------------------------------------
# Boilerplate
Expand All @@ -49,7 +59,6 @@

# External imports
from docutils.parsers.rst.directives import unchanged

from sphinx.errors import SphinxError

# Bokeh imports
Expand All @@ -63,7 +72,6 @@
__all__ = (
'BokehEnumDirective',
'setup',
'wrapper',
)

#-----------------------------------------------------------------------------
Expand All @@ -74,21 +82,16 @@
# Dev API
#-----------------------------------------------------------------------------

wrapper = textwrap.TextWrapper(subsequent_indent=' ')

class BokehEnumDirective(BokehDirective):

has_content = True
required_arguments = 1
optional_arguments = 2

option_spec = {
'module': unchanged,
'noindex': lambda x: True, # directives.flag weirdly returns None
}

def run(self):

name = self.arguments[0]

try:
Expand All @@ -101,7 +104,7 @@ def run(self):
fullrepr = repr(enum)
if len(fullrepr) > 180:
shortrepr = fullrepr[:40] + " .... " + fullrepr[-40:]
fullrepr = wrapper.wrap(fullrepr)
fullrepr = _wrapper.wrap(fullrepr)
else:
shortrepr = fullrepr
fullrepr = None
Expand All @@ -118,12 +121,15 @@ def run(self):
return self._parse(rst_text, "<bokeh-enum>")

def setup(app):
''' Required Sphinx extension setup function. '''
app.add_directive_to_domain('py', 'bokeh-enum', BokehEnumDirective)

#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------

_wrapper = textwrap.TextWrapper(subsequent_indent=' ')

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
Loading

0 comments on commit b8b604c

Please sign in to comment.