nova/nova/safe_utils.py
Matt Riedemann 8b24bf766d Set autodoc_index_modules=True so tox -e docs builds module docs again
Commit bd7e62f796 disabled the
autodoc_index_modules flag for building docs but it wasn't really
necessary, that change was just to get the module index out of the main
docs page.

We want to autodoc the modules so we can view the actual module index in
the tox -d docs build results, which also tells us if we have correct
ReST format in doc strings.

Notes
-----

1. Several doc string blocks have to be fixed as part of this to get
   the docs tox job to pass.
2. A docstring in vhdutilsv2 is updated to remove the math directive
   since that requires the sphinx.ext.pngmath extension which requires
   latex and dvipng packages from the distro - which is overkill for
   what the docstring was actually doing with the math directive.
3. We exclude autodoc for tests since we don't really care about
   docstrings on unit tests.
4. We exclude the nova.wsgi.nova-* modules since those won't build with
   autodoc since they can't be imported (there is no
   nova/wsgi/__init__.py module). We could arguably add the __init__.py
   but it's not really necessary for what those scripts are used for.
5. The sphinx.ext.ifconfig extension is removed since there are no docs
   that use the ifconfig directive.
6. Update the developer docs to explicitly point out that graphviz must
   be installed prior to running tox -e docs.
7. Hide doc/source/api/autoindex.rst from the toctree so that we don't
   regress the point of commit bd7e62f796.
8. unused_docs and exclude_trees options are removed from conf.py since
   they are deprecated in Sphinx 1.2.3:

   https://github.com/sphinx-doc/sphinx/blob/1.2.3/sphinx/config.py#L54
9. Fix imports for moved libvirt volume options.

Closes-Bug: #1471934

Change-Id: I946e2f89f2c9fc70e870faaf84e4a8b0fc703344
2015-07-30 17:11:47 -07:00

59 lines
2.3 KiB
Python

# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# Copyright 2011 Justin Santa Barbara
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Utilities and helper functions that won't produce circular imports."""
import inspect
def getcallargs(function, *args, **kwargs):
"""This is a simplified inspect.getcallargs (2.7+).
It should be replaced when python >= 2.7 is standard.
This method can only properly grab arguments which are passed in as
keyword arguments, or given names by the method being called. This means
that an ``*arg`` in a method signature and any arguments captured by it
will be left out of the results.
"""
keyed_args = {}
argnames, varargs, keywords, defaults = inspect.getargspec(function)
keyed_args.update(kwargs)
# NOTE(alaski) the implicit 'self' or 'cls' argument shows up in
# argnames but not in args or kwargs. Uses 'in' rather than '==' because
# some tests use 'self2'.
if len(argnames) > 0 and ('self' in argnames[0] or 'cls' == argnames[0]):
# The function may not actually be a method or have im_self.
# Typically seen when it's stubbed with mox.
if inspect.ismethod(function) and hasattr(function, 'im_self'):
keyed_args[argnames[0]] = function.im_self
else:
keyed_args[argnames[0]] = None
remaining_argnames = filter(lambda x: x not in keyed_args, argnames)
keyed_args.update(dict(zip(remaining_argnames, args)))
if defaults:
num_defaults = len(defaults)
for argname, value in zip(argnames[-num_defaults:], defaults):
if argname not in keyed_args:
keyed_args[argname] = value
return keyed_args