Enforces module presence.

    The general use here is to allow conditional imports that may fail (e.g., a
    required python package is not installed) but still allow the rest of the
    python package to compile and run fine. If the wrapped method with this
    decorated is invoked, then a runtime error is generated.

    :param module: required module (set as variable to ``None`` on import fail)
    :type  module: ``module`` or ``None``
    :param name: module name
    :type  name: ``string``

def requires(module, name=""):
    """Enforces module presence.

    The general use here is to allow conditional imports that may fail (e.g., a
    required python package is not installed) but still allow the rest of the
    python package to compile and run fine. If the wrapped method with this
    decorated is invoked, then a runtime error is generated.

    :param module: required module (set as variable to ``None`` on import fail)
    :type  module: ``module`` or ``None``
    :param name: module name
    :type  name: ``string``
    """
    def wrapped(method):
        """Call and enforce method."""
        if module is None:
            raise ImproperlyConfigured("Module '%s' is not installed." % name)
        return method

    return wrapped