Skip to content

Commit

Permalink
Coverted keras docstrings from markdown to rst
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Aug 7, 2017
1 parent 89f8246 commit 2b8ce62
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
28 changes: 27 additions & 1 deletion conx/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@
from functools import reduce
import sys
import inspect
import re

import numpy as np
import keras
from keras.optimizers import (SGD, RMSprop, Adagrad, Adadelta, Adam, Adamax, Nadam,
TFOptimizer)

try:
import pypandoc
except:
pypandoc = None

from .utils import *
#------------------------------------------------------------------------

Expand Down Expand Up @@ -333,15 +339,35 @@ def make_image(self, vector, config={}):
import PIL
return PIL.Image.fromarray(vector.astype("uint8")).resize(self.vshape)

def process_class_docstring(docstring):
docstring = re.sub(r'\n # (.*)\n',
r'\n __\1__\n\n',
docstring)

docstring = re.sub(r' ([^\s\\\(]+):(.*)\n',
r' - __\1__:\2\n',
docstring)

docstring = docstring.replace(' ' * 5, '\t\t')
docstring = docstring.replace(' ' * 3, '\t')
docstring = docstring.replace(' ', '')
return docstring

## Dynamically load all of the keras layers, making a conx layer:
## Al of these will have BaseLayer as their superclass:
keras_module = sys.modules["keras.layers"]
for (name, obj) in inspect.getmembers(keras_module):
if type(obj) == type and issubclass(obj, (keras.engine.Layer, )):
try:
docstring_md = ' **' + obj.__name__ + '**\n\n'
docstring_md += ' ' + obj.__doc__
docstring = pypandoc.convert(process_class_docstring(docstring_md), "rst", "markdown_github")
except:
docstring = obj.__doc__
new_name = "%sLayer" % name
locals()[new_name] = type(new_name, (BaseLayer,),
{"CLASS": obj,
"__doc__": obj.__doc__})
"__doc__": docstring})

## Overwrite, or make a more specific version manually:
InputLayer = Layer
Expand Down
2 changes: 2 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Pillow
IPython
tensorflow
theano
pypandoc
sphinx_rtd_theme
9 changes: 5 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
Expand All @@ -45,8 +46,8 @@
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ['.rst', '.md']
# source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'
Expand Down Expand Up @@ -89,7 +90,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down

0 comments on commit 2b8ce62

Please sign in to comment.