Skip to content

Commit

Permalink
Added Sphinx documenting of rose.(config,macro).
Browse files Browse the repository at this point in the history
    * Fixes traceback for a rose macro without a docstring
  • Loading branch information
oliver-sanders committed Mar 21, 2017
1 parent dd5d2c3 commit 5052fac
Show file tree
Hide file tree
Showing 17 changed files with 1,792 additions and 150 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
etc/rose.conf
etc/opt
lib/bash/rose_init_site
doc/sphinx/_build
venv
41 changes: 41 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/make -f

# If sphinx-build is not installed or if too early a version is installed make
# will attempt to install latest sphinx-build via a virtualenv.
#
# export SPHINX_DEV_MODE='true' to prevent the virtualenv from being deleted
# after the build completes.

min-sphinx-version = 1.5.3 # TODO
pypath = ../lib/python

env-path = ../venv
sphinx-install := $(shell scripts/sphinx-install $(env-path) $(min-sphinx-version))
sphinx-uninstall := $(shell scripts/sphinx-uninstall)

venv =
ifneq "$(sphinx-install)" ""
venv = . $(env-path)/bin/activate;
endif

all: doctest html

html: sphinx-build
$(venv) PYTHONPATH=../$(pypath) make -C sphinx html

doctest: sphinx-build
$(venv) PYTHONPATH=../$(pypath) make -C sphinx doctest

sphinx-build: $(sphinx-install)
echo ${PWD}
ls ../lib/python
$(venv) PYTHONPATH=$(pypath) sphinx-build -aEW -b dummy sphinx sphinx/_build

sphinx-uninstall:
rm -rf $(env-path)

sphinx-install: $(sphinx-uninstall)
virtualenv --python=python2.7 "$(env-path)"
$(venv) pip install sphinx

sphinx-activate:
43 changes: 26 additions & 17 deletions doc/rose-api.html
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,8 @@ <h2 id="macro">Rose Macros</h2>
e.g. adding/removing options.</li>

<li>Upgraders - these are special transformer macros
for upgrading and downgrading configurations.</li>
for upgrading and downgrading configurations. (covered in the
<a href="#upgrade">next section</a>)</li>

<li>Reporters - output information about a
configuration.</li>
Expand Down Expand Up @@ -839,24 +840,30 @@ <h4 id="macro:code:examples">Examples</h4>
"rose-rug-advanced-tutorials-macro.html">Advanced
Tutorial</a>.</p>

<h4 id="macro:code:api:docs">API Documentation</h4>
<p>The <code>rose.macro.MacroBase</code> class (subclassed by all
rose macros) is documented <a
href="sphinx/_build/html/macro.html">here</a>.

<h4 id="macro:code:api">API Reference</h4>

<p>Macros should subclass from
<code>rose.macro.MacroBase</code>. There are two types
of macro - checkers (validators) which do not alter a
configuration but provide error messages, and changers
(transformers) which return an altered configuration. A
macro class can contain one or both of these
behaviours.</p>

<p>Your macro should provide a method called
<code>validate</code> (for <em>checking</em>) and/or a
method called <code>transform</code> (for
<em>changing</em>). These methods should accept two
<code>rose.config.ConfigNode</code> instances as
arguments - one is the configuration, and one is the
metadata configuration that provides information about
the configuration items.</p>
<p>Validator, transformer and reporter macros are
python classes which subclass from
<code>rose.macro.MacroBase</code> (<a
href="sphinx/_build/html/macro.html">api docs</a>).

<p>These macros implement their behaviours by providing a
<code>validate</code>, <code>transform</code> or
<code>report</code> method. A macro can contain any
combination of these methods so, for example, a macro
might be both a validator and a transformer.</p>

<p>These methods should accept two
<code>rose.config.ConfigNode</code> (<a
href="sphinx/_build/html/config.html">api docs</a>)
instances as arguments - one is the configuration, and
one is the metadata configuration that provides
information about the configuration items.</p>

<p>A validator macro should look like:</p>
<pre class="prettyprint">
Expand Down Expand Up @@ -963,6 +970,8 @@ <h4 id="macro:code:api">API Reference</h4>

<pre class="prettyprint">
def report(self, config, meta_config=None):
""" Write some information about the configuration to a report file."""
# Note: report methods do not have a return value.
with open('report/file', 'r') as report_file:
report_file.write(str(config.get(["namelist:snowflakes"])))
</pre>
Expand Down
27 changes: 27 additions & 0 deletions doc/rose-config-api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<!-- Redirect to sphinx page docs. -->
<meta http-equiv="refresh"
content="0; url=sphinx/_build/html/config.html" />
<style type="text/css">
#panel-main {
display: none;
}
</style>
</head>
<body>

<!-- Placeholder to be displayed in the single-page version. -->
<div id="panel-main" class="panel panel-default">
<div class="panel-heading">
<h1>Rose Config API</h1>
</div>

<div class="panel-body">
<p>View the API docs <a href="rose-config-api.html">here</a>.
</div>
</div>

</body>
</html>
2 changes: 2 additions & 0 deletions doc/rose.html
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ <h2>Content</h2>

<li><a href=
"rose-variables.html">Variables</a></li>

<li><a href="rose-config-api.html">Rose Config API</a></li>
</ul>
</li>

Expand Down
38 changes: 38 additions & 0 deletions doc/scripts/sphinx-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# Determines whether it is necessary to install sphinx-build, or whether to
# activate a virtualenv located in $ENV_PATH.

ENV_PATH="$1"
SPHINX_VERSION="$2"
USE_ENV='false'

# Activate virtualenv if present
if [[ ${SPHINX_DEV_MODE} == 'true' && -d "${ENV_PATH}" ]]; then
. "${ENV_PATH}"/bin/activate
USE_ENV='true'
fi

# Compare installed sphinx-build version (if present).
python -c "
import sys
min_version = tuple((int(num) for num in '${SPHINX_VERSION}'.split('.')))
cur_version_string = '$(sphinx-build --version | cut -d ' ' -f 3)'
try:
cur_version = tuple((int(num) for num in cur_version_string.split('.')))
except ValueError:
sys.exit(1) # sphinx-build not installed.
if not cur_version or min_version > cur_version:
sys.exit(1) # sphinx-build version too old.
sys.exit(0) # sphinx-build sufficient.
"

# Echo any required action: 'sphinx-install', 'sphinx-activate' or ''.
if [[ $? == 1 ]]; then
echo 'sphinx-install'
if [[ ${USE_ENV} == 'true' ]]; then
# Existing virtualenv has too early a version of sphinx-build.
rm -rf "${ENV_PATH}"
fi
elif [[ ${USE_ENV} == 'true' ]]; then
echo 'sphinx-activate'
fi
5 changes: 5 additions & 0 deletions doc/scripts/sphinx-uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

if [[ ! ${SPHINX_DEV_MODE} == 'true' ]]; then
echo 'sphinx-uninstall'
fi
177 changes: 177 additions & 0 deletions doc/sphinx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# Makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build

# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext

help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"

clean:
rm -rf $(BUILDDIR)/*

html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."

singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."

pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."

json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."

htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."

qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/rose-api-doc.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/rose-api-doc.qhc"

devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/rose-api-doc"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/rose-api-doc"
@echo "# devhelp"

epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."

latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."

latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."

man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."

texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."

info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."

gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."

changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."

linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."

doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."

pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
Empty file added doc/sphinx/_static/-
Empty file.
Loading

0 comments on commit 5052fac

Please sign in to comment.