Include documentation of the utility modules

Add a documentation section that uses the automodule
sphinx documentation generator to build a utility page
that shows people what the utility modules taskflow
uses for *internal* usage are and include a warning to
try to avoid end-users from using these modules (better
to warn than not warn).

This also adds on docstrings to various functions that
were missing it so that they appear correctly in the
generated documentation.

Change-Id: Ibd5695927601614f31793ea5450887694f4320ae
This commit is contained in:
Joshua Harlow 2014-11-27 21:56:07 -08:00 committed by Joshua Harlow
parent 707b47e798
commit 95e94f768a
5 changed files with 86 additions and 17 deletions

View File

@ -70,13 +70,9 @@ TaskFlow into your project:
``[TaskFlow]`` to your emails subject to get an even faster response). ``[TaskFlow]`` to your emails subject to get an even faster response).
* Follow (or at least attempt to follow) some of the established * Follow (or at least attempt to follow) some of the established
`best practices`_ (feel free to add your own suggested best practices). `best practices`_ (feel free to add your own suggested best practices).
* Keep in touch with the team (see above); we are all friendly and enjoy
.. warning:: knowing your use cases and learning how we can help make your lives easier
by adding or adjusting functionality in this library.
External usage of internal helpers and other internal utility functions
and modules should be kept to a *minimum* as these may be altered,
refactored or moved *without* notice. If you are unsure whether to use
a function, class, or module, please ask (see above).
.. _IRC: irc://chat.freenode.net/openstack-state-management .. _IRC: irc://chat.freenode.net/openstack-state-management
.. _best practices: http://wiki.openstack.org/wiki/TaskFlow/Best_practices .. _best practices: http://wiki.openstack.org/wiki/TaskFlow/Best_practices
@ -92,6 +88,7 @@ Miscellaneous
exceptions exceptions
states states
types types
utils
Indices and tables Indices and tables
================== ==================

49
doc/source/utils.rst Normal file
View File

@ -0,0 +1,49 @@
---------
Utilities
---------
.. warning::
External usage of internal utility functions and modules should be kept
to a **minimum** as they may be altered, refactored or moved to other
locations **without** notice (and without the typical deprecation cycle).
Async
~~~~~
.. automodule:: taskflow.utils.async_utils
Deprecation
~~~~~~~~~~~
.. automodule:: taskflow.utils.deprecation
Kazoo
~~~~~
.. automodule:: taskflow.utils.kazoo_utils
Locks
~~~~~
.. automodule:: taskflow.utils.lock_utils
Miscellaneous
~~~~~~~~~~~~~
.. automodule:: taskflow.utils.misc
Persistence
~~~~~~~~~~~
.. automodule:: taskflow.utils.persistence_utils
Reflection
~~~~~~~~~~
.. automodule:: taskflow.utils.reflection
Threading
~~~~~~~~~
.. automodule:: taskflow.utils.threading_utils

View File

@ -14,7 +14,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import functools
import warnings import warnings
import six import six
@ -193,8 +192,12 @@ def _moved_decorator(kind, new_attribute_name, message=None,
return decorator return decorator
"""Decorates a *instance* property that was moved to another location.""" def moved_property(new_attribute_name, message=None,
moved_property = functools.partial(_moved_decorator, 'Property') version=None, removal_version=None):
"""Decorates a *instance* property that was moved to another location."""
return _moved_decorator('Property', new_attribute_name, message=message,
version=version, removal_version=removal_version)
def moved_class(new_class, old_class_name, old_module_name, message=None, def moved_class(new_class, old_class_name, old_module_name, message=None,

View File

@ -95,8 +95,12 @@ class KazooTransactionException(k_exc.KazooException):
def checked_commit(txn): def checked_commit(txn):
# Until https://github.com/python-zk/kazoo/pull/224 is fixed we have """Commits a kazoo transcation and validates the result.
# to workaround the transaction failing silently.
NOTE(harlowja): Until https://github.com/python-zk/kazoo/pull/224 is fixed
or a similar pull request is merged we have to workaround the transaction
failing silently.
"""
if not txn.operations: if not txn.operations:
return [] return []
results = txn.commit() results = txn.commit()

View File

@ -342,11 +342,27 @@ def capture_failure():
For example:: For example::
except Exception: >>> from taskflow.utils import misc
with capture_failure() as fail: >>>
LOG.warn("Activating cleanup") >>> def cleanup():
cleanup() ... pass
save_failure(fail) ...
>>>
>>> def save_failure(f):
... print("Saving %s" % f)
...
>>>
>>> try:
... raise IOError("Broken")
... except Exception:
... with misc.capture_failure() as fail:
... print("Activating cleanup")
... cleanup()
... save_failure(fail)
...
Activating cleanup
Saving Failure: IOError: Broken
""" """
exc_info = sys.exc_info() exc_info = sys.exc_info()
if not any(exc_info): if not any(exc_info):