Ejemplo n.º 1
0
def map_(dist, group, name):
    """Print out a map of cached entry points"""
    import pprint
    from reentry import manager
    if dist is None:
        res = {
            d: manager.get_entry_map(d, group, name)
            for d in manager.distribution_names
        }
    else:
        res = manager.get_entry_map(dist, group, name)
    click.echo(pprint.pformat(res))
Ejemplo n.º 2
0
def get_entry_point_from_class(class_module, class_name):
    """
    Given the module and name of a class, attempt to obtain the corresponding entry point if it exists

    :param class_module: module of the class
    :param class_name: name of the class
    :return: a tuple of the corresponding group and entry point or None if not found
    """
    prefix = 'JobProcess_'

    # Curiosity of the dynamically generated JobProcess classes
    if class_name.startswith(prefix):
        class_path = class_name[len(prefix):]
        class_module, class_name = class_path.rsplit('.', 1)

    for group in epm.get_entry_map().keys():
        for entry_point in epm.iter_entry_points(group):

            if entry_point.module_name != class_module:
                continue

            for entry_point_class_name in entry_point.attrs:
                if entry_point_class_name == class_name:
                    return group, entry_point

    return None, None
Ejemplo n.º 3
0
def main(with_noreg):
    """Test automatic scanning / registering"""
    entry_point_map = manager.get_entry_map(
        groups='reentry_test',
        ep_names=['test-plugin', 'test-noreg', 'builtin'])
    data_file = py_path.local(get_datafile())

    assert entry_point_map, 'The test plugin entry point were not found\nMap:\n{}\n\nData File: {}\n\nContents:\n{}'.format(
        manager.get_entry_map(), data_file.strpath, data_file.read())

    try:
        test_entry_point = entry_point_map['reentry_test']['test-plugin']
        builtin_entry_point = entry_point_map['reentry_test']['builtin']
        if with_noreg:
            noreg_entry_point = entry_point_map['reentry_test']['test-noreg']
    except Exception as err:
        print('datafile: {}'.format(data_file.strpath))
        print('\nCurrent relevant entry point map:\n\n')
        print(manager.format_map(entry_point_map))
        print('\n')
        scan_map = manager.scan(groups=['reentry_test'], nocommit=True)
        print('\nFull entry point map after scan:\n\n')
        print(manager.format_map(scan_map))
        raise err

    plugin_class = test_entry_point.load()
    builtin_class = builtin_entry_point.load()

    assert plugin_class.test_string == 'TEST', 'The test string was incorrect'
    assert builtin_class.test_string == 'TEST', 'The test string was incorrect'
    if with_noreg:
        noreg_class = noreg_entry_point.load()
        assert noreg_class.test_string == 'TEST', 'The test string was incorrect'

    plugin_list = [
        ep.load() for ep in manager.iter_entry_points('reentry_test')
    ]
    assert plugin_class in plugin_list, 'iter_entry_points found differing test entry point from get_entry_map.'
    assert builtin_class in plugin_list, 'iter_entry_points found differing test entry point from get_entry_map.'
    if with_noreg:
        assert noreg_class in plugin_list, 'iter_entry_points found differing test entry point from get_entry_map.'
Ejemplo n.º 4
0
def get_class_to_entry_point_map(short_group_name=False):
    """
    create a mapping of modules to entry point groups / names

    :param short_group_name: bool, if True the leading 'aiida.' is cut off group names
    :return: dictionary, keys are modules, values are (group, entrypoint-name)
    """
    groups = (g for g in epm.get_entry_map('aiida-core').iterkeys() if g.startswith('aiida'))
    class_ep_map = {}
    for group in groups:
        for ep in epm.iter_entry_points(group):
            for classname in ep.attrs:
                key = '.'.join([ep.module_name, classname])
                if short_group_name:
                    groupname = '.'.join(group.split('.')[1:])
                else:
                    groupname = group
                value = (groupname, ep.name)
                class_ep_map[key] = value
    # ~ module_ep_map = {'.'.join([ep.module_name, ep.attrs]): (group, ep.name) for group in groups for ep in iter_entry_points(group)}
    return class_ep_map