コード例 #1
0
def load_validation_plugin(name=None):
    """Find and load the chosen validation plugin.

    Args:
        name (string): the name of the entry_point, as advertised in the
            setup.py of the providing package.

    Returns:
        an uninstantiated subclass of ``bigchaindb.validation.AbstractValidationRules``
    """
    if not name:
        return BaseValidationRules

    # TODO: This will return the first plugin with group `bigchaindb.validation`
    #       and name `name` in the active WorkingSet.
    #       We should probably support Requirements specs in the config, e.g.
    #       validation_plugin: 'my-plugin-package==0.0.1;default'
    plugin = None
    for entry_point in iter_entry_points('bigchaindb.validation', name):
        plugin = entry_point.load()

    # No matching entry_point found
    if not plugin:
        raise ResolutionError(
            'No plugin found in group `bigchaindb.validation` with name `{}`'.
            format(name))

    # Is this strictness desireable?
    # It will probably reduce developer headaches in the wild.
    if not issubclass(plugin, (BaseValidationRules, )):
        raise TypeError('object of type "{}" does not implement `bigchaindb.'
                        'validation.BaseValidationRules`'.format(type(plugin)))

    return plugin
コード例 #2
0
ファイル: sanity_check.py プロジェクト: pombredanne/pkglib
 def run(self):
     errors = collections.defaultdict(list)
     for dist in working_set:
         for req in dist.requires():
             try:
                 working_set.require(str(req))
             except Exception as e:
                 errors[dist].append((req, repr(e)))
     if errors:
         msg = ['']
         for dist in errors:
             msg.append("Package: {}".format(dist))
             for error in errors[dist]:
                 req, err = error
                 msg.append("  Requirement: {}".format(req))
                 msg.append("      {}".format(err))
         raise ResolutionError('\n'.join(msg))
     log.info("All OK")