jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/382483 )
Change subject: Documentation: Sphinx setup
......................................................................
Documentation: Sphinx setup
* Use Sphinx Read the Docs theme with a CSS fix for the tables.
* Use Sphinx autodoc for automatically gather the documentation of
Cumin API.
* Use Sphinx napoleon to parse the human-friendly Google Style
docstrings.
* Use sphinx-argparse to automatically generate the documentation of
Cumin CLI.
* Use intersphinx to link external libraries documentation.
* Add a custom pyparsing.inv Sphinx inventory file with just the
referenced resources because pyparsing doesn't use Sphinx.
* For reference a first version of the api/ files were autogenerated
with sphinx-apidoc but heavily modified afterward:
SPHINX_APIDOC_OPTIONS=members,undoc-members,private-members sphinx-apidoc
--output-dir doc/source/ --force --separate --private --module-first
--suffix .rst cumin cumin/tests/
Bug: T159308
Change-Id: I241753d4648d3828803f3e601a05af547f7201cc
---
M .gitignore
A doc/Makefile
M doc/examples/aliases.yaml
M doc/examples/config.yaml
A doc/source/_static/theme_overrides.css
A doc/source/api/cumin.backends.direct.rst
A doc/source/api/cumin.backends.openstack.rst
A doc/source/api/cumin.backends.puppetdb.rst
A doc/source/api/cumin.backends.rst
A doc/source/api/cumin.grammar.rst
A doc/source/api/cumin.query.rst
A doc/source/api/cumin.transport.rst
A doc/source/api/cumin.transports.clustershell.rst
A doc/source/api/cumin.transports.rst
A doc/source/api/index.rst
A doc/source/cli.rst
A doc/source/conf.py
A doc/source/config.rst
A doc/source/index.rst
A doc/source/pyparsing.inv
M setup.cfg
M setup.py
M tox.ini
23 files changed, 412 insertions(+), 6 deletions(-)
Approvals:
jenkins-bot: Verified
Volans: Looks good to me, approved
diff --git a/.gitignore b/.gitignore
index ce3f261..720c5ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
/build/
+/doc/build/
/.cache/
/.coverage
/.coverage-integration-clustershell
diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 0000000..81838ff
--- /dev/null
+++ b/doc/Makefile
@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+SPHINXPROJ = Cumin
+SOURCEDIR = source
+BUILDDIR = build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
\ No newline at end of file
diff --git a/doc/examples/aliases.yaml b/doc/examples/aliases.yaml
index 4ea5a09..ca4a81f 100644
--- a/doc/examples/aliases.yaml
+++ b/doc/examples/aliases.yaml
@@ -1,4 +1,11 @@
-alias_direct: D{host1 or host2}
-alias_puppetdb: P{R:Class = My::Class}
-alias_openstack: O{project:project_name}
-alias_complex: A:alias_direct and (A:alias_puppetdb and not D{host3})
+# Cumin aliases configuration
+#
+# Cumin looks for an aliases.yaml file in the same directory of the loaded
main configuration file.
+# Aliases are resolved recursively at runtime, hence they can be nested.
+# Aliases are defined in the form:
+# alias_name: query_ tring using the global grammar
+#
+alias_direct: D{host1 or host2} # Use the direct backend
+alias_puppetdb: P{R:Class = My::Class} # Use the PuppetDB backend
+alias_openstack: O{project:project_name} # Use the OpenStack backend
+alias_complex: A:alias_direct and (A:alias_puppetdb and not D{host3}) # Mix
aliases and backend grammars
diff --git a/doc/examples/config.yaml b/doc/examples/config.yaml
index 62d7018..75e7c30 100644
--- a/doc/examples/config.yaml
+++ b/doc/examples/config.yaml
@@ -1,3 +1,7 @@
+# Cumin main configuration
+#
+# By default Cumin load the configuration from /etc/cumin/config.yaml, but it
can be overriden by command line argument
+#
transport: clustershell # Default transport to use, can be overriden by
command line argument
log_file: logs/cumin.log # Absolute or relative path for the log file
# If set, use this backend to parse the query first and only if it fails,
fallback to parse it with the general
diff --git a/doc/source/_static/theme_overrides.css
b/doc/source/_static/theme_overrides.css
new file mode 100644
index 0000000..e5d3f19
--- /dev/null
+++ b/doc/source/_static/theme_overrides.css
@@ -0,0 +1,13 @@
+/* override table width restrictions */
+@media screen and (min-width: 767px) {
+
+ .wy-table-responsive table td {
+ /* !important prevents the common CSS stylesheets from overriding
+ this as on RTD they are loaded after this stylesheet */
+ white-space: normal !important;
+ }
+
+ .wy-table-responsive {
+ overflow: visible !important;
+ }
+}
diff --git a/doc/source/api/cumin.backends.direct.rst
b/doc/source/api/cumin.backends.direct.rst
new file mode 100644
index 0000000..864e3ae
--- /dev/null
+++ b/doc/source/api/cumin.backends.direct.rst
@@ -0,0 +1,5 @@
+Direct
+======
+
+.. automodule:: cumin.backends.direct
+ :special-members: __init__
diff --git a/doc/source/api/cumin.backends.openstack.rst
b/doc/source/api/cumin.backends.openstack.rst
new file mode 100644
index 0000000..e35696e
--- /dev/null
+++ b/doc/source/api/cumin.backends.openstack.rst
@@ -0,0 +1,5 @@
+OpenStack
+=========
+
+.. automodule:: cumin.backends.openstack
+ :special-members: __init__
diff --git a/doc/source/api/cumin.backends.puppetdb.rst
b/doc/source/api/cumin.backends.puppetdb.rst
new file mode 100644
index 0000000..da5c40e
--- /dev/null
+++ b/doc/source/api/cumin.backends.puppetdb.rst
@@ -0,0 +1,5 @@
+PuppetDB
+========
+
+.. automodule:: cumin.backends.puppetdb
+ :special-members: __init__
diff --git a/doc/source/api/cumin.backends.rst
b/doc/source/api/cumin.backends.rst
new file mode 100644
index 0000000..fe54e75
--- /dev/null
+++ b/doc/source/api/cumin.backends.rst
@@ -0,0 +1,13 @@
+Backends
+========
+
+.. automodule:: cumin.backends
+ :special-members: __init__
+
+.. rubric:: Available backends
+
+.. toctree::
+
+ cumin.backends.direct
+ cumin.backends.openstack
+ cumin.backends.puppetdb
diff --git a/doc/source/api/cumin.grammar.rst b/doc/source/api/cumin.grammar.rst
new file mode 100644
index 0000000..9f033ac
--- /dev/null
+++ b/doc/source/api/cumin.grammar.rst
@@ -0,0 +1,6 @@
+Grammar
+=======
+
+.. automodule:: cumin.grammar
+ :no-private-members:
+ :no-inherited-members:
diff --git a/doc/source/api/cumin.query.rst b/doc/source/api/cumin.query.rst
new file mode 100644
index 0000000..b0170a1
--- /dev/null
+++ b/doc/source/api/cumin.query.rst
@@ -0,0 +1,5 @@
+Query
+=====
+
+.. automodule:: cumin.query
+ :special-members: __init__
diff --git a/doc/source/api/cumin.transport.rst
b/doc/source/api/cumin.transport.rst
new file mode 100644
index 0000000..2a36f5d
--- /dev/null
+++ b/doc/source/api/cumin.transport.rst
@@ -0,0 +1,4 @@
+Transport
+=========
+
+.. automodule:: cumin.transport
diff --git a/doc/source/api/cumin.transports.clustershell.rst
b/doc/source/api/cumin.transports.clustershell.rst
new file mode 100644
index 0000000..f24b1f9
--- /dev/null
+++ b/doc/source/api/cumin.transports.clustershell.rst
@@ -0,0 +1,5 @@
+ClusterShell
+============
+
+.. automodule:: cumin.transports.clustershell
+ :special-members: __init__
diff --git a/doc/source/api/cumin.transports.rst
b/doc/source/api/cumin.transports.rst
new file mode 100644
index 0000000..3cb2a4e
--- /dev/null
+++ b/doc/source/api/cumin.transports.rst
@@ -0,0 +1,18 @@
+Transports
+==========
+
+.. automodule:: cumin.transports
+ :special-members: __init__
+ :exclude-members: Command,State
+
+ .. autoclass:: Command
+ :special-members: __init__,__repr__,__str__,__eq__,__ne__
+
+ .. autoclass:: State
+ :special-members: __init__,__repr__,__str__,__getattr__,__cmp__
+
+.. rubric:: Available transports
+
+.. toctree::
+
+ cumin.transports.clustershell
diff --git a/doc/source/api/index.rst b/doc/source/api/index.rst
new file mode 100644
index 0000000..00f4054
--- /dev/null
+++ b/doc/source/api/index.rst
@@ -0,0 +1,20 @@
+Python API
+==========
+
+Cumin Python API autodoc.
+
+.. automodule:: cumin
+ :no-inherited-members:
+ :special-members: __init__,__new__
+
+.. autodata:: __version__
+
+.. rubric:: Subpackages and Submodules
+
+.. toctree::
+
+ cumin.grammar
+ cumin.query
+ cumin.transport
+ cumin.backends
+ cumin.transports
diff --git a/doc/source/cli.rst b/doc/source/cli.rst
new file mode 100644
index 0000000..84b4781
--- /dev/null
+++ b/doc/source/cli.rst
@@ -0,0 +1,8 @@
+CLI
+===
+
+.. argparse::
+ :module: cumin.cli
+ :func: get_parser
+ :prog: cumin
+ :nodefault:
diff --git a/doc/source/conf.py b/doc/source/conf.py
new file mode 100644
index 0000000..d7d1148
--- /dev/null
+++ b/doc/source/conf.py
@@ -0,0 +1,223 @@
+# -*- coding: utf-8 -*-
+"""Sphynx configuration."""
+#
+# Cumin documentation build configuration file, created by
+# sphinx-quickstart on Sat Sep 30 13:33:02 2017.
+#
+# This file is execfile()d with the current directory set to its
+# containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+import importlib
+import os
+import sys
+import types
+
+from pkg_resources import get_distribution
+
+import sphinx_rtd_theme
+
+
+# Adjust path
+sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
os.pardir)))
+
+
+# -- General configuration ------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#
+# needs_sphinx = '1.0'
+
+# 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',
+ 'sphinx.ext.napoleon',
+ 'sphinx.ext.intersphinx',
+ 'sphinx.ext.todo',
+ 'sphinx.ext.coverage',
+ 'sphinx.ext.viewcode',
+ 'sphinx.ext.githubpages',
+ 'sphinxarg.ext',
+]
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix(es) of source filenames.
+# You can specify multiple suffix as a list of string:
+#
+# source_suffix = ['.rst', '.md']
+source_suffix = '.rst'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'Cumin'
+title = u'{project} Documentation'.format(project=project)
+copyright = u"2017, Riccardo Coccioli <[email protected]>, Wikimedia
Foundation, Inc."
+author = u'Riccardo Coccioli'
+
+# The version info for the project you're documenting, acts as replacement for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The full version, including alpha/beta/rc tags.
+release = get_distribution('cumin').version
+# The short X.Y version.
+version = release
+
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#
+# This is also used if you do content translation via gettext catalogs.
+# Usually you set "language" from the command line for these cases.
+language = None
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This patterns also effect to html_static_path and html_extra_path
+exclude_patterns = []
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# If true, `todo` and `todoList` produce output, else they produce nothing.
+todo_include_todos = True
+
+
+# -- Options for HTML output ----------------------------------------------
+
+html_theme = 'sphinx_rtd_theme'
+html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
+html_use_smartypants = False
+
+# Add any paths that contain custom static files (such as style sheets) here,
+# relative to this directory. They are copied after the builtin static files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+html_context = {
+ 'css_files': [
+ '_static/theme_overrides.css', # override wide tables in RTD theme
+ ],
+}
+
+# -- Options for HTMLHelp output ------------------------------------------
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'Cumindoc'
+
+
+# -- Options for manual page output ---------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ('cli', 'cumin', 'Automation and orchestration framework written in
Python', [author], 1),
+]
+
+
+# -- Options for intersphinx ---------------------------------------
+
+intersphinx_mapping = {
+ 'python': ('https://docs.python.org/2.7/', None),
+ 'requests': ('http://docs.python-requests.org/en/master/', None),
+ 'ClusterShell': ('https://clustershell.readthedocs.io/en/v1.7.3/', None),
+ 'keystoneauth1': ('https://docs.openstack.org/keystoneauth/latest', None),
+ 'novaclient': ('https://docs.openstack.org/python-novaclient/latest/',
None),
+ 'pyparsing': ('https://pythonhosted.org/pyparsing/', 'pyparsing.inv'),
+}
+
+# Napoleon settings
+napoleon_google_docstring = True
+napoleon_numpy_docstring = False
+napoleon_include_init_with_doc = False
+napoleon_include_private_with_doc = False
+napoleon_include_special_with_doc = False
+napoleon_use_admonition_for_examples = False
+napoleon_use_admonition_for_notes = False
+napoleon_use_admonition_for_references = False
+napoleon_use_ivar = False
+napoleon_use_param = True
+napoleon_use_rtype = True
+napoleon_use_keyword = True
+
+# Autodoc settings
+autodoc_default_flags = ['members', 'show-inheritance', 'inherited-members',
'private-members']
+
+
+# -- Helper functions -----------------------------------------------------
+
+def filter_namedtuple_docstrings(app, what, name, obj, options, lines):
+ """Fix the automatically generated docstrings for namedtuples classes."""
+ if what == 'attribute' and len(lines) == 1 and lines[0].startswith('Alias
for field number'):
+ lines[0] = 'See the Keyword Arguments description.'
+
+
+def add_abstract_annotations(app, what, name, obj, options, lines):
+ """Workaround to add an abstract annotation for ABC abstract classes and
abstract methods."""
+ if ((what in ('method', 'attribute') and getattr(obj,
'__isabstractmethod__', False)) or
+ (what == 'class' and len(getattr(obj, '__abstractmethods__', []))
> 0)):
+ lines.insert(0, '``abstract``')
+
+
+def add_inherited_annotations(app, what, name, obj, options, lines):
+ """Workaround to add an inherited annotation for methods inherited from
the parent classes."""
+ if what == 'method':
+ if hasattr(obj, 'im_class'):
+ if obj.__name__ not in obj.im_class.__dict__:
+ lines.insert(0, '``inherited``')
+ elif isinstance(obj, types.FunctionType): # Static methods
+ module_name, class_name, _ = name.rsplit('.', 2)
+ module = importlib.import_module(module_name) # Dynamically
import the module
+ if obj.__name__ not in getattr(module, class_name).__dict__: #
Dynamically inspect the class
+ lines.insert(0, '``inherited``')
+ lines.insert(0, '``static``')
+
+ elif what == 'attribute':
+ module_name, class_name, prop = name.rsplit('.', 2)
+ module = importlib.import_module(module_name) # Dynamically import
the module
+ if prop not in getattr(module, class_name).__dict__: # Dynamically
inspect the class
+ lines.insert(0, '``inherited``')
+
+
+def skip_external_inherited(app, what, name, obj, skip, options):
+ """Skip methods inherited from external libraries."""
+ if not (what == 'class' and hasattr(obj, 'im_class') and obj.__name__ not
in obj.im_class.__dict__):
+ return
+
+ classes = [obj.im_class]
+ while classes:
+ c = classes.pop()
+ if obj.__name__ in c.__dict__: # Found the class that defined the
method
+ return 'cumin' not in c.__module__ # Skip if from external
libraries
+ else:
+ classes = list(c.__bases__) + classes # Continue in the
inheritance tree
+
+
+def skip_exceptions_init(app, what, name, obj, skip, options):
+ """Skip __init__ method for Exception classes."""
+ if what == 'exception' and name == '__init__':
+ return True
+
+
+def setup(app):
+ """Register the filter_namedtuple_docstrings function."""
+ app.connect('autodoc-process-docstring', filter_namedtuple_docstrings)
+ app.connect('autodoc-process-docstring', add_abstract_annotations)
+ app.connect('autodoc-process-docstring', add_inherited_annotations)
+ app.connect('autodoc-skip-member', skip_exceptions_init)
+ app.connect('autodoc-skip-member', skip_external_inherited)
diff --git a/doc/source/config.rst b/doc/source/config.rst
new file mode 100644
index 0000000..44f587e
--- /dev/null
+++ b/doc/source/config.rst
@@ -0,0 +1,14 @@
+Configuration
+=============
+
+config.yaml
+-----------
+
+.. literalinclude:: ../examples/config.yaml
+ :language: yaml
+
+aliases.yaml
+------------
+
+.. literalinclude:: ../examples/aliases.yaml
+ :language: yaml
diff --git a/doc/source/index.rst b/doc/source/index.rst
new file mode 100644
index 0000000..51c3b87
--- /dev/null
+++ b/doc/source/index.rst
@@ -0,0 +1,17 @@
+Cumin |release| documentation
+=============================
+
+.. toctree::
+ :maxdepth: 3
+
+ config
+ cli
+ api/index
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
diff --git a/doc/source/pyparsing.inv b/doc/source/pyparsing.inv
new file mode 100644
index 0000000..29d014b
--- /dev/null
+++ b/doc/source/pyparsing.inv
Binary files differ
diff --git a/setup.cfg b/setup.cfg
index b7e4789..c1db188 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,2 +1,7 @@
[aliases]
-test=pytest
+test = pytest
+
+[build_sphinx]
+project = Cumin
+source-dir = doc/source
+build-dir = doc/build
diff --git a/setup.py b/setup.py
index 04a03c1..fdec6de 100644
--- a/setup.py
+++ b/setup.py
@@ -27,6 +27,9 @@
'pytest-cov>=1.8.0',
'pytest-xdist>=1.15.0',
'requests-mock>=0.7.0',
+ 'Sphinx>=1.4.9',
+ 'sphinx-argparse>=0.1.15',
+ 'sphinx_rtd_theme>=0.1.6',
'tox>=2.5.0',
'vulture>=0.6,<0.25', # Required for
https://github.com/landscapeio/prospector/issues/230
]
diff --git a/tox.ini b/tox.ini
index 20c044c..62d4e23 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,10 +1,11 @@
[tox]
minversion = 1.6
-envlist = flake8, unit, bandit, prospector
+envlist = flake8, unit, bandit, prospector, sphinx
[testenv]
usedevelop = True
basepython = python2.7
+whitelist_externals = sed
commands =
flake8: flake8
unit: py.test --strict --cov-report term-missing --cov=cumin
cumin/tests/unit {posargs}
@@ -12,6 +13,10 @@
bandit: bandit -l -i -r --exclude cumin/tests cumin/
bandit: bandit -l -i -r --skip B101 cumin/tests
prospector: prospector --profile "{toxinidir}/prospector.yaml" cumin/
+ sphinx: python setup.py build_sphinx -b html
+ sphinx: python setup.py build_sphinx -b man
+ # Fix missing space after bold blocks in man page:
https://github.com/ribozz/sphinx-argparse/issues/80
+ sphinx: sed -i='' -e 's/^\.B/.B /' '{toxinidir}/doc/build/man/cumin.1'
deps =
# Use install_requires and extras_require['tests'] from setup.py
.[tests]
--
To view, visit https://gerrit.wikimedia.org/r/382483
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I241753d4648d3828803f3e601a05af547f7201cc
Gerrit-PatchSet: 11
Gerrit-Project: operations/software/cumin
Gerrit-Branch: master
Gerrit-Owner: Volans <[email protected]>
Gerrit-Reviewer: Faidon Liambotis <[email protected]>
Gerrit-Reviewer: Gehel <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits