Esempio n. 1
0
def scan_for_installed(dist, attr, value):  # pylint: disable=unused-argument
    """
    scan for entry points of the given groups in the already installed
    distributions

    :param value: a list of groups names to scan for
    """
    ensure_list(value, attr)
    if value:
        from reentry import manager
        print('[ REENTRY ] scanning for plugins in groups {}...'.format(value),
              file=sys.stderr)
        print('[ REENTRY ] Current entry point map at {}:'.format(
            get_datafile()),
              file=sys.stderr)
        print(manager.format_map(manager.get_dist_map()), file=sys.stderr)
        scanned_map = manager.scan(groups=value, group_re=False, nodelete=True)
        print('[ REENTRY ] ... plugin scanning done.', file=sys.stderr)
        print('[ REENTRY ] Replaced following parts of the map at {}:'.format(
            get_datafile()),
              file=sys.stderr)
        print(manager.format_map(scanned_map), file=sys.stderr)
        print('[ REENTRY ] Current entry point map at {}:'.format(
            get_datafile()),
              file=sys.stderr)
        print(manager.format_map(manager.get_dist_map()), file=sys.stderr)
Esempio n. 2
0
def register_dist(dist, attr, value):
    """If value is True, register the distribution's entry points in reentrys storage."""
    from distutils.errors import DistutilsSetupError  # pylint: disable=import-error,no-name-in-module
    # assert is boolean
    if not is_bool(value):
        raise DistutilsSetupError('{} must be a boolean, got {}'.format(
            attr, value))

    if value:
        print('[ REENTRY ] registering entry points with reentry...',
              file=sys.stderr)
        from reentry import manager
        dist_name, entry_point_map = manager.register(dist)
        print('[ REENTRY ] ... registered to {}'.format(get_datafile()),
              file=sys.stderr)
        print('[ REENTRY ] Following entrypoints were registered\n',
              file=sys.stderr)
        print(manager.format_map({dist_name: entry_point_map}),
              file=sys.stderr)
        print('[ REENTRY ] Current entry point map at {}:'.format(
            get_datafile()),
              file=sys.stderr)
        print(manager.format_map(manager.get_dist_map()), file=sys.stderr)
Esempio 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.'
Esempio n. 4
0
def test_get_datafile():
    datafile = Path(config.get_datafile())

    assert datafile.is_file()
    assert datafile.exists()
Esempio n. 5
0
def datafile():
    """Print the path to the current datafile."""
    click.echo(get_datafile())
Esempio n. 6
0
def test_get_datafile():
    datafile = py_path.local(config.get_datafile())

    assert datafile.isfile()
    assert datafile.exists()
Esempio n. 7
0
def get_default_backend():
    from reentry.config import get_datafile
    return JsonBackend(datafile=get_datafile())